I want to increment another key when a key expires in Redis,
I found Redis Keyspace Notifications. However, it seems to only support client subsciptions.
Is it possible to set an action on expiration in redis-server itself?
Related
I want to delete all keys from redis cluster by using fast process. I know how to delete the keys by using "redis-cli FLUSHALL". But this command can be slow when the data set is large. I heard that all keys can be cleared from redis cache by re-starting the redis service. I am testing this process on my local mac laptop. I am performing following steps:-
Setting many number of keys on my local redis server by using example command redis-cli SET mykey1 "Hello"
Then Re-starting the redis service "brew services restart redis" in the hope that all keys will be deleted when the service will be back up
Then getting the keys by giving "redis-cli KEYS '*'" command
I still see the keys after step-3
The keys are gone only when I give this command--> redis-cli FLUSHALL? How I can clear the keys by re-starting the redis service locally on my mac laptop first then I will try on QA servers?
You see the keys after restart because there is either RDB or AOF persistence enabled. See https://redis.io/topics/persistence.
RDB is enabled by default. To disable persistence, you need to edit your redis.conf or start as redis-server --save "" --appendonly no
See Is there a way to flushall on a cluster so all keys from master and slaves are deleted from the db on how to use redis-cli to send the command to all cluster nodes.
As dizzyf indicates, use FLUSHALL ASYNC to have the deletion performed in the background. This will create fresh hash maps for each database, while the old ones are deleted (memory reclaimed) progressively by a background thread.
In redis 4.0 and greater, the FLUSHALL ASYNC command was introduced, as a way to delete all the keys in a non-blocking manner. Would this solve your issue?
https://redis.io/commands/flushall
Thank you for links. These were very helpful. I was able to achieve the result by making changes to my redis.conf file with--> redis-server --save "" and --appendonly no. So after these changes, when I now re-start redis service nothing is saved.
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.
I use redis on Ubuntu machine to store some keys with expiration, but in testing server (Ubuntu) my keys get deleted/disappears before expiration. Key was set to expire for 24hours but was already gone after 4 hours or so.
I know that ttl is correct and set in seconds and I do not see any key flush in history.
I also checked redis info maxmemory:0 (not set) and evicted_keys:0, so I assume it is not memory problem.
What could cause removal of my keys?
Maybe there is some script in server that might delete keys? If so how could I track such script?
It seems there are still some keys left after i ran redis SHELL command flushdb,
what are these keys used for and why flushdb does not work?
When Redis runs flushdb command, it blocks any new writings to the database, and flushes all keys in the database. However, when Redis finishes the flushdb command, it can receive new writings, i.e. other Redis client can put new keys into the database.
In your case, I think there're other clients constantly writing to the database. So after you flush the database, new keys are put into Redis by other clients.
If you want to stop any further writing, you have to shutdown Redis server.
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.