redis_backed_model 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -43,7 +43,14 @@ You can use RBM to get Redis commands that will save your object as a hash
|
|
43
43
|
p.to_redis => ["sadd|person_ids|2", "hset|person:2|id|2", "hset|person:2|first_name|Bill", "hset|person:2|last_name|Smith"]
|
44
44
|
```
|
45
45
|
|
46
|
-
|
46
|
+
If the value of a variable is nil, it is not included in the to_redis commands
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
p = Person.new({:id => 2, :first_name => "Bill", :last_name => nil})
|
50
|
+
p.to_redis => ["sadd|person_ids|2", "hset|person:2|id|2", "hset|person:2|first_name|Bill"]
|
51
|
+
```
|
52
|
+
|
53
|
+
You can parse the to_redis results and pass them to Redis yourself or use the gem 'redis_pipeline': https://github.com/SeniorServiceAmerica/redis_pipeline
|
47
54
|
|
48
55
|
Once your data is in Redis, you can use RBM to find and instantiate objects:
|
49
56
|
|
@@ -62,7 +62,7 @@ module RedisBackedModel
|
|
62
62
|
collection << redis_object.to_redis
|
63
63
|
end
|
64
64
|
else
|
65
|
-
collection << instance_variable_to_redis(variable)
|
65
|
+
collection << instance_variable_to_redis(variable) if value
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -71,7 +71,8 @@ module RedisBackedModel
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def instance_variable_to_redis(instance_variable)
|
74
|
-
|
74
|
+
value = instance_variable_get(instance_variable)
|
75
|
+
"hset|#{model_name_for_redis}:#{id}|#{instance_variable.to_s.deinstance_variableize}|#{value}" if value
|
75
76
|
end
|
76
77
|
|
77
78
|
def model_name_for_redis
|
@@ -84,8 +84,9 @@ describe RedisBackedModel do
|
|
84
84
|
before(:each) do
|
85
85
|
@rbm = InheritingFromRedisBackedModel.new()
|
86
86
|
@rbm.instance_variable_set('@id', 1)
|
87
|
-
@rbm.instance_variable_set('@foo', 20)
|
87
|
+
@rbm.instance_variable_set('@foo', 20)
|
88
88
|
end
|
89
|
+
|
89
90
|
it "creates a hset command for instance variables" do
|
90
91
|
@rbm.send(:instance_variable_to_redis, '@foo').should eq("hset|#{@rbm.class.to_s.underscore}:1|foo|20")
|
91
92
|
end
|
@@ -115,6 +116,13 @@ describe RedisBackedModel do
|
|
115
116
|
hset_command = @rbm.send(:instance_variable_to_redis, '@bar')
|
116
117
|
hset_command.split('|').count.should eq(4)
|
117
118
|
end
|
119
|
+
|
120
|
+
it "does not include an hset command if the instance variable's value is nil" do
|
121
|
+
@rbm.instance_variable_set('@nil_value', nil)
|
122
|
+
hset_command = @rbm.send(:instance_variable_to_redis, '@nil_value')
|
123
|
+
hset_command.should == nil
|
124
|
+
@rbm.to_redis.count.should == 3
|
125
|
+
end
|
118
126
|
end
|
119
127
|
|
120
128
|
it "includes as sadd command in to_redis" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis_backed_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-09-
|
13
|
+
date: 2012-09-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
17
|
-
requirement:
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,15 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements:
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
26
31
|
- !ruby/object:Gem::Dependency
|
27
32
|
name: redis
|
28
|
-
requirement:
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
29
34
|
none: false
|
30
35
|
requirements:
|
31
36
|
- - ! '>='
|
@@ -33,10 +38,15 @@ dependencies:
|
|
33
38
|
version: '0'
|
34
39
|
type: :development
|
35
40
|
prerelease: false
|
36
|
-
version_requirements:
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
37
47
|
- !ruby/object:Gem::Dependency
|
38
48
|
name: activesupport
|
39
|
-
requirement:
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
40
50
|
none: false
|
41
51
|
requirements:
|
42
52
|
- - ! '>='
|
@@ -44,7 +54,12 @@ dependencies:
|
|
44
54
|
version: '0'
|
45
55
|
type: :runtime
|
46
56
|
prerelease: false
|
47
|
-
version_requirements:
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
48
63
|
description: Provides methods to models that are backed by a redis instance.
|
49
64
|
email:
|
50
65
|
- iwhitney@ssa-i.org
|
@@ -88,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
103
|
version: '0'
|
89
104
|
requirements: []
|
90
105
|
rubyforge_project:
|
91
|
-
rubygems_version: 1.8.
|
106
|
+
rubygems_version: 1.8.24
|
92
107
|
signing_key:
|
93
108
|
specification_version: 3
|
94
109
|
summary: Provides methods for the creation of redis-backed models, specifically the
|