This is my code
public void subscribeToEncounterCheckoutTimeChannel(){
logger.info("Inside subscribeXXXChannel()");
StatefulRedisClusterPubSubConnection<String, String> pubsubConnection = connectToRedisCluster.getClusterPubSubConnection();
pubsubConnection.setNodeMessagePropagation(true);
pubsubConnection.addListener(new RedisClusterPubSubAdapter(){
public void message(String pattern, String channel, String message) {
String msg = message;
logger.info("msg" + msg);
}
});
RedisClusterPubSubAsyncCommands<String, String> async = pubsubConnection.async();
PubSubAsyncNodeSelection<String, String> masters =async.upstream();
NodeSelectionPubSubAsyncCommands<String, String> commands = masters.commands();
logger.info("number of master nodes: "+masters.size());
commands.psubscribe("__keyspace@0__:"+CacheConstants.XXX+"*");
logger.info(commands.toString());
}
However, after entering the key and message, the system does not print any expiry messages.
I have tried to run the event information in individual nodes in a cluster with the following commands
`docker exec -it <ContainerID> sh
redis-cli -c config set notify-keyspace-events Kx
redis-cli -c
127.0.0.1:6379> CLUSTER NODES
127.0.0.1:6379> SETEX EncounterCheckoutTime:1 120 "Hello, Redis"
-> Redirected to slot [11230] located at 172.18.0.4:6379
OK
system changes the cluster host
172.18.0.4:6379> INFO keyspace
# Keyspace
db0:keys=1,expires=1,avg_ttl=9289'
found out the node in a cluster where the key got created and then run
`docker exec -it <ContainerID> sh
redis-cli -c -h <IP of keyspace server>
psubscribe '__keyspace@0__:EncounterCheckoutTime*'
or to subscribe keyspace and keyevents
psubscribe '__key*__:*'`
I see the system is printing the expired key information.
$ redis-cli -c -h 172.18.0.4
172.18.0.4:6379> psubscribe '__keyspace@0__:EncounterCheckoutTime*'
Reading messages... (press Ctrl-C to quit)
1) "psubscribe"
2) "__keyspace@0__:EncounterCheckoutTime*"
3) (integer) 1
1) "pmessage"
2) "__keyspace@0__:EncounterCheckoutTime*"
3) "__keyspace@0__:EncounterCheckoutTime:1"
4) "set"
1) "pmessage"
2) "__keyspace@0__:EncounterCheckoutTime*"
3) "__keyspace@0__:EncounterCheckoutTime:1"
4) "expire"