Redis Future + Rails

I use redis in one of my rails projects where I tried to combine redis sets like

$redis.smembers('set1') | $redis.smembers('set2') 

but it causes an error like this

 undefined method `|' for #<Redis::Future:0x000001306e5830> 

What is Redis::Future ? I use redis and redis-store gems

thanks

+4
source share
2 answers

Future objects are usually returned when invoking methods in a pipeline or transaction.

The return value is only available when the EXEC command has been applied to the Redis server. With redis-rb, this means you must exit the pipeline or several blocks earlier.

If you want to select / read data, do this before the multi / exec block and only write to the multi / exec block.

By the way, it is more efficient to use $ redis.sunion () to generate a server-side result.

+6
source

What Didier said, and also check that your code is not working inside the multi block, for example:

 $redis.multi do $set1 = $redis.smembers("set1") end 

In this case, $set1 is the "future" indicating the result you will get as soon as the block exists.

You can get the real base value by calling $set1.value .

+4
source

Source: https://habr.com/ru/post/1416132/


All Articles