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 +17 -6
- data/lib/redis_storage_methods.rb +2 -7
- data/lib/redis_storage_methods/version.rb +1 -1
- data/redis_storage_methods.gemspec +2 -0
- metadata +24 -2
data/README.md
CHANGED
@@ -18,15 +18,26 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
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.
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
2
|
-
|
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
|
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.
|
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:
|