我正在使用JDK 1.8,但无法弄清楚为什么 publish 不能正常工作。 Redis的“ set ”命令适用于数据。
<dependency>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
<version>5.0.1.RELEASE</version>
</dependency>
代码段:
RedisClient redisClient = RedisClient.create(redisURI);
connection = redisClient.connect();
String l_message = l_eventObject.toString();
connection.sync().publish(l_namespace, l_message);
connection.flushCommands(); // added this to see if this works
调试日志中的输出:
01:25:44.826 [Thread-3] DEBUG io.lettuce.core.RedisChannelHandler - dispatching command AsyncCommand [type=PUBLISH, output=IntegerOutput [output=null, error='null'], commandType=io.lettuce.core.protocol.Command]
01:25:44.826 [Thread-3] DEBUG io.lettuce.core.protocol.DefaultEndpoint - [channel=0xb75e3dc8, /10.1.1.202:59522 -> /10.1.1.44:6379, epid=0x1] write() writeAndFlush command AsyncCommand [type=PUBLISH, output=IntegerOutput [output=null, error='null'], commandType=io.lettuce.core.protocol.Command]
01:25:44.827 [Thread-3] DEBUG io.lettuce.core.protocol.DefaultEndpoint - [channel=0xb75e3dc8, /10.1.1.202:59522 -> /10.1.1.44:6379, epid=0x1] write() done
01:25:44.827 [lettuce-nioEventLoop-4-1] DEBUG io.lettuce.core.protocol.CommandHandler - [channel=0xb75e3dc8, /10.1.1.202:59522 -> /10.1.1.44:6379, chid=0x1] write(ctx, AsyncCommand [type=PUBLISH, output=IntegerOutput [output=null, error='null'], commandType=io.lettuce.core.protocol.Command], promise)
01:25:44.829 [lettuce-nioEventLoop-4-1] DEBUG io.lettuce.core.protocol.CommandEncoder - [channel=0xb75e3dc8, /10.1.1.202:59522 -> /10.1.1.44:6379] writing command AsyncCommand [type=PUBLISH, output=IntegerOutput [output=null, error='null'], commandType=io.lettuce.core.protocol.Command]
01:25:44.830 [lettuce-nioEventLoop-4-1] DEBUG io.lettuce.core.protocol.CommandHandler - [channel=0xb75e3dc8, /10.1.1.202:59522 -> /10.1.1.44:6379, chid=0x1] Received: 4 bytes, 1 commands in the stack
01:25:44.831 [lettuce-nioEventLoop-4-1] DEBUG io.lettuce.core.protocol.CommandHandler - [channel=0xb75e3dc8, /10.1.1.202:59522 -> /10.1.1.44:6379, chid=0x1] Stack contains: 1 commands
01:25:44.831 [lettuce-nioEventLoop-4-1] DEBUG io.lettuce.core.protocol.RedisStateMachine - Decode AsyncCommand [type=PUBLISH, output=IntegerOutput [output=null, error='null'], commandType=io.lettuce.core.protocol.Command]
01:25:44.831 [lettuce-nioEventLoop-4-1] DEBUG io.lettuce.core.protocol.RedisStateMachine - Decoded AsyncCommand [type=PUBLISH, output=IntegerOutput [output=0, error='null'], commandType=io.lettuce.core.protocol.Command], empty stack: true
01:25:44.831 [Thread-3] DEBUG io.lettuce.core.protocol.DefaultEndpoint - [channel=0xb75e3dc8, /10.1.1.202:59522 -> /10.1.1.44:6379, epid=0x1] flushCommands()
01:25:44.831 [Thread-3] DEBUG io.lettuce.core.protocol.DefaultEndpoint - [channel=0xb75e3dc8, /10.1.1.202:59522 -> /10.1.1.44:6379, epid=0x1] flushCommands() Flushing 0 commands
答案 0 :(得分:0)
可能的解决方案:
async.multi();
async.publish(l_namespace, l_message);
async.set(l_key, l_message); // for late subscribers to catch up
async.exec();