rails - redis - zrange with scores - ubuntu - インストール + zrange でWITHSCORESをつけるオプション
ライブラリは以下を使用
type : redis client
library : redis-rb
git : https://github.com/ezmobius/redis-rb
# /path/to/app/Gemfile gem 'redis'
でbundle install
あまり乗り気じゃないけどグローバル変数にインスタンス突っ込む。
# /path/to/app/config/initializers/redis.rb $redis = Redis.new(:host => 'localhost', :port => 6379)
で
$redis.zrange("yourzset", 0, 10,'WITHSCORES')
とかやってみたけどscoreがとれなかった。
gitのソースを見てみると
def zrange(key, start, stop, options = {}) command = CommandOptions.new(options) do |c| c.bool :withscores c.bool :with_scores end synchronize do @client.call [:zrange, key, start, stop, *command.to_a] end end
となっていたので
$redis.zrange("yourzset", 0, 10,:withscores => true)
でとれた。