gpt4 book ai didi

node.js - node_redis 获取 zrange withscores

转载 作者:IT王子 更新时间:2023-10-29 05:58:47 30 4
gpt4 key购买 nike

有谁知道我怎样才能通过 Node redis获得有分数的成员?我试过这样的事情:

client.ZRANGE(key, 0, -1, withscores, function(err, replies) {

});

谢谢。

最佳答案

这段代码看起来不错。查看以下链接以检索您想要的内容:

http://ricochen.wordpress.com/2012/02/28/example-sorted-set-functions-with-node-js-redis/

在此处添加该链接示例的代码,以防它被删除。

var rc=require('redis').createClient();
var _=require('underscore');

rc.zincrby('myset', 1, 'usera');
rc.zincrby('myset', 5, 'userb');
rc.zincrby('myset', 3, 'userc');
rc.zrevrange('myset', 0, -1, 'withscores', function(err, members) {
// the resulting members would be something like
// ['userb', '5', 'userc', '3', 'usera', '1']
// use the following trick to convert to
// [ [ 'userb', '5' ], [ 'userc', '3' ], [ 'usera', '1' ] ]
// learned the trick from
// http://stackoverflow.com/questions/8566667/split-javascript-array-in-chunks-using-underscore-js
var lists=_.groupBy(members, function(a,b) {
return Math.floor(b/2);
});
console.log( _.toArray(lists) );
});
rc.quit();

关于node.js - node_redis 获取 zrange withscores,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24157632/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com