据此https://github.com/NodeRedis/node_redis/issues/896
我有zset,我正在将标记(元素)保存到相应的时间戳(分数)
现在我想使用zscan删除比特定时间戳早的令牌。

redis.zscan('my_key', cursor[i], 'MATCH', '*', "COUNT", count, function(err,
  console.log(err);
  console.log(reply);
});

我遇到的问题是zscan将返回所有值,而不考虑时间戳。
此“match”参数检查元素(标记)上的模式。
我想得到比某个特定时间戳(分数)早的所有令牌。
例如:
var startingTime = new Date().getTime();


    redis.zrangebyscore("iflychat_auth_token", 0, startingTime - 43200000 * 2 * 7, function (error, data) {
       // This will return all token older the 7 days.
        });

有办法在得分时使用“匹配”吗
像这样的东西
redis.zscan('my_key', cursor[i], 'MATCH', < timestamp, "COUNT", count, function(err,
  console.log(err);
  console.log(reply);
});

最佳答案

ZSCAN没有分数范围选项。最简单的替代方法是使用redis'ZREMRANGEBYSCORE,可能是这样:

redis.zremrangebyscore('my_key','-inf', timestamp, function(error,data) { ... });

注意:如果您需要一个独占范围,即timestamp,则在发送值时用(前置。

关于node.js - 在分数上使用zscan,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38457723/

10-15 20:21