简体   繁体   中英

Why can't I turn this Redis query result directly into a hash?

This is confusing me to no end. Why am I unable to perform this operation directly on the query?

(rdb:1) $redis.zrange(key(p_id, range), 0, -1, {withscores: true})
["2008", "15769"]

(rdb:1) Hash["2008", "15769"]
{"2008"=>"15769"}

(rdb:1) Hash($redis.zrange(key(p_id, range), 0, -1, {withscores: true}))
NoMethodError Exception: undefined method `Hash' for Player:Module

(rdb:1) Hash[$redis.zrange(key(p_id, range), 0, -1, {withscores: true})]
{}

You should unpack the arguments:

Hash[*$redis.zrange(key(p_id, range), 0, -1, {withscores: true})]

Hash#[] takes also an array of pairs, so if the result is always a pair:

Hash[[$redis.zrange(key(p_id, range), 0, -1, {withscores: true})]]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM