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

Transactions (MULTI) support #7

Open
Sija opened this issue Dec 15, 2017 · 7 comments
Open

Transactions (MULTI) support #7

Sija opened this issue Dec 15, 2017 · 7 comments

Comments

@Sija
Copy link

Sija commented Dec 15, 2017

As per https://redis.io/topics/transactions.

@soveran
Copy link
Owner

soveran commented Dec 15, 2017

Hello @Sija, Ohm uses Lua scripts in order to make operations atomic. In the past, before scripts were available, we relied on MULTI/EXEC. If you have something else in mind, please let me know and we can analize the use case. Thanks!

@Sija
Copy link
Author

Sija commented Dec 15, 2017

I'd need to have transaction(&block) method with rollback support in case an Exception is thrown during block execution.

My use case is as follows:

store = Store::Redis.new

store.transaction do
  store.clear # persist only when `#update` call below succeeds.
  store.update(fetch_data)
end

@soveran
Copy link
Owner

soveran commented Dec 15, 2017

Ah, I'm afraid it's not possible with either MULTI/EXEC or Lua scripts.

@Sija
Copy link
Author

Sija commented Dec 15, 2017

IIRC it has been implemented by crystal-redis shard.

@soveran
Copy link
Owner

soveran commented Dec 15, 2017

Gotcha! Ohm is like an ORM for Redis, while crystal-redis is a Redis client. Ohm uses a different Redis client called Resp. With Resp you can build transactions with MULTI/EXEC and you can pipeline commands. I think we can discuss your use case so I can give you an example of how to solve the problem with Resp, sounds good?

@Sija
Copy link
Author

Sija commented Dec 15, 2017

I'm aware of that, yet I couldn't find anything about MULTI/EXEC in Resp. It's great if that's already possible, I'd love to hear more! :)

@soveran
Copy link
Owner

soveran commented Dec 18, 2017

Here's an example of how you can use MULTI/EXEC with Resp:

c = Resp.new("redis://localhost:6379")

c.queue("MULTI")
c.queue("ECHO", "hello")
c.queue("ECHO", "world")
c.queue("EXEC")

assert_equal ["hello", "world"], c.commit.last

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

2 participants