Skip to content

inossidabile/redis-objects-rmap

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages