Adds Redis-cached hash containing correspondence between row id and selected field to ActiveRecord models.
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib/redis/objects
spec
.gitignore
.rspec
.travis.yml
Gemfile
LICENSE.txt
README.md
Rakefile
init.rb
redis-objects-rmap.gemspec

README.md

Redis::Objects::RMap

Gem Version Travis CI Code Climate

Adds Redis-cached hash containing correspondence between row id and selected field to ActiveRecord models.

endorse

Installation

Add this line to your application's Gemfile:

gem 'redis-objects-rmap'

And then execute:

$ bundle

Or install it yourself as:

$ gem install redis-objects-rmap

Usage

class Foo < ActiveRecord::Base
  include Redis::Objects::RMap
  has_rmap :title # field to use as a title
end

Foo.create! :title => 'foo'
Foo.rmap # {1 => 'foo'} <- Does SQL request and puts to Redis
Foo.rmap # {1 => 'foo'} <- Gets from Redis without an SQL query

You can specify field to use as an ID source:

class Foo < ActiveRecord::Base
  include Redis::Objects::RMap
  has_rmap :title, :my_id
end

Or even specify lambdas to prepare your cache:

class Foo < ActiveRecord::Base
  include Redis::Objects::RMap
  has_rmap :title => lambda{|x| x.camelize}, :id => lambda{|x| x.to_s}
end
class Foo < ActiveRecord::Base
  include Redis::Objects::RMap
  has_rmap({:title => lambda{|x| x.camelize}}, :my_id)
end

License

It is free software, and may be redistributed under the terms of MIT license.

Bitdeli Badge