Hi, is there any possibility to pull elements from sorted set by score.For example, my sorted set consists of:[{1:a}, {2:b}, {3:c}, {5:d}, {7:d}]I do "pull" using score: (2,5)and set changes to:[{1:a}, {2:b}, {5:d}, {7:d}]and returned element is: {3:c}Is there any possibility to implement such functionality using other Redis data structures?
Also it's ok to pull elements from sorted head or tail.
I have only one solution in my mind:There are X concurrent sorted-set readers1. x1 sends zrangebyscore2. x1 iterates over elements and deletes them. If delete operation == 1, then x1 gets element exclusively3. Repeat 1..2 changing zrangebyscore range to get enough element.Looks ugly but could work?
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 http://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
Hi, thanks for the reply.The problem I'm trying to solve:I have events, each event has id.I put event to sorted set, where value is id and score = timestamp.The idea is to keep unique events id sorted by timestamp.I have application which wakes up each minute and gets events from sorted set by score range.The problem is that I can't run several instances of that application.I want to pull by score range so each application could get values from set.>Also it's ok to pull elements from sorted head or tail.I mean that I can redesign my algorithm and pull elements from head or tail of sorted set if it's hard to do pull by range.Right now I do get elements from sorted list by custom range.
> "scan for and optionally remove elements from a ZSET, returning the results to the caller", you should use a Lua script.Set should be sorted by score.And I need to pull it tail/head or by score range.From business point, it's triggers queue. Each trigger has id. Score = execution timestamp. I scan sorted set using score range to get triggers that could be executed (their score is in range).
четверг, 14 мая 2015 г., 16:32:58 UTC+3 пользователь Serega Sheypak написал:Hi, is there any possibility to pull elements from sorted set by score.For example, my sorted set consists of:[{1:a}, {2:b}, {3:c}, {5:d}, {7:d}]I do "pull" using score: (2,5)and set changes to:[{1:a}, {2:b}, {5:d}, {7:d}]and returned element is: {3:c}Is there any possibility to implement such functionality using other Redis data structures?Also it's ok to pull elements from sorted head or tail.I have only one solution in my mind:There are X concurrent sorted-set readers1. x1 sends zrangebyscore2. x1 iterates over elements and deletes them. If delete operation == 1, then x1 gets element exclusively3. Repeat 1..2 changing zrangebyscore range to get enough element.Looks ugly but could work?
--
You received this message because you are subscribed to a topic in the Google Groups "Redis DB" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/redis-db/D5AwILCV8SA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to redis-db+u...@googlegroups.com.
>Great. Use a Lua script. You can pull any range you want. The start, the end, the middle. You can pull by score or by index.I can't find api to pull from sorted set by score or index.
I have to write lua script, that:1. zrangebyscore using score range I need2. zrem elements from zrangebyscore result3. return zrangebyscore result for processing.And it guarantees me that each sorted list consumer using lua script would get unique result, correct?