Redis backed Rails model

Go To


I am looking for something where I can keep an entire Rails based Model stored in Redis. There is Redis Objects that is found here but that only works when your model is already backed by something like ActiveRecord and it requires a unique id generator. I don't wish to make an ActiveRecord backed model, as I want to persist everything directly into memory and not into the database.

Is there a drop in tool that I can use right now that'll let me do things like:


and it'll retrieve me the RedisBackedModel from Redis?

2012-04-04 01:57
by randombits


I've used Ohm before for storing searches that expire after a couple hours; it's pretty nice. I think DataMapper also has a redis adapter, although I've never used it. Here's some Ohm code for what I think you're after:

class RedisBackedModel < Ohm::Model
  attribute :name
  index :name

rbm = RedisBackedModel.create :name => "foo" # => 1

# Search by name:
RedisBackedModel.find(:name => "foo")

# Search by id (like AR-style model.get(id)):
2012-04-04 03:05
by Abe Voelker
Did you used OHM with rails - Pravin Mishra 2014-01-07 12:22
They are complaining "Unfortunately we don't use ohm with rails at all (and never plan to)." - Pravin Mishra 2014-01-07 12:23
@PravinMishra Yes, I used it on a project a couple years ago when Rails 3.0 had just come out. It works fine - Abe Voelker 2014-01-12 00:14
thanks for the reference to Ohm! : - Tilo 2016-09-23 02:26