how to make Redis expire event only send to one client - redis

If two same clients connect to a redis server,and register same listener on a key expire event,can I make redis server only send a expire event to one client ,not two clients

No, you can't do that with Redis Keyspace Notifications. Keyspace Notifications is just a special case of Pub/Sub. And Pub/Sub do not allow you to do this.

Related

Redis Keyspace notification not working for go-redis in cluster mode

I am using go-redis/v8 as a client library and its universal client to get/set etc.
I am subscribing to the keyspace notifications like the one below.
keyspace := fmt.Sprintf("__keyspace#%d__:%s", s.config.Redis.DB, key)
ch := s.rdb.GetClient().Subscribe(ctx, keyspace).Channel()
It seems subscriber is not getting any notification in cluster mode of Redis. But it's working in dev env when the Redis was set up in docker-compose in standalone mode. I was researching about this and what I found out from Redis documentation is -
Every node of a Redis cluster generates events about its own subset of the keyspace as described above. However, unlike regular Pub/Sub communication in a cluster, events' notifications are not broadcasted to all nodes. Put differently, keyspace events are node-specific. This means that to receive all keyspace events of a cluster, clients need to subscribe to each of the nodes.
But with go-redis as I am creating the universal client with all the node ip's why the subscriber is not working as expected?

when redis update, redis will send the update to my grpc server. How to implement it

When there's an update in redis, redis would send the update to my grpc server. How to implement it.
It looks like redis monitor command can get all updates in redis. I though I can parse data from redis monitor and send it to grpc server.
Is there a better solution?
Hope you want to notify when your value get updated in redis. If so, you can use redis keyspace notification to get notified about update. You need to subscribe this event, so redis will publish when ever update done. So you need to use any one of clients like node.js to subscribe those events, so you can do whatever you need from there.
You can get detailed explanation from following page with this example:
Reference: https://redis.io/topics/notifications
FYI: By default this notification will be disabled, if you want then you need to enable by update redis configuration and restart is needed to apply this configuration change.

Redis Pub/Sub persistence

I am working on redis SMQ persistence. My questions here is, While publisher publishing the messages, consumer has stopped suddenly. When consumer connects again, is it possible to subscribe messages from where it has stopped?
No - Redis' Pub/Sub has no persistence, and once a message has been published, it is sent only to the connected subscribed clients. Afterwards, the message is gone forever.
With standard Pub/Sub you can use Lua scripts to persist your message. You need to check whether you have a listener on channel or not. If not then storing your message with channel key on redis . When the subscriber cames back it checks if there is anything for him based on channel key. Second option is to use Redis Stream. Check this gist.
Plz use 2 redis connections: 1 pubsub, second - LPOP/RPOP

How to restart all subscriptions done by Redis after Redis is restarted?

Once the Redis server is restarted, how to start all the processes which were run by Redis instance?
Here in my application, I can see that Redis instance is created, but all the subscriptions which the Redis instance was doing, is not restarted. Hence application is not able to receive new messages from the event bus/ Redis bus.
You application needs to capture the disconnect event and, once the database is back online, reconnect to it and resubscribe to the relevant channels.

Redis PUB/SUB: how to ignore own messages?

The idea is:
I have N WCF services which connected and subscribed to the same Redis message channel. These services use this channel to exchange messages to sync some caches and other data.
How each service can ignore its own messages? I.e. how to publish to all but me?
It looks like Redis PUB/SUB doesn't support such filtration. So, the solution is to use set of individual channels for every publisher and common channel for subscription synchronization between them. Here is an golang example of no-echo chat application.