node.js - Use zscan on score -
according https://github.com/noderedis/node_redis/issues/896
i have zset , saving tokens(element) corresponding timestamp(score)
now want delete tokens older particular timestamp using zscan.
redis.zscan('my_key', cursor[i], 'match', '*', "count", count, function(err, console.log(err); console.log(reply); });
problem having zscan return values irrespective of timestamp.
'match' paramter checks pattern on elements(token). want tokens older particular timestamp(score).
for example :
var startingtime = new date().gettime(); redis.zrangebyscore("iflychat_auth_token", 0, startingtime - 43200000 * 2 * 7, function (error, data) { // return token older 7 days. });
is there way use 'match' on score
redis.zscan('my_key', cursor[i], 'match', < timestamp, "count", count, function(err, console.log(err); console.log(reply); });
zscan
doesn't have score range option. simplest alternative using redis' zremrangebyscore
, possibly so:
redis.zremrangebyscore('my_key','-inf', timestamp, function(error,data) { ... });
note: if need exclusive range, i.e. < timestamp
, prepend (
when sending value.
Comments
Post a Comment