Redis supports the Rails model

I am looking for something where I can save the entire Rails-based model stored in Redis. There are Redis objects that are located here https://github.com/nateware/redis-objects , but this only works when your model is already supported by something like ActiveRecord and it requires a unique identifier generator. I do not want to create a backup ActiveRecord model, because I want to store everything directly in memory, not in the database.

Is there any way to remove a tool that I can use right now, which will allow me to do things like:

RedisBackedModel.find_by_name('foo')

and it will return me the RedisBackedModel from Redis?

+5
source share
1 answer

Ohm , ; . , DataMapper redis adapter, . , , :

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

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

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

# Search by id (like AR-style model.get(id)):
RedisBackedModel[1]
+6

All Articles