我正在尝试使用aredis api连接redis服务器。由于服务器是安全的。尝试使用 AsyncRedisFactory.setAuth(主机,密码)进行身份验证; 经过身份验证的发送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);
当试图面对异常时,
线程“main”中的异常java.lang.ClassCastException:java.lang.String无法强制转换为org.aredis.io.ClassDescriptors at org.aredis.cache.RedisClassDescriptorStorage.getMasterClassDescriptors(RedisClassDescriptorStorage.java:120) 在org.aredis.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) at org.aredis.cache.RedisCommandObject.writeArg(RedisCommandObject.java:108) at org.aredis.cache.RedisCommandObject.generateRequestData(RedisCommandObject.java:192) at org.aredis.cache.RedisCommandList.generateRequestData(RedisCommandList.java:166) at org.aredis.cache.AsyncRedisConnection.submitCommands(AsyncRedisConnection.java:759) 在org.aredis.cache.AsyncRedisConnection.submitCommand(AsyncRedisConnection.java:847) at org.aredis.cache.AbstractAsyncRedisClient.submitCommand(AbstractAsyncRedisClient.java:74)
答案 0 :(得分:0)
在将另一个命令传递给Redis服务器之前先发送AUTH命令。</ p>
asynCon.submitCommand(RedisCommand.AUTH,密码);