Sha256: fac6e69fb203d6999e6abad755479a4a0f7d9faf7d5e5b39ca442f140cc3da21
Contents?: true
Size: 1.56 KB
Versions: 2
Compression:
Stored size: 1.56 KB
Contents
# RedisBackedModel Provides useful functions to objects that are backed by a Redis store instead of ActiveRecord. ## Installation Add this line to your application's Gemfile: gem 'redis_backed_model' And then execute: $ bundle Or install it yourself as: $ gem install redis_backed_model ## Usage Subclass your models from RedisBackedModel::RedisBackedModel ```ruby class Person < RedisBackedModel::RedisBackedModel end ``` When initializing a person, pass in a hash of attributes ```ruby p = Person.new({:id => 2, :first_name => "Bill", :last_name => "Smith"}) ``` RBM will create instance variables as needed ```ruby p.instance_variables => [:@id, :@first_name, :@last_name] ``` You can use RBM to get Redis commands that will save your object as a hash ```ruby p.to_redis => ["sadd|person_ids|2", "hset|person:2|id|2", "hset|person:2|first_name|Bill", "hset|person:2|last_name|Smith"] ``` You can parse these and pass them to Redis yourself or use the gem 'redis_pipeline': https://github.com/SeniorServiceAmerica/redis_pipeline Once your data is in Redis, you can use RBM to find and instantiate objects: ```ruby p = Person.find(2) => #<Person:0x00000104023a00 @id=2, @first_name=Bill, @last_name=Smith> ``` You can also find multiple records: ```ruby p = Person.find([1,2,3]) => [person,person,person] ``` ## Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Added some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
redis_backed_model-1.0.1 | README.md |
redis_backed_model-1.0.0 | README.md |