Ohm and Transactions?

51 views
Skip to first unread message

Michael Gorsuch

unread,
Apr 16, 2011, 11:32:50 AM4/16/11
to ohm-...@googlegroups.com
Hello - I'm rather new to Ohm and Redis, and am trying to grasp on how I might employ transactions to ensure that one object cannot be created without another.  If this is the wrong way to approach things in this space, perhaps someone could suggest a different pattern.  

My example is a simple multi-tenant app that has both Account and User objects.  An account can have multiple users, a single user can belong to a single Account.  This is all very easy to model in Ohm (thank you!), but my business logic requires that Accounts cannot exist without Users, and Users cannot exist without accounts.  Basically, I don't want orphaned objects around.

On account signup for the first user, my plan was to try and use Ohm.redis.multi {} to create an Account and a User object together.  If one of those events failed, I'd raise and exception and Redis will presumably act like nothing ever happened.  However, when I try and do something like this, everything just blocks.

Ohm.redis.multi do 
  Account.create
  User.create
end

I can do things like this without issue:

Ohm.redis.multi do
  Ohm.redis.set "foo", "baz"
  Ohm.redis.set "bar", "neato"
end

My guess is that these things can't work together.  

Can you offer any suggestions?  

All the Best,

Michael Gorsuch

Damian Janowski

unread,
Apr 19, 2011, 3:01:32 PM4/19/11
to ohm-...@googlegroups.com

This is currently not supported in Ohm.

When you call Account.create we still need to read some values,
something that can't work inside a MULTI block.

Michael Gorsuch

unread,
Apr 19, 2011, 3:11:35 PM4/19/11
to ohm-...@googlegroups.com
Okay!  I worked up a small pattern to work with this.  

Thanks for the reply.

Michael
Reply all
Reply to author
Forward
0 new messages