I am using Jedis java client for redis. My requirement is that when someone add item to list, say mylist by doing jedisClient.lpush("mylist", "this is my msg"), I need to get notification. Is this possible ?
1 Answers
Yes, it is possible to achieve that in one of two ways.
The first approach is to use Redis' keyspace notifications. Configure Redis to generate list events with the following configuration directive:
CONFIG SET notify-keyspace-events El
Then, subscribe to the relevant channel/channels. If you want to subscribe only to mylist
's changes, do:
SUBSCRIBE __keyevent@0__:mylist
Or, use PSUBSCRIBE and listen to events to matching key names that match a pattern.
Note, however, that keysapce notifications will not provide the actual pushed value. You can use Lua scripts as an alternate approach and implement your own notifications mechanism. For example, use the following script to push and publish a custom message to a custom channel:
local l = redis.call("LPUSH", KEYS[1], ARGS[1])
redis.call("PUBLISH", "mylistnotif:" .. KEYS[1], "Pushed value " .. ARGS[1])
return l
Make sure that "someone" uses that script to do the actual list-pushing and subscribe to the relevant channel/channels.

- 47,336
- 7
- 91
- 117
-
Thanks for reply. I will try this. Another thing I want to ask, I am doing this for storing logs on Redis and then showing them to client on browser in real time. Will this publish/subscribe thing slow down my app or should I do **polling**(querying via ajax) from client to redis ? – Bhushan Jan 03 '15 at 16:22
-
Sounds like another question... :) – Itamar Haber Jan 03 '15 at 20:25
-
...and would appreciate marking this as the answer. – Itamar Haber Jan 05 '15 at 16:35