Additional Keyspace Notification Info

24 views
Skip to first unread message

sra...@gmail.com

unread,
Jul 26, 2016, 11:20:16 PM7/26/16
to Redis DB
I have a sorted set, and when elements are removed using zrem, I need to know which elements were removed and what their scores were.

1. Is this supported by redis keyspace notifications?

2. If not, can anyone suggest a way to implement this functionality?

Thanks

Itamar Haber

unread,
Jul 27, 2016, 5:46:22 AM7/27/16
to Redis DB
Hi,

WRT 1 - no, it isn't. The keyspace notifications generated by Redis in general, and specifically for ZREM command, do not include the actual data - only the key's name and command.

WRT 2 - the easiest way of doing this is to use the PUBLISH command alongside calling ZREM. The following Lua script, for example, does this:

    for _, arg in pairs(ARGV) do
        local score = redis.call('ZSCORE', KEYS[1], arg)
        redis.call('PUBLISH', 'mychannel', 'key: ' .. KEYS[1] .. ', element: ' .. arg .. ', score: ' .. tostring(score))
    end

    redis.call('ZREM', KEYS[1], unpack(ARGV))

Assuming that this script is loaded to Redis (the SCRIPT LOAD command), you can call it as follows: EVALSHA <script-sha> 1 <zset-keyname> <1st element to remove> <2nd element> ....

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.



--

Itamar Haber | Chief Developer Advocate
Redis Watch Newsletter | &&(curat||edit||janit||)
Redis Labs ~/redis

Mobile: +972 (54) 567 9692
Email: ita...@redislabs.com
Twitter: @itamarhaber
Skype: itamar.haber

Blog  |  Twitter  |  LinkedIn


Reply all
Reply to author
Forward
0 new messages