Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing a new Error for watch exception #772

Open
GustavoCaso opened this issue Aug 9, 2018 · 0 comments
Open

Introducing a new Error for watch exception #772

GustavoCaso opened this issue Aug 9, 2018 · 0 comments

Comments

@GustavoCaso
Copy link
Contributor

GustavoCaso commented Aug 9, 2018

I noticed that the python redis library will raise an exception when you are watching any key.

In my opinion, think is quite useful when you are inside loops and using watch method.

Here is an example:

  while Time.now.to_i < threshold do
    begin
      client.watch("market:", buyer) do
        price = client.zscore("market:", item).to_i
        funds = client.hget(buyer, 'funds')

        if price != seller_price || price > funds
          client.unwatch
          break
        end

        client.multi do |multi|
          multi.hincrby(seller, 'funds', price)
          multi.hincrby(buyer, 'funds', price * -1)
          multi.sadd(inventory, itemid)
          multi.zrem('market:', item)
        end

        break
      end
    rescue Redis::WatchError
      next
    end
  end

I would like to know if you think it something useful and if so I do not mind working on a PR to add it

@GustavoCaso GustavoCaso changed the title Introducing a new Error Introducing a new Error for watch exception Aug 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant