No commit activity in last 3 years
No release in over 3 years
Simple ActiveModel-compatible persistence layer in Redis
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.0
>= 0
>= 0
>= 0
~> 0.8.0

Runtime

~> 0.0.19
 Project Readme

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
    # => #<Redis client v2.2.2 connected to redis://127.0.0.1:6379/0 (Redis v2.4.1)>

    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: {"id"=>1, "title"=>"The Thing", ...}>

    article.title
    # => The Thing!

    article.created.year
    # => 2011

    article.title = 'The Cabin'
    article.save
    # => <Article: {"id"=>1, "title"=>"The Cabin", ...}>

See the examples/article.rb for full example.


(c) 2011, Social Insider, s.r.o., released under the MIT License.