I am using redis in one of my rails project where I tried to union the sets of redis like
$redis.smembers('set1') | $redis.smembers('set2')
but it throws error like this
undefined method `|' for #<Redis::Future:0x000001306e5830>
What is Redis::Future
? I am using redis and redis-store gems
Thank you
Future objects are typically returned when methods are called in a pipeline or a transaction.
The returned value is only available when the EXEC command has been applied to the Redis server. With redis-rb, it means you should exit a pipelined or multi block before.
If you want to select/read data, do it before the multi/exec block, and do only write in the multi/exec block.
By the way, it will be more efficient to use $redis.sunion() to generate the result on server-side.
What Didier said, plus check that your code is not running inside a multi
block, like this:
$redis.multi do
$set1 = $redis.smembers("set1")
end
In that case, $set1
is a "future" pointing to the result you'll get as soon as the block exists.
You can access the real, underlying value by calling $set1.value
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With