ruby - batch/multi with redis to sum different keys -


i know using multi execution of redis commands delayed until block finished.

how can use multi (or similar) send 1 redis request, yet still able calculate using data returned?

example - user has many friends. each friend has own set of friends. want count how many friends of friends (with duplication) each user has

$redis.multi   friends_of_friends = user.friends.map(&:friends_count) end  friend_of_friends.inject(&:+) 

is possible?

what primary goal you're trying achieve? multi/exec ensure bulk of commands executed 1 block (i.e. atomically) - trying read , write based on response isn't possible.

the way redis use watch directive optimistic locking - exec error if watched keys changed. alternatively, should consider using lua script embed read & write logic - ensure atomicity, require single request redis , save network overhead.


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -