zpopbyscore( key, score_start, score_end, count ){
data = zrangebyscore key score_start score_end count;
for( val : data) {
zrem key val
}
print(data)
}
Now, we can add sort queue with zset, and atom-sort-pop with zset. Don't say use LUA Script, is a bad idea
eq:
push{
zadd key time() xxx1
zadd key time()+1 xxx2
...
...
}
pop {
data = zrangebyscore key 0 time() 100
for(val : data) {
todo(val)
}
}
Comment From: yiwiz-sai
I remembered this feature has been mentioned many years, but still not added... I really hope redis has "zpop" . nobody like "watch/exec" even though it works.
Comment From: luca-saggese
I've made this Lua script fo zpoopbyscore if can be useful
local keys = redis.call('zrangebyscore', KEYS[1], ARGV[1], ARGV[2], 'limit', 0, ARGV[3]);
if #keys == 0 then
return {};
end
local values = redis.call('mget', unpack(keys))
local results = {};
for i, key in ipairs(keys) do
if values[i] then
table.insert(results, keys[i]);
table.insert(results, values[i]);
end
redis.call('zrem', KEYS[1], keys[i]);
end
return results;