Cause Vlaue cannot be queried in the Redis Cluster

What is the redis

What is a Cluster

Background:

The Redis architecture of the company is Cluster mode, as shown in the figure below, which is also for extensibility. HA is also used. The production environment before is normal and there is no problem Less than Redis data query, the database query, scale is not big, but there is a department in the process of the old and new business to replace, thanks to the agile development, rapid iteration (save trouble, lazy), latest operating directly to modify the cache, not update the database, if less than no data query, will generate dirty data, q is a headache Problem, so to quickly locate the problem and solve, the business solution is also very simple.

The solution

  1. Local cache data ->Redis ->Mysql
  2. Mysql > select * from ‘Redis’ where’ Redis’ = ‘Redis’
  3. Redis could not query data ->Nocos/(Apollo)->Mysql

The business can solve the problem, but why can’t query the situation, the client we use is

[github.com/xetorthio/j…] :

The official preferred recommended client,Maven’s package is

Jedis introduction

<dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
    <version>2.9. 0</version>
    <type>jar</type>
    <scope>compile</scope>
</dependency>

Copy the code

Official provided Demo

    @Test
    public void ConnectionTest(a){
        //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();
   }
Copy the code

Pooled connections

    @Test
    public void ConnectionPoolTest(a){
        // Connection pool Settings
        JedisPoolConfig config = new JedisPoolConfig();
        // Set the maximum number of connections
        config.setMaxTotal(30);
        // Set the maximum number of idle connections
        config.setMaxIdle(10);
        // Create a connection pool
        JedisPool jedisPool = new JedisPool(config, "127.0.0.1");
        // Obtain service resources
        Jedis jedis = jedisPool.getResource();
        jedis.select(1);
        jedis.set("username"."Roxin By Jedis Pool");
        System.out.println(jedis.get("username"));
        jedis.close();
        jedisPool.close();
    }
Copy the code

Sample code for Jedis

   @Test
    public void SetTest(a){
        Jedis jedis = jedisPool.getResource();
        String setKey1 = "SETKEY-1";
        for (int i = 0; i < 10; i++) {
            // Add an element
            jedis.sadd(setKey1,"value-"+i);
        }
        assert 10 == jedis.scard(setKey1); // Get the number of elements
        jedis.sadd(setKey1,"value-1");// Adding duplicate elements is invalid
        assert 10 == jedis.scard(setKey1);
        String s= jedis.srandmember(setKey1);// Get an element at random
        assert jedis.sismember(setKey1,s);// Whether to be a collection member
        String setKey2 = "SETKEY-2";
        for (int i = 1; i < 11; i++) {
            jedis.sadd(setKey2,"value-"+i);
        }
        assert jedis.sdiff(setKey1,setKey2).size() == 1;/ / complement
        assert jedis.sinter(setKey1,setKey2).size() == 9;/ / intersection
        assert jedis.sunion(setKey1,setKey2).size() == 11;/ / and set
        jedis.del(setKey1,setKey2);
        jedis.close();
    }
Copy the code

Cluster architecture The process of a Cluster query is as follows

The probable reason why the data cannot be queried is

  1. Serialization problem
  2. The socket cannot be queried when the Jedis problem is concurrent
  3. The problem of RedisTemplate
  4. Redis Cluster problem
  5. Redistribute card slots
  6. Connection timed out
  7. Bigkey
  8. Nic issue