Quantcast
Channel: Active questions tagged redis+ruby-on-rails - Stack Overflow
Viewing all articles
Browse latest Browse all 873

Redis gem watch and unwatch confusion

$
0
0

According to the redis-rb ruby gem docs;

redis.watch("key") do if redis.get("key") == "some value"  redis.multi do |multi|   multi.set("key", "other value")   multi.incr("counter")  end else  redis.unwatch endend

I have two questions about this;

  1. Why is the unwatch line required? My thought is that if key == "some value", set "key" to other value and increase counter if "key" has not changed by the time EXEC is called. In my mind, the else statement never gets executed in this scenario. If you run this code without the else/unwatch, nil is returned.
  2. If redis.watch "key" is entered without a block (redis.watch "key"); Why am I unable to unwatch a specific key? I get (wrong number of arguments (given 1, expected 0))??

Here is a link to the ruby gem https://github.com/redis/redis-rb


Viewing all articles
Browse latest Browse all 873

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>