2013-05-02 43 views
2

我从IMDB(电影列表)从这里下载电影:http://www.imdb.com/interfaces这个Redis排序集中的顶级电影是什么?

我想算一个给定的电影是如何经常出现在列表中有帮助的Redis排序集合,但我有点疑惑的结果:

 
redis 127.0.0.1:6379> zrangebyscore 'movies:title' 5000 +inf WITHSCORES 
1) "Countdown" 
2) "5254" 
3) "The Bold and the Beautiful" 
4) "5322" 
5) "Days of Our Lives" 
6) "5451" 
7) "Neighbours" 
8) "6442" 
9) "The New Price Is Right" 
10) "7633" 
11) "Coronation Street" 
12) "8097" 

我想要最常出现在最上面的电影。另外,我对比分感到困惑。这5k,6k,7k是什么意思?

我用我的实验的脚本是一个Rake任务是这样的:

 
    task :import do 
    file = File.new(ENV['file']) 
    redis = Redis.new 
    file.each_line do |l| 
     if l =~ /^"(.*)"/ 
     puts $1 
     redis.zincrby 'movies:title', 1, $1 
     end 
    end 
+0

嗯。 Redis当然是正确的:cat db/movies_utf.txt | grep“我们的日子”| wc - > 5462 - >问题出在数据集中。 – poseid 2013-05-03 06:25:28

回答

1

您可能需要使用zrevrangebyscore代替zrangebyscore的尝试。

语法:

ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count] 

例如,你的情况:

zrangebyscore 'movies:title' +inf 5000 WITHSCORES 

Reference