redis-classy 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +36 -22
- data/Rakefile +6 -0
- data/VERSION +1 -1
- data/lib/redis/classy.rb +1 -1
- data/redis-classy.gemspec +3 -3
- data/spec/redis_classy_spec.rb +20 -5
- data/spec/spec_helper.rb +4 -0
- metadata +12 -12
data/README.md
CHANGED
@@ -10,16 +10,17 @@ class Something < Redis::Classy
|
|
10
10
|
end
|
11
11
|
|
12
12
|
Something.set 'foo', 'bar' # equivalent of => redis.set 'Something:foo', 'bar'
|
13
|
-
Something.get 'foo' #
|
13
|
+
Something.get 'foo' # equivalent of => redis.get 'Something:foo'
|
14
14
|
=> "bar"
|
15
15
|
```
|
16
16
|
|
17
|
-
|
17
|
+
All methods are delegated to the `redis-namespace` gems.
|
18
18
|
|
19
|
-
|
19
|
+
This library contains only 30+ lines of code, yet powerful when you need better abstraction on Redis objects to keep things organized.
|
20
20
|
|
21
|
-
What's new:
|
21
|
+
### What's new:
|
22
22
|
|
23
|
+
* v1.0.1: Relaxed version dependency on redis-namespace
|
23
24
|
* v1.0.0: Play nice with Mongoid
|
24
25
|
|
25
26
|
Synopsis
|
@@ -30,23 +31,32 @@ With the vanilla `redis` gem, you've been doing this:
|
|
30
31
|
```ruby
|
31
32
|
redis = Redis.new
|
32
33
|
redis.set 'foo', 'bar'
|
34
|
+
redis.get 'foo'
|
35
|
+
=> "bar"
|
33
36
|
```
|
34
37
|
|
35
38
|
With the `redis-namespace` gem, you can add a prefix in the following manner:
|
36
39
|
|
37
40
|
```ruby
|
38
41
|
redis_ns = Redis::Namespace.new('ns', :redis => redis)
|
39
|
-
redis_ns['foo'] = 'bar'
|
42
|
+
redis_ns['foo'] = 'bar' # equivalent of => redis.set 'ns:foo', 'bar'
|
43
|
+
redis_ns['foo'] # equivalent of => redis.get 'ns:foo'
|
44
|
+
=> "bar"
|
40
45
|
```
|
41
46
|
|
42
|
-
Now, with the redis-classy gem, you
|
47
|
+
Now, with the `redis-classy` gem, you finally achieve a class-based encapsulation:
|
43
48
|
|
44
49
|
```ruby
|
45
50
|
class Something < Redis::Classy
|
46
51
|
end
|
47
52
|
|
48
|
-
Something.set 'foo', 'bar' # equivalent of => redis.set '
|
49
|
-
Something.get 'foo'
|
53
|
+
Something.set 'foo', 'bar' # equivalent of => redis.set 'Something:foo', 'bar'
|
54
|
+
Something.get 'foo' # equivalent of => redis.get 'Something:foo'
|
55
|
+
=> "bar"
|
56
|
+
|
57
|
+
something = Something.new('foo')
|
58
|
+
something.set 'bar'
|
59
|
+
something.get
|
50
60
|
=> "bar"
|
51
61
|
```
|
52
62
|
|
@@ -64,14 +74,14 @@ In Gemfile:
|
|
64
74
|
gem 'redis-classy'
|
65
75
|
```
|
66
76
|
|
67
|
-
|
77
|
+
Register the Redis server: (e.g. in `config/initializers/redis_classy.rb` for Rails)
|
68
78
|
|
69
79
|
```ruby
|
70
|
-
Redis::Classy.db = Redis.new
|
80
|
+
Redis::Classy.db = Redis.new(:host => 'localhost')
|
71
81
|
```
|
72
82
|
|
73
|
-
Now you can write models that inherit
|
74
|
-
You can use any Redis commands on the class,
|
83
|
+
Now you can write models that inherit `Redis::Classy`, automatically prefixing keys with its class name.
|
84
|
+
You can use any Redis commands on the class, as they are eventually passed to the `redis` gem.
|
75
85
|
|
76
86
|
```ruby
|
77
87
|
class UniqueUser < Redis::Classy
|
@@ -80,16 +90,17 @@ class UniqueUser < Redis::Classy
|
|
80
90
|
end
|
81
91
|
end
|
82
92
|
|
83
|
-
UniqueUser.sadd '2011-02-28',
|
84
|
-
UniqueUser.sadd '2011-02-28',
|
85
|
-
UniqueUser.sadd '2011-03-01',
|
93
|
+
UniqueUser.sadd '2011-02-28', '123'
|
94
|
+
UniqueUser.sadd '2011-02-28', '456'
|
95
|
+
UniqueUser.sadd '2011-03-01', '789'
|
86
96
|
|
87
97
|
UniqueUser.smembers '2011-02-28'
|
88
98
|
=> ["123", "456"]
|
89
99
|
|
90
|
-
UniqueUser.
|
100
|
+
UniqueUser.keys
|
91
101
|
=> ["2011-02-28", "2011-03-01"]
|
92
102
|
|
103
|
+
UniqueUser.nuke
|
93
104
|
UniqueUser.keys
|
94
105
|
=> []
|
95
106
|
```
|
@@ -109,24 +120,27 @@ end
|
|
109
120
|
@room = Room.create
|
110
121
|
|
111
122
|
counter = Counter.new(@room)
|
123
|
+
counter.key
|
124
|
+
=> "Room:123"
|
125
|
+
|
112
126
|
counter.incr
|
113
127
|
counter.incr
|
114
128
|
counter.get
|
115
129
|
=> "2"
|
116
|
-
|
117
|
-
counter.key
|
118
|
-
=> "Room:123"
|
119
130
|
```
|
120
131
|
|
121
|
-
You also have access to the non-namespaced, raw Redis instance via Redis::Classy
|
132
|
+
You also have access to the non-namespaced, raw Redis instance via `Redis::Classy`.
|
122
133
|
|
123
134
|
```ruby
|
135
|
+
Redis::Classy.keys
|
136
|
+
=> ["UniqueUser:2011-02-28", "UniqueUser:2011-03-01", "Counter:Room:123"]
|
137
|
+
|
124
138
|
Redis::Classy.keys 'UniqueUser:*'
|
125
139
|
=> ["UniqueUser:2011-02-28", "UniqueUser:2011-03-01"]
|
126
140
|
|
127
141
|
Redis::Classy.multi do
|
128
|
-
UniqueUser.sadd '2011-02-28',
|
129
|
-
UniqueUser.sadd '2011-02-28',
|
142
|
+
UniqueUser.sadd '2011-02-28', '123'
|
143
|
+
UniqueUser.sadd '2011-02-28', '456'
|
130
144
|
end
|
131
145
|
```
|
132
146
|
|
data/Rakefile
CHANGED
@@ -22,6 +22,12 @@ Jeweler::Tasks.new do |gem|
|
|
22
22
|
end
|
23
23
|
Jeweler::RubygemsDotOrgTasks.new
|
24
24
|
|
25
|
+
desc "Flush the test database"
|
26
|
+
task :flushdb do
|
27
|
+
require 'redis'
|
28
|
+
Redis.new(:db => 15).flushdb
|
29
|
+
end
|
30
|
+
|
25
31
|
task :default => :spec
|
26
32
|
task :spec do
|
27
33
|
exec "rspec spec"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.2
|
data/lib/redis/classy.rb
CHANGED
@@ -4,7 +4,7 @@ class Redis
|
|
4
4
|
attr_accessor :db
|
5
5
|
|
6
6
|
def inherited(subclass)
|
7
|
-
subclass.db = Redis::Namespace.new(subclass.name, :redis =>
|
7
|
+
subclass.db = Redis::Namespace.new(subclass.name, :redis => Redis::Classy.db)
|
8
8
|
end
|
9
9
|
|
10
10
|
def method_missing(method_name, *args, &block)
|
data/redis-classy.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "redis-classy"
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kenn Ejima"]
|
12
|
-
s.date = "2011-
|
12
|
+
s.date = "2011-12-13"
|
13
13
|
s.description = "Class-style namespace prefixing for Redis"
|
14
14
|
s.email = "kenn.ejima@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -34,7 +34,7 @@ Gem::Specification.new do |s|
|
|
34
34
|
s.homepage = "http://github.com/kenn/redis-classy"
|
35
35
|
s.licenses = ["MIT"]
|
36
36
|
s.require_paths = ["lib"]
|
37
|
-
s.rubygems_version = "1.8.
|
37
|
+
s.rubygems_version = "1.8.10"
|
38
38
|
s.summary = "Class-style namespace prefixing for Redis"
|
39
39
|
|
40
40
|
if s.respond_to? :specification_version then
|
data/spec/redis_classy_spec.rb
CHANGED
@@ -1,14 +1,22 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
class Something < Redis::Classy
|
4
4
|
end
|
5
5
|
|
6
|
+
class Another < Something
|
7
|
+
end
|
8
|
+
|
9
|
+
module Deep
|
10
|
+
class Klass < Another
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
6
14
|
describe "RedisClassy" do
|
7
|
-
before
|
15
|
+
before do
|
8
16
|
Redis::Classy.flushdb
|
9
17
|
end
|
10
18
|
|
11
|
-
after
|
19
|
+
after do
|
12
20
|
Redis::Classy.flushdb
|
13
21
|
end
|
14
22
|
|
@@ -18,9 +26,16 @@ describe "RedisClassy" do
|
|
18
26
|
|
19
27
|
it "should prepend class name to the key" do
|
20
28
|
Something.set("foo", "bar")
|
29
|
+
Something.keys.should == ["foo"]
|
30
|
+
Redis::Classy.keys.should include "Something:foo"
|
31
|
+
|
32
|
+
Another.set("foo", "bar")
|
33
|
+
Another.keys.should == ["foo"]
|
34
|
+
Redis::Classy.keys.should include "Another:foo"
|
21
35
|
|
22
|
-
|
23
|
-
|
36
|
+
Deep::Klass.set("foo", "bar")
|
37
|
+
Deep::Klass.keys.should == ["foo"]
|
38
|
+
Redis::Classy.keys.should include "Deep::Klass:foo"
|
24
39
|
end
|
25
40
|
|
26
41
|
it "should delegate class methods" do
|
data/spec/spec_helper.rb
CHANGED
@@ -10,4 +10,8 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
|
10
10
|
RSpec.configure do |config|
|
11
11
|
# Use database 15 for testing so we don't accidentally step on you real data.
|
12
12
|
Redis::Classy.db = Redis.new(:db => 15)
|
13
|
+
unless Redis::Classy.keys.empty?
|
14
|
+
puts '[ERROR]: Redis database 15 not empty! If you are sure, run "rake flushdb" beforehand.'
|
15
|
+
exit!
|
16
|
+
end
|
13
17
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-classy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-12-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis-namespace
|
16
|
-
requirement: &
|
16
|
+
requirement: &2158303540 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '1.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2158303540
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &2158302700 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2158302700
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bundler
|
38
|
-
requirement: &
|
38
|
+
requirement: &2158301960 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2158301960
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: jeweler
|
49
|
-
requirement: &
|
49
|
+
requirement: &2158301360 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2158301360
|
58
58
|
description: Class-style namespace prefixing for Redis
|
59
59
|
email: kenn.ejima@gmail.com
|
60
60
|
executables: []
|
@@ -91,7 +91,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
91
91
|
version: '0'
|
92
92
|
segments:
|
93
93
|
- 0
|
94
|
-
hash:
|
94
|
+
hash: 2229584726006491915
|
95
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
96
|
none: false
|
97
97
|
requirements:
|
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
100
|
version: '0'
|
101
101
|
requirements: []
|
102
102
|
rubyforge_project:
|
103
|
-
rubygems_version: 1.8.
|
103
|
+
rubygems_version: 1.8.10
|
104
104
|
signing_key:
|
105
105
|
specification_version: 3
|
106
106
|
summary: Class-style namespace prefixing for Redis
|