zrangebyscore redis in perl



我在perl-scrpit中使用Redis.pm,并尝试执行下一个命令:

zrevrangebyscore <key> <highscore> 0 WITHSCORES LIMIT 0 1

在有redis文档的设备中,我接下来会写,它运行良好

my $data = { $redis->zrevrangebyscore($rkey, $ipl, 0, 'WITHSCORES') };

但当我试图突破极限时在perl命令中:

my $data = { $redis->zrevrangebyscore($rkey, $ipl, 0, 'WITHSCORES','LIMIT 0 1') };

我收到错误

[zrevrangebyscore] ERR syntax error,  at /usr/local/lib/perl5/site_perl/5.14/Redis.pm line 163
    Redis::__ANON__(undef, 'ERR syntax error') called at /usr/local/lib/perl5/site_perl/5.14/Redis.pm line 195
    Redis::wait_one_response('Redis=HASH(0x801075300)') called at /usr/local/lib/perl5/site_perl/5.14/Redis.pm line 183
    Redis::wait_all_responses('Redis=HASH(0x801075300)') called at /usr/local/lib/perl5/site_perl/5.14/Redis.pm line 172

如何在Redis.pm中传递参数"LIMIT 0 1"?

答案是:

my $data = { $redis->zrevrangebyscore($rkey, $ipl, 0, 'WITHSCORES', qw{LIMIT 0 1})};

也许它对某人有用。谢谢

如果您只是想迭代您的排序集,并且总是获取最高的条目,只需使用

zrange

(zrange文档)

而不是zrevrangebyscore。

my $start = -1; #-1 is last element = the element with the highest score
my $stop = -1;
while (my $data = $redis->zrange($rkey, $start--, $stop--, 'WITHSCORES')) {
   #fetch the ultimate element, then the penultimate, etc....
};

最新更新