I am trying to receive invalidation message from local redis setup using the client tracking feature in Redis. It basically publishes key that was updated in redis on “__redis__:invalidate” pubsub channel, so this key can be evicted from client side cache.
It throws error of unsupported pubsub message: “invalidate” for go-redis v9 but works fine for v8.
The code I am trying is :
package main
import (
"context"
"fmt"
"time"
"github.com/redis/go-redis/v9"
//"github.com/go-redis/redis/v8"
)
func main() {
ctx := context.Background()
redisOptions := &redis.Options{
Addr: "localhost:6379",
OnConnect: func(ctx context.Context, cn *redis.Conn) error {
cid := cn.ClientID(ctx).Val()
return cn.Process(ctx, redis.NewBoolCmd(ctx, "CLIENT", "TRACKING", "ON", "REDIRECT", fmt.Sprintf("%v", cid), "BCAST", "PREFIX", "my"))
},
}
redisClient := redis.NewClient(redisOptions)
pubsub := redisClient.Subscribe(ctx, "__redis__:invalidate")
go func() {
defer pubsub.Close()
for {
fmt.Println("Listening...")
msg, err := pubsub.ReceiveMessage(ctx)
if err != nil {
fmt.Println(err) //This error is thrown
}
fmt.Println(msg)
}
}()
time.Sleep(30 * time.Second)
}
The steps to reproduce are :
- start local redis server
- Run the above script
- Run command
SET my-key "val"
in redis cli
boomerang is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.