PIKA trouble02 — (error) ERR Syntax error, try CLIENT (LIST [order by [addr|idle]| KILL ip:port)

  1. Problem description

Redis was originally used, but now Pika is used. Springboot version 2.1.8 is used. ClientName is configured inside. There is no problem when starting, but the following exception information will be reported when using:

org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool] with root cause

redis.clients.jedis.exceptions.JedisDataException: ERR Syntax error, try CLIENT (LIST [order by [addr|idle]| KILL ip:port)

    @Bean
    public RedisConnectionFactory connectionFactory(RedisProperties redisProperties) {

        JedisClientConfiguration clientConfig = JedisClientConfiguration.builder()
                .clientName("zcx")
                .usePooling().poolConfig(getGenericObjectJedisPoolConfig(redisProperties)).and().readTimeout(redisProperties.getTimeout())
                .build();

        RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration(redisProperties.getHost());
        configuration.setPort(redisProperties.getPort());
        configuration.setPassword(RedisPassword.of(redisProperties.getPassword()));

        return new JedisConnectionFactory(configuration, clientConfig);
    }

  2. Solution

After searching, it is caused by the ClientName field. Just remove the ClientName configuration. The problem is found as follows:

Call creation connection in class GenericObjectPool

private PooledObject<T> create() throws Exception {
        ...

        final PooledObject<T> p;
        try {
            p = factory.makeObject();
        } catch (final Throwable e) {
            createCount.decrementAndGet();
            throw e;
        } finally {
            synchronized (makeObjectCountLock) {
                makeObjectCount--;
                makeObjectCountLock.notifyAll();
            }
        }
}

The client setname “zcx” command is called in the JedisFactory class, and an exception is thrown.

@Override
  public PooledObject<Jedis> makeObject() throws Exception {
    final HostAndPort hostAndPort = this.hostAndPort.get();
    final Jedis jedis = new Jedis(hostAndPort.getHost(), hostAndPort.getPort(), connectionTimeout,
        soTimeout, ssl, sslSocketFactory, sslParameters, hostnameVerifier);

    try {
      jedis.connect();
      if (password != null) {
        jedis.auth(password);
      }
      if (database != 0) {
        jedis.select(database);
      }
      if (clientName != null) {
        jedis.clientSetname(clientName);
      }
    } catch (JedisException je) {
      jedis.close();
      throw je;
    }

In the final analysis, pika does not support the client setname command, so when creating a connection, it cannot obtain the connection and report that the command is not supported

Read More: