Redis-Cluster cannot query the key

The reason why Vlaue cannot be queried by Redis Cluster

Article Directory

What is redis

What is Cluster

background:

​ The architecture used by the company's Redis is the Cluster model, as shown in the figure below, which is also for scalability, and HA. The previous production environment was normal and there was no problem. However, it was suddenly discovered that some KEYs cannot query Redis. The data, the database is queried, and the magnitude is not very large, but in the process of replacing the old and new businesses of a department, due to rapid iteration (saving trouble, laziness) for agile development, the latest operations directly modify the cache. Without updating the database, if noSql data cannot be queried, dirty data will be generated, which is a headache, so it is very simple to quickly locate the problem and solve it, and the business solution is also very simple.

solution

  1. Local cache data ->Redis ->Mysql
  2. Redis cannot query data-query data again -> Mysql
  3. Redis can't query data ->Nocos/(Apollo)->Mysql

The problem can be solved in business, but why does it happen that it cannot be queried? The client we use is

[https://github.com/xetorthio/jedisJedis,]:

The official preferred recommended client, the Maven package is

Jedis introduction

Insert picture description here
<dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
    <version>2.9.0</version>
    <type>jar</type>
    <scope>compile</scope>
</dependency>

Officially provided Demo

    @Test
    public void ConnectionTest(){
        //1. Connecting to Redis server on localhost
        Jedis jedis = new Jedis("localhost");
        System.out.println("Connection to server sucessfully");
        //2. set the data in redis string
        jedis.set("username", "Roxin");
        //3. Get the stored data and print it
        System.out.println("Stored string in redis:: "+ jedis.get("username"));
        //4. Close the Redis connection;
        jedis.close();
   }

Pooled connection

    @Test
    public void ConnectionPoolTest(){
        //连接池设定
        JedisPoolConfig config = new JedisPoolConfig();
        //设定最大连接数
        config.setMaxTotal(30);
        //设置最大空闲连接数
        config.setMaxIdle(10);
        //创建连接池
        JedisPool jedisPool = new JedisPool(config, "127.0.0.1");
        //获得服务资源
        Jedis jedis = jedisPool.getResource();
        jedis.select(1);
        jedis.set("username", "Roxin By Jedis Pool");
        System.out.println(jedis.get("username"));
        jedis.close();
        jedisPool.close();
    }

Jedis sample code

   @Test
    public void SetTest(){
        Jedis jedis = jedisPool.getResource();
        String setKey1 = "SETKEY-1";
        for (int i = 0; i < 10; i++) {
            //添加一个元素
            jedis.sadd(setKey1,"value-"+i);
        }
        assert 10 == jedis.scard(setKey1); //获得元素个数
        jedis.sadd(setKey1,"value-1");//添加重复的元素将失效
        assert 10 == jedis.scard(setKey1);
        String s= jedis.srandmember(setKey1);//随机获取一个元素
        assert jedis.sismember(setKey1,s);//是否为集合成员
        String setKey2 = "SETKEY-2";
        for (int i = 1; i < 11; i++) {
            jedis.sadd(setKey2,"value-"+i);
        }
        assert jedis.sdiff(setKey1,setKey2).size() == 1;//补集
        assert jedis.sinter(setKey1,setKey2).size() == 9;//交集
        assert jedis.sunion(setKey1,setKey2).size() == 11;//并集
        jedis.del(setKey1,setKey2);
        jedis.close();
    }

The cluster architecture

Cluster architecture


Cluster query process is like this

Query process

The reason why the data cannot be queried is probably

  1. Serialization issues
  2. Jedis problem concurrency socket can not be queried
  3. Problems with RedisTemplate
  4. Problems with Redis Cluster
  5. Re-allocate the card slot
  6. Connection timed out
  7. Bigkey
  8. NIC problem