我正在尝试使用 aredis api 连接 redis 服务器。由于服务器是安全的。我正在尝试使用AsyncRedisFactory.setAuth(host, password);进行身份验证 经过身份验证发送 set 命令在 redis db 中写入一些值。
AsyncRedisConnection asynCon = null;
AsyncRedisFactory.setAuth(host, password);
AsyncRedisFactory factory = new AsyncRedisFactory(null);
factory.setPoolSize(100);
RedisServerInfo info = new RedisServerInfo(host, port);
asyncPool = factory.getConnectionPool(info);
asyncPool.setPoolSize(100);
String value = "Testing jedis....";
Future<AsyncRedisConnection> futureCon = asyncPool.borrow((int) (Math.random() * asyncPool.getPoolSize()));
asynCon = futureCon.get(5, TimeUnit.SECONDS);
String key = "TEST_KEY";
byte[] valueStore;
Object object = null;
valueStore = SerializationUtils.serialize(value);
asynCon.submitCommand(RedisCommand.SET, key, valueStore);
System.out.println("Set Command....completed...");
asyncPool.returnToPool(asynCon);
当尝试面对以下异常时,
线程“主”java.lang.ClassCastException 中的异常:java.lang.String 无法转换为 org.aredis.cache.RedisClassDescriptorStorage.getMasterClassDescriptors(RedisClassDescriptorStorage.java:120) 的 org.aredis.io.ClassDescriptors。 io.OptiObjectOutputStream.(OptiObjectOutputStream.java:88) 在 org.aredis.io.OptiObjectOutputStream.(OptiObjectOutputStream.java:106) 在 org.aredis.cache.JavaHandler.optiWriteObject(JavaHandler.java:150) 在 org.aredis.cache .JavaHandler.serialize(JavaHandler.java:225) 在 org.aredis.cache.RedisCommandObject.writeArg(RedisCommandObject.java:108) 在 org.aredis.RedisCommandObject.generateRequestData(RedisCommandObject.java:192) 在 org.aredis。 cache.RedisCommandList.generateRequestData(RedisCommandList.java:166) 在 org.aredis.cache.AsyncRedisConnection。submitCommands(AsyncRedisConnection.java:759) at org.aredis.cache.AsyncRedisConnection.submitCommand(AsyncRedisConnection.java:847) at org.aredis.cache.AbstractAsyncRedisClient.submitCommand(AbstractAsyncRedisClient.java:74)