diff --git a/src/main/java/redis/clients/jedis/Connection.java b/src/main/java/redis/clients/jedis/Connection.java index a214750781..2d0dd94da1 100644 --- a/src/main/java/redis/clients/jedis/Connection.java +++ b/src/main/java/redis/clients/jedis/Connection.java @@ -354,40 +354,46 @@ private void initializeFromClientConfig(JedisClientConfig config) { auth(credentialsProvider); } - try { - List fireAndForgetMsg = new ArrayList<>(); - - int dbIndex = config.getDatabase(); - if (dbIndex > 0) { - fireAndForgetMsg.add(new CommandArguments(Command.SELECT).add(Protocol.toByteArray(dbIndex))); - } + List fireAndForgetMsg = new ArrayList<>(); - String clientName = config.getClientName(); - if (clientName != null) { - fireAndForgetMsg.add(new CommandArguments(Command.CLIENT).add(Keyword.SETNAME).add(clientName)); - } + int dbIndex = config.getDatabase(); + if (dbIndex > 0) { + fireAndForgetMsg.add(new CommandArguments(Command.SELECT).add(Protocol.toByteArray(dbIndex))); + } - String libName = JedisMetaInfo.getArtifactId(); - if (libName != null) { - fireAndForgetMsg.add(new CommandArguments(Command.CLIENT).add(Keyword.SETINFO) - .add(ClientAttrOption.LIB_NAME.getRaw()).add(libName)); - } + String clientName = config.getClientName(); + if (clientName != null) { + fireAndForgetMsg.add(new CommandArguments(Command.CLIENT).add(Keyword.SETNAME).add(clientName)); + } - String libVersion = JedisMetaInfo.getVersion(); - if (libVersion != null) { - fireAndForgetMsg.add(new CommandArguments(Command.CLIENT).add(Keyword.SETINFO) - .add(ClientAttrOption.LIB_VER.getRaw()).add(libVersion)); - } + String libName = JedisMetaInfo.getArtifactId(); + if (libName != null) { + fireAndForgetMsg.add(new CommandArguments(Command.CLIENT).add(Keyword.SETINFO) + .add(ClientAttrOption.LIB_NAME.getRaw()).add(libName)); + } - for (CommandArguments arg : fireAndForgetMsg) { - sendCommand(arg); - } + String libVersion = JedisMetaInfo.getVersion(); + if (libVersion != null) { + fireAndForgetMsg.add(new CommandArguments(Command.CLIENT).add(Keyword.SETINFO) + .add(ClientAttrOption.LIB_VER.getRaw()).add(libVersion)); + } - // getMany and ignore result - getMany(fireAndForgetMsg.size()); + for (CommandArguments arg : fireAndForgetMsg) { + sendCommand(arg); + } - } catch (JedisDataException e) { - // just ignore dataException, such as unknown command + List objects = getMany(fireAndForgetMsg.size()); + for (Object obj : objects) { + if (obj instanceof JedisDataException) { + JedisDataException e = (JedisDataException)obj; + String errorMsg = e.getMessage().toUpperCase(); + if (errorMsg.contains("UNKNOWN") || + errorMsg.contains("NOAUTH")) { + // ignore + } else { + throw e; + } + } } } catch (JedisException je) { try { diff --git a/src/test/java/redis/clients/jedis/JedisPooledTest.java b/src/test/java/redis/clients/jedis/JedisPooledTest.java index 34eb166756..ac06efa975 100644 --- a/src/test/java/redis/clients/jedis/JedisPooledTest.java +++ b/src/test/java/redis/clients/jedis/JedisPooledTest.java @@ -243,6 +243,9 @@ public void cleanUp() { assertEquals(1, prepareCount.get()); assertEquals(1, cleanupCount.get()); + // clear existing `noauth` links + pool.getPool().clear(); + pool.set("foo", "bar"); assertEquals("bar", pool.get("foo")); assertEquals(2, prepareCount.get());