redis_storage_methods 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,15 +18,26 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- Presumably, you'll be passing hashes into your create method. Now you will need to pass them into your
21
+ What this Gem does is provides a framework mixin for your models that exposes new methods that allow you to save to redis when you save to the database, and let you get/update redis without getting/updating the database until later(maybe under a cron job or something.) This is great if you want all the speed of redis but the querying reporting ability of SQL.
22
+
23
+ When you create, normally you'll be passing hashes into your create method, most likely from form submission. Now you will need to pass them into your
22
24
 
23
25
  create_with_associations_and_redis(params)
24
26
 
25
- method. This is to differentiate between the two: This method will take your object and create it, and then store it in redis as a hash. It will not store it's associations unless you instruct it to do so. This is because redis has no ability to store foreign keyed objects, if a Battle has a Soldier in it, you can really only store it in a redis hash for Battle like this: soldier0hp, soldier0stamina, soldier1hp, soldier1stamina, etc.
26
-
27
- You need to instruct it to do this.
28
-
29
- Pretty easy here, just do:
27
+ method. I didn't overwrite the create method, because I wanted to differentiate between the two: This method will take your object and create it, and then store it in redis as a hash. It will not store it's associations unless you instruct it to do so, as will be discussed further in depth below. This is because redis has no ability to store foreign keyed objects, if a Battle has a Soldier in it, you can really only store it in a redis hash for Battle like this:
28
+
29
+ {
30
+ battle_name
31
+ battle_time
32
+ soldier0hp
33
+ soldier0stamina
34
+ soldier1hp
35
+ soldier1stamina
36
+ }
37
+
38
+ You can see how this is a limitation of redis - you can clearly see there are two soldiers in this battle hash but it only allows storing of hashes at the top level. You cannot store hashes in hashes, so you have to use this method. Because of this limitation, when I designed this mixin, I made it non-implementation specific for pushing associations with your model.
39
+
40
+ Pretty easy to use, just do:
30
41
 
31
42
  class Battle < ActiveRecord::Base
32
43
  include RedisStorageMethods
@@ -1,10 +1,5 @@
1
- #This module is for Toplevel Objects that are intended for storage in redis, with possible nested subobjects that are not meant to be
2
- #stored independently in redis.
3
-
4
- # So a Battle is a Toplevel Object. Video is not - it's always nested in redis, so it's just normal. Video does not include this
5
- #module, but Battle would. A Toplevel Object should not reference another Toplevel Object via an association, but if it must, do not
6
- #put it in the associations_names method so that this Toplevel object doesnt try to store it. That's what this module uses
7
- # to determine associations with.
1
+ require 'redis'
2
+ require 'hiredis'
8
3
  module RedisStorageMethods
9
4
 
10
5
  module ClassMethods
@@ -1,3 +1,3 @@
1
1
  module RedisStorageMethods
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -14,4 +14,6 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "redis_storage_methods"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = RedisStorageMethods::VERSION
17
+ gem.add_dependency "redis"
18
+ gem.add_dependency "hiredis"
17
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis_storage_methods
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,29 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
  date: 2013-02-05 00:00:00.000000000 Z
13
- dependencies: []
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: redis
16
+ requirement: &11928740 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *11928740
25
+ - !ruby/object:Gem::Dependency
26
+ name: hiredis
27
+ requirement: &11928020 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *11928020
14
36
  description: Transparently store objects both in redis and your sql store, but GET
15
37
  only on the redis store for speed.
16
38
  email: