Module: Redis::Persistence

Extended by:
ActiveSupport::Concern
Defined in:
lib/redis/persistence.rb,
lib/redis/persistence/version.rb

Overview

Redis::Persistence is a lightweight object persistence framework, fully compatible with ActiveModel and based on Redis.

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

Basic example:

class Article
  include Redis::Persistence

  property :title
  property :body
  property :author, :default  => '(Unknown)'
  property :created
end

Article.create title: 'Hello World!', body: 'So, in the beginning...', created: Time.now.utc
article = Article.find(1)
# => <Article: {"id"=>1, "title"=>"Hello World!", ...}>
article.title
# => Hello World!
article.created.class
# => Time

See the examples/article.rb for full example.

Defined Under Namespace

Modules: ActiveModelIntegration, ClassMethods, InstanceMethods Classes: FamilyNotLoaded, RedisNotAvailable

Constant Summary collapse

DEFAULT_FAMILY =
'default'
VERSION =
"0.0.5"

Class Method Summary collapse

Class Method Details

.configObject



56
57
58
# File 'lib/redis/persistence.rb', line 56

def self.config
  @__config ||= Hashr.new
end

.configure {|config| ... } ⇒ Object

Yields:



60
61
62
# File 'lib/redis/persistence.rb', line 60

def self.configure
  yield config
end