No commit activity in last 3 years
No release in over 3 years
Adds fast-map to a AR model
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

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