redis_backed_model 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# RedisBackedModel
|
2
2
|
|
3
|
-
|
3
|
+
Provides useful functions to objects that are backed by a Redis store instead of ActiveRecord.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,34 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
Subclass your models from RedisBackedModel::RedisBackedModel
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
class Person < RedisBackedModel::RedisBackedModel
|
25
|
+
...
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
When initializing a person, pass in a hash of attributes
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
p = Person.new({:id => 2, :first_name => "Bill", :last_name => "Smith"})
|
33
|
+
```
|
34
|
+
|
35
|
+
RBM will create instance variables as needed
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
p.instance_variables => [:@id, :@first_name, :@last_name]
|
39
|
+
```
|
40
|
+
|
41
|
+
You can use RBM to get Redis commands that will save your object as a hash
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
p.to_redis => ["sadd|person_ids|2", "hset|person:2|id|2", "hset|person:2|first_name|Bill", "hset|person:2|last_name|Smith"]
|
45
|
+
```
|
46
|
+
|
47
|
+
You can parse these and pass them to Redis yourself or use the gem 'redis_pipeline': https://github.com/SeniorServiceAmerica/redis_pipeline
|
48
|
+
|
22
49
|
|
23
50
|
## Contributing
|
24
51
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module RedisBackedModel
|
2
2
|
class RedisBackedModel
|
3
|
-
|
3
|
+
|
4
4
|
def initialize(attributes={})
|
5
5
|
if attributes.class == Hash
|
6
6
|
attributes.each do |key, value|
|
@@ -17,12 +17,13 @@ module RedisBackedModel
|
|
17
17
|
instance_variables.each do | var |
|
18
18
|
build_command_for_variable(var, redis_commands)
|
19
19
|
end
|
20
|
+
|
20
21
|
redis_commands
|
21
22
|
end
|
22
23
|
|
23
24
|
private
|
24
25
|
|
25
|
-
attr_reader :id
|
26
|
+
attr_reader :id
|
26
27
|
|
27
28
|
def add_to_instance_variables(key, value)
|
28
29
|
if key.match(/score_\[\w+\|\w+\]/)
|
@@ -33,8 +34,7 @@ module RedisBackedModel
|
|
33
34
|
end
|
34
35
|
|
35
36
|
def add_to_scores(key, value)
|
36
|
-
|
37
|
-
@scores << SortedSet.new(self.class, id, Hash[key,value])
|
37
|
+
scores << SortedSet.new(self.class, id, Hash[key,value])
|
38
38
|
end
|
39
39
|
|
40
40
|
def build_command_for_variable(variable, collection)
|
@@ -59,7 +59,10 @@ module RedisBackedModel
|
|
59
59
|
def model_name_for_redis
|
60
60
|
class_as_string = self.class.to_s.demodulize.underscore
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
|
+
def scores
|
64
|
+
@scores ||= []
|
65
|
+
end
|
63
66
|
end
|
64
67
|
|
65
68
|
end
|
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: 0.0.
|
4
|
+
version: 0.0.4
|
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-
|
13
|
+
date: 2012-09-04 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
17
|
-
requirement: &
|
17
|
+
requirement: &2164484940 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2164484940
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: redis
|
28
|
-
requirement: &
|
28
|
+
requirement: &2164484520 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2164484520
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: activesupport
|
39
|
-
requirement: &
|
39
|
+
requirement: &2164484100 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *2164484100
|
48
48
|
description: Provides methods to models that are backed by a redis instance.
|
49
49
|
email:
|
50
50
|
- iwhitney@ssa-i.org
|