go-redis
go-redis copied to clipboard
Questions about keyspace subscribe
I'm using keyspace notification in redis. Let's say the key I'm interesting in
the key-space event of testkey
With redis-cli, I can use PSUBSCRIBE
with the pattern _keyspace@*__:testkey
successfully.
127.0.0.1:6379> PSUBSCRIBE __keyspace@*__:testkey
Reading messages... (press Ctrl-C to quit)
1) "psubscribe"
2) "__keyspace@*__:testkey"
3) (integer) 1
1) "pmessage"
2) "__keyspace@*__:testkey"
3) "__keyspace@0__:testkey"
4) "set"
1) "pmessage"
2) "__keyspace@*__:testkey"
3) "__keyspace@0__:testkey"
4) "set"
But in go, the above pattern following pattern won't work. Here's code sample
subPattern := "__keyspace@*__:testkey"
sub := a.redisClient.PSubscribe(subPattern)
log.Printf("watching %v", subPattern)
//lastScore := util.TimeNowMillis()
for {
msg, err := sub.Receive()
if err != nil {
log.Println(err)
continue
}
log.Println(msg)
//switch msg.(type) {
}
But this pattern __keyspace@*__:testkey*
, with a wildcard suffix, works.
I've tested and see that this issue happen with both redis single instance and in cluster mode. I've tested this with other golang redis lib yet.
Is this an expected behaviors? If so, may I have a link to read more about keyspace patterns?