Redis Persistence
Redis::Persistence
is a lightweight object persistence framework,
fully compatible with ActiveModel, based on Redis,
easily used standalone or within Rails applications.
Installation
$ gem install redis-persistence
Features:
- 100% Rails compatibility
- 100% ActiveModel compatibility: callbacks, validations, serialization, ...
- No crazy
has_many
-type of semantics
- Auto-incrementing IDs
- Defining default values for properties
- Casting properties as built-in or custom classes
- Convenient "dot access" to properties (article.views.today)
- Support for "collections" of embedded objects (eg. article Ā» comments)
- Automatic conversion of UTC-formatted strings to Time objects
- Small: 1 file, ~ 200 lines of code
- Fast: ~2000 saves/sec, ~6000 finds/sec
Basic example
require 'redis/persistence'
Redis::Persistence.config.redis = Redis.new
class Article
include Redis::Persistence
property :title
property :body
property :author, :default => '(Unknown)'
property :created
end
Article.create title: 'The Thing', body: 'So, in the beginning...', created: Time.now.utc
article = Article.find(1)
article.title
article.created.year
article.title = 'The Cabin'
article.save
See the examples/article.rb
for full example.
(c) 2011, Ataxo Interactive, s.r.o., released under the MIT License.