redis-classy 1.2.0 → 2.0.0
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.
- checksums.yaml +7 -0
- data/.travis.yml +5 -8
- data/CHANGELOG.md +25 -0
- data/README.md +96 -79
- data/UPGRADING.md +10 -0
- data/lib/redis-classy.rb +2 -2
- data/lib/redis_classy/version.rb +3 -0
- data/lib/redis_classy.rb +75 -0
- data/redis-classy.gemspec +2 -2
- data/spec/redis_classy_spec.rb +58 -42
- data/spec/spec_helper.rb +2 -2
- metadata +22 -31
- data/lib/redis/classy/version.rb +0 -5
- data/lib/redis/classy.rb +0 -37
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 43bc9e17910f065ef35c2be995966f0714ce4ea1
|
4
|
+
data.tar.gz: b7499771aa9b2354c43ea346d8f3878297d66ab6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4b7491c74284bdddc17a8f47641813d608beb0dfdd4f02890e7cd79dcb04f51ba8a207cff3784ce09d4dfc3230039db945bf95b849e4b8e605051f503395e9de
|
7
|
+
data.tar.gz: 1614dd0aaee898bb35b74b2ccfc13d6ff866d01e8479edcdbe7c583ea68b955a2ffadbef83f3f2a953b9fbd75712a3c857f1bb4c47923d790aec3674cf1d5cc8
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
## 2.0.0 2014-11-23
|
2
|
+
|
3
|
+
* New feature: `singletons` to support predefined keys
|
4
|
+
* New feature: `singleton` to deal with singleton data
|
5
|
+
* New feature: `on` as a syntactic sugar for `new`
|
6
|
+
* New feature: `multi`, `pipelined`, `exec` and `eval` are available as instance methods
|
7
|
+
* No redis commands are delegated at the class level. Always use instance methods or explicitly declare singleton.
|
8
|
+
* The base class `Redis::Classy` is now `RedisClassy`
|
9
|
+
* `Redis::Classy.db = Redis.new` is now `RedisClassy.redis = Redis.new`.
|
10
|
+
|
11
|
+
## 1.1.1
|
12
|
+
|
13
|
+
* Raise exception when Redis::Classy.db is not assigned
|
14
|
+
|
15
|
+
## 1.1.0
|
16
|
+
|
17
|
+
* Explicitly require all files
|
18
|
+
|
19
|
+
## 1.0.1
|
20
|
+
|
21
|
+
* Relaxed version dependency on redis-namespace
|
22
|
+
|
23
|
+
## 1.0.0
|
24
|
+
|
25
|
+
* Play nice with Mongoid
|
data/README.md
CHANGED
@@ -1,43 +1,61 @@
|
|
1
|
-
Redis Classy
|
2
|
-
============
|
1
|
+
# Redis Classy
|
3
2
|
|
4
3
|
[](http://travis-ci.org/kenn/redis-classy)
|
5
4
|
|
6
|
-
|
5
|
+
A very simple, class-based namespace prefixing and encapsulation for Redis. Key features include:
|
7
6
|
|
8
|
-
|
7
|
+
- Establishes a maintainable convention by prefixing keys with the class name (e.g. `YourClass:123`)
|
8
|
+
- Delegates all method calls to the [redis-rb](https://github.com/redis/redis-rb) within the namespace
|
9
|
+
- Adds a better abstraction layer around Redis objects and commands
|
10
|
+
|
11
|
+
Here's an example:
|
9
12
|
|
10
13
|
```ruby
|
11
|
-
class
|
14
|
+
class Timer < RedisClassy
|
15
|
+
def start
|
16
|
+
pipelined do
|
17
|
+
set Time.now.to_i
|
18
|
+
expire 120.seconds
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def stop
|
23
|
+
del
|
24
|
+
end
|
25
|
+
|
26
|
+
def running?
|
27
|
+
!!get
|
28
|
+
end
|
12
29
|
end
|
13
30
|
|
14
|
-
|
15
|
-
|
16
|
-
|
31
|
+
timer = Timer.new(123)
|
32
|
+
timer.start
|
33
|
+
timer.running?
|
34
|
+
=> true
|
35
|
+
|
36
|
+
Timer.keys
|
37
|
+
=> ["123"]
|
38
|
+
RedisClassy.keys
|
39
|
+
=> ["Timer:123"]
|
17
40
|
```
|
18
41
|
|
19
|
-
|
42
|
+
The Timer class above is self-contained and more readable.
|
20
43
|
|
21
|
-
This library
|
44
|
+
This library is made intentionally small, yet powerful when you need better abstraction on Redis objects to keep things organized.
|
22
45
|
|
23
|
-
###
|
46
|
+
### UPGRADING FROM v1
|
24
47
|
|
25
|
-
|
26
|
-
* v1.1.1: Raise exception when Redis::Classy.db is not assigned
|
27
|
-
* v1.1.0: Explicitly require all files
|
28
|
-
* v1.0.1: Relaxed version dependency on redis-namespace
|
29
|
-
* v1.0.0: Play nice with Mongoid
|
48
|
+
[**An important message about upgrading from 1.x**](UPGRADING.md)
|
30
49
|
|
31
|
-
|
32
|
-
|
50
|
+
|
51
|
+
## redis-rb vs redis-namespace vs redis-classy
|
33
52
|
|
34
53
|
With the vanilla `redis` gem, you've been doing this:
|
35
54
|
|
36
55
|
```ruby
|
37
56
|
redis = Redis.new
|
38
57
|
redis.set 'foo', 'bar'
|
39
|
-
redis.get 'foo'
|
40
|
-
=> "bar"
|
58
|
+
redis.get 'foo' # => "bar"
|
41
59
|
```
|
42
60
|
|
43
61
|
With the `redis-namespace` gem, you can add a prefix in the following manner:
|
@@ -45,31 +63,23 @@ With the `redis-namespace` gem, you can add a prefix in the following manner:
|
|
45
63
|
```ruby
|
46
64
|
redis_ns = Redis::Namespace.new('ns', :redis => redis)
|
47
65
|
redis_ns['foo'] = 'bar' # equivalent of => redis.set 'ns:foo', 'bar'
|
48
|
-
redis_ns['foo'] #
|
49
|
-
=> "bar"
|
66
|
+
redis_ns['foo'] # => "bar"
|
50
67
|
```
|
51
68
|
|
52
|
-
Now, with the `redis-classy` gem, you finally achieve a class-based
|
69
|
+
Now, with the `redis-classy` gem, you finally achieve a class-based naming convention:
|
53
70
|
|
54
71
|
```ruby
|
55
|
-
class Something <
|
72
|
+
class Something < RedisClassy
|
56
73
|
end
|
57
74
|
|
58
|
-
Something.
|
59
|
-
Something.
|
60
|
-
=> "bar"
|
75
|
+
Something.on('foo').set('bar') # equivalent of => redis.set 'Something:foo', 'bar'
|
76
|
+
Something.on('foo').get # => "bar"
|
61
77
|
|
62
78
|
something = Something.new('foo')
|
63
|
-
something.set 'bar'
|
64
|
-
something.get
|
65
|
-
=> "bar"
|
79
|
+
something.set 'bar' # equivalent of => redis.set 'Something:foo', 'bar'
|
80
|
+
something.get # => "bar"
|
66
81
|
```
|
67
82
|
|
68
|
-
Install
|
69
|
-
-------
|
70
|
-
|
71
|
-
gem install redis-classy
|
72
|
-
|
73
83
|
Usage
|
74
84
|
-----
|
75
85
|
|
@@ -82,77 +92,84 @@ gem 'redis-classy'
|
|
82
92
|
Register the Redis server: (e.g. in `config/initializers/redis_classy.rb` for Rails)
|
83
93
|
|
84
94
|
```ruby
|
85
|
-
|
95
|
+
RedisClassy.redis = Redis.current
|
86
96
|
```
|
87
97
|
|
88
|
-
|
89
|
-
You can use any Redis commands on the class, as they are eventually passed to the `redis` gem.
|
98
|
+
Create a class that inherits RedisClassy. (e.g. in `app/redis/cache.rb` for Rails, for auto- and eager-loading)
|
90
99
|
|
91
100
|
```ruby
|
92
|
-
class
|
93
|
-
def
|
94
|
-
|
101
|
+
class Cache < RedisClassy
|
102
|
+
def put(content)
|
103
|
+
pipelined do
|
104
|
+
set content
|
105
|
+
expire 5.seconds
|
106
|
+
end
|
95
107
|
end
|
96
108
|
end
|
97
109
|
|
98
|
-
|
99
|
-
|
100
|
-
|
110
|
+
cache = Cache.new(123)
|
111
|
+
cache.put "This tape will self-destruct in five seconds. Good luck."
|
112
|
+
```
|
113
|
+
|
114
|
+
Since the `on` method is added as a syntactic sugar for `new`, you can also run a command in one shot as well:
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
Cache.on(123).persist
|
118
|
+
```
|
119
|
+
|
120
|
+
For convenience, singleton and predefined static keys are also supported.
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
class Counter < RedisClassy
|
124
|
+
singleton
|
125
|
+
end
|
126
|
+
|
127
|
+
Counter.incr # 'Counter:singleton' => '1'
|
128
|
+
Counter.incr # 'Counter:singleton' => '2'
|
129
|
+
Counter.get # => '2'
|
130
|
+
```
|
101
131
|
|
102
|
-
|
103
|
-
|
132
|
+
``` ruby
|
133
|
+
class Stats < RedisClassy
|
134
|
+
singletons :median, :average
|
135
|
+
end
|
104
136
|
|
105
|
-
|
106
|
-
=> ["2011-02-28", "2011-03-01"]
|
137
|
+
ages = [21,22,24,28,30]
|
107
138
|
|
108
|
-
|
109
|
-
|
110
|
-
=>
|
139
|
+
Stats.median.set ages[ages.size/2] # 'Stats:median' => '24'
|
140
|
+
Stats.average.set ages.inject(:+)/ages.size # 'Stats:average' => '25'
|
141
|
+
Stats.median.get # => '24'
|
142
|
+
Stats.average.get # => '25'
|
111
143
|
```
|
112
144
|
|
113
|
-
|
145
|
+
Finally, you can also pass an arbitrary object that responds to `id` as a key. This is useful when used in combination with ActiveRecord, etc.
|
114
146
|
|
115
147
|
```ruby
|
116
|
-
class
|
117
|
-
def initialize(object)
|
118
|
-
super("#{object.class.name}:#{object.id}")
|
119
|
-
end
|
148
|
+
class Lock < RedisClassy
|
120
149
|
end
|
121
150
|
|
122
151
|
class Room < ActiveRecord::Base
|
123
152
|
end
|
124
153
|
|
125
|
-
|
154
|
+
room = Room.create
|
126
155
|
|
127
|
-
|
128
|
-
counter.key
|
129
|
-
=> "Room:123"
|
130
|
-
|
131
|
-
counter.incr
|
132
|
-
counter.incr
|
133
|
-
counter.get
|
134
|
-
=> "2"
|
156
|
+
lock = Lock.new(room)
|
135
157
|
```
|
136
158
|
|
137
|
-
|
159
|
+
When you need an access to the non-namespaced, raw Redis keys, it's available as `RedisClass.keys`. Keep in mind that this method is very slow at O(N) computational complexity and potentially hazardous when you have many keys. [Read the details](http://redis.io/commands/keys).
|
138
160
|
|
139
161
|
```ruby
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
Redis::Classy.keys 'UniqueUser:*'
|
144
|
-
=> ["UniqueUser:2011-02-28", "UniqueUser:2011-03-01"]
|
162
|
+
RedisClassy.keys
|
163
|
+
=> ["Stats:median", "Stats:average", "Counter"]
|
145
164
|
|
146
|
-
|
147
|
-
|
148
|
-
UniqueUser.sadd '2011-02-28', '456'
|
149
|
-
end
|
165
|
+
RedisClassy.keys 'Stats:*'
|
166
|
+
=> ["Stats:median", "Stats:average"]
|
150
167
|
```
|
151
168
|
|
152
|
-
Since the `
|
169
|
+
Since the `redis` attribute is a class instance variable, you can dynamically assign different databases for each class, without affecting other classes.
|
153
170
|
|
154
171
|
```ruby
|
155
|
-
|
172
|
+
Cache.redis = Redis::Namespace.new('Cache', redis: Redis.new(host: 'another.host'))
|
156
173
|
```
|
157
174
|
|
158
175
|
Unicorn support
|
@@ -162,11 +179,11 @@ If you run fork-based app servers such as **Unicorn** or **Passenger**, you need
|
|
162
179
|
|
163
180
|
```ruby
|
164
181
|
after_fork do
|
165
|
-
|
182
|
+
RedisClassy.redis.client.reconnect
|
166
183
|
end
|
167
184
|
```
|
168
185
|
|
169
|
-
Note that since Redis Classy assigns a namespaced Redis instance upon the inheritance event of each subclass (`class Something <
|
186
|
+
Note that since Redis Classy assigns a namespaced Redis instance upon the inheritance event of each subclass (`class Something < RedisClassy`), reconnecting the master (non-namespaced) connection that is referenced from all subclasses should probably be the safest and the most efficient way to survive a forking event.
|
170
187
|
|
171
188
|
Reference
|
172
189
|
---------
|
data/UPGRADING.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Upgrading from 1.x
|
2
|
+
|
3
|
+
`redis-classy` 2.0 has brought quite a few changes. Please read these points carefully.
|
4
|
+
|
5
|
+
Please post any implications we may have missed as a GitHub Issue or Pull Request.
|
6
|
+
|
7
|
+
* No redis commands are delegated at the class level. Always use instance methods or explicitly declare singleton.
|
8
|
+
* `Something.set 'key', 'value'` is now `Something.on('key').set('value')`
|
9
|
+
* The base class `Redis::Classy` is now `RedisClassy`.
|
10
|
+
* `Redis::Classy.db = Redis.new` is now `RedisClassy.redis = Redis.new`.
|
data/lib/redis-classy.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
require 'redis-namespace'
|
2
|
-
require '
|
3
|
-
require '
|
2
|
+
require 'redis_classy'
|
3
|
+
require 'redis_classy/version'
|
data/lib/redis_classy.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
class RedisClassy
|
2
|
+
class << self
|
3
|
+
attr_accessor :redis
|
4
|
+
|
5
|
+
def inherited(subclass)
|
6
|
+
raise Error.new('RedisClassy.redis is not assigned') unless RedisClassy.redis
|
7
|
+
subclass.redis = Redis::Namespace.new(subclass.name, redis: RedisClassy.redis)
|
8
|
+
end
|
9
|
+
|
10
|
+
def singletons(*args)
|
11
|
+
args.each do |key|
|
12
|
+
define_singleton_method(key) do
|
13
|
+
new key
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def singleton
|
19
|
+
@singleton = true
|
20
|
+
end
|
21
|
+
|
22
|
+
def keys(pattern = nil)
|
23
|
+
@redis.keys(pattern || '*')
|
24
|
+
end
|
25
|
+
|
26
|
+
def on(key)
|
27
|
+
new(key)
|
28
|
+
end
|
29
|
+
|
30
|
+
def method_missing(command, *args, &block)
|
31
|
+
if @singleton
|
32
|
+
new('singleton').send(command, *args, &block)
|
33
|
+
else
|
34
|
+
super
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Instance methods
|
40
|
+
|
41
|
+
attr_accessor :key, :redis, :object
|
42
|
+
|
43
|
+
def initialize(object)
|
44
|
+
@redis = self.class.redis
|
45
|
+
@object = object
|
46
|
+
|
47
|
+
case object
|
48
|
+
when String, Symbol, Integer
|
49
|
+
@key = object.to_s
|
50
|
+
else
|
51
|
+
if object.respond_to?(:id)
|
52
|
+
@key = object.id.to_s
|
53
|
+
else
|
54
|
+
raise ArgumentError, 'object must be a string, symbol, integer or respond to :id method'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
KEYLESS_COMMANDS = [:multi, :pipelined, :exec, :eval]
|
60
|
+
|
61
|
+
def method_missing(command, *args, &block)
|
62
|
+
if @redis.respond_to?(command)
|
63
|
+
case command
|
64
|
+
when *KEYLESS_COMMANDS
|
65
|
+
@redis.send(command, *args, &block)
|
66
|
+
else
|
67
|
+
@redis.send(command, @key, *args, &block)
|
68
|
+
end
|
69
|
+
else
|
70
|
+
super
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
Error = Class.new(StandardError)
|
75
|
+
end
|
data/redis-classy.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path('../lib/
|
2
|
+
require File.expand_path('../lib/redis_classy/version', __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["Kenn Ejima"]
|
@@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
|
|
13
13
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
14
|
gem.name = "redis-classy"
|
15
15
|
gem.require_paths = ["lib"]
|
16
|
-
gem.version =
|
16
|
+
gem.version = RedisClassy::VERSION
|
17
17
|
|
18
18
|
gem.add_runtime_dependency "redis-namespace", "~> 1.0"
|
19
19
|
gem.add_development_dependency "rspec"
|
data/spec/redis_classy_spec.rb
CHANGED
@@ -1,65 +1,75 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
class Something <
|
3
|
+
class Something < RedisClassy
|
4
4
|
end
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
describe RedisClassy do
|
7
|
+
before do
|
8
|
+
RedisClassy.redis.flushdb
|
9
|
+
end
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
+
after(:all) do
|
12
|
+
RedisClassy.redis.flushdb
|
13
|
+
RedisClassy.redis.quit
|
11
14
|
end
|
12
|
-
end
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
Redis::
|
16
|
+
it 'stores redis or redis-namespace' do
|
17
|
+
expect(RedisClassy.redis.is_a?(Redis)).to be_truthy
|
18
|
+
expect(RedisClassy.redis.is_a?(Redis::Namespace)).to be_falsy
|
19
|
+
expect(Something.redis.is_a?(Redis)).to be_falsy
|
20
|
+
expect(Something.redis.is_a?(Redis::Namespace)).to be_truthy
|
17
21
|
end
|
18
22
|
|
19
|
-
|
20
|
-
|
21
|
-
|
23
|
+
it 'gets keys' do
|
24
|
+
Something.on(:foo).set('bar')
|
25
|
+
expect(Something.keys).to eq(['foo'])
|
26
|
+
expect(RedisClassy.keys).to eq(['Something:foo'])
|
22
27
|
end
|
23
28
|
|
24
29
|
it 'prepends class name to the key' do
|
25
|
-
Something
|
26
|
-
|
27
|
-
Redis::Classy.keys.should include 'Something:foo'
|
30
|
+
class Another < Something
|
31
|
+
end
|
28
32
|
|
29
|
-
|
30
|
-
|
31
|
-
|
33
|
+
module Deep
|
34
|
+
class Klass < Another
|
35
|
+
end
|
36
|
+
end
|
32
37
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
38
|
+
Something.on(:foo).set('bar')
|
39
|
+
expect(Something.on(:foo).keys).to eq(['foo'])
|
40
|
+
expect(RedisClassy.keys.size).to eq(1)
|
41
|
+
expect(RedisClassy.keys).to include 'Something:foo'
|
42
|
+
|
43
|
+
Another.on(:foo).set('bar')
|
44
|
+
expect(Another.on(:foo).keys).to eq(['foo'])
|
45
|
+
expect(RedisClassy.keys.size).to eq(2)
|
46
|
+
expect(RedisClassy.keys).to include 'Another:foo'
|
37
47
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
48
|
+
Deep::Klass.on(:foo).set('bar')
|
49
|
+
expect(Deep::Klass.on(:foo).keys).to eq(['foo'])
|
50
|
+
expect(RedisClassy.keys.size).to eq(3)
|
51
|
+
expect(RedisClassy.keys).to include 'Deep::Klass:foo'
|
42
52
|
end
|
43
53
|
|
44
54
|
it 'delegates instance methods with the key binding' do
|
45
55
|
something = Something.new('foo')
|
46
56
|
|
47
|
-
something.get.
|
57
|
+
expect(something.get).to eq(nil)
|
48
58
|
something.set('bar')
|
49
|
-
something.get.
|
50
|
-
Something.
|
59
|
+
expect(something.get).to eq('bar')
|
60
|
+
expect(Something.on(:foo).get).to eq('bar')
|
51
61
|
end
|
52
62
|
|
53
63
|
it 'handles multi block' do
|
54
64
|
something = Something.new('foo')
|
55
65
|
|
56
|
-
|
66
|
+
something.multi do
|
57
67
|
something.sadd 1
|
58
68
|
something.sadd 2
|
59
69
|
something.sadd 3
|
60
70
|
end
|
61
71
|
|
62
|
-
something.smembers.
|
72
|
+
expect(something.smembers).to eq(['1','2','3'])
|
63
73
|
end
|
64
74
|
|
65
75
|
it 'handles method_missing' do
|
@@ -71,20 +81,26 @@ describe Redis::Classy do
|
|
71
81
|
expect { something.bogus }.to raise_error(NoMethodError)
|
72
82
|
end
|
73
83
|
|
74
|
-
it '
|
75
|
-
|
76
|
-
|
77
|
-
def self.get(value)
|
78
|
-
value
|
79
|
-
end
|
84
|
+
it 'handles singleton key' do
|
85
|
+
class Counter < RedisClassy
|
86
|
+
singleton
|
80
87
|
end
|
81
88
|
|
82
|
-
|
83
|
-
|
84
|
-
|
89
|
+
Counter.incr
|
90
|
+
expect(Counter.get).to eq('1')
|
91
|
+
Counter.incr
|
92
|
+
expect(Counter.get).to eq('2')
|
93
|
+
end
|
85
94
|
|
86
|
-
|
87
|
-
|
95
|
+
it 'handles predefined keys' do
|
96
|
+
class Stats < RedisClassy
|
97
|
+
singletons :median, :average
|
88
98
|
end
|
99
|
+
|
100
|
+
ages = [21,22,24,28,30]
|
101
|
+
Stats.median.set ages[ages.size/2]
|
102
|
+
Stats.average.set ages.inject(:+)/ages.size
|
103
|
+
expect(Stats.median.get).to eq('24')
|
104
|
+
expect(Stats.average.get).to eq('25')
|
89
105
|
end
|
90
106
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,8 +6,8 @@ require 'redis-classy'
|
|
6
6
|
|
7
7
|
RSpec.configure do |config|
|
8
8
|
# Use database 15 for testing so we don't accidentally step on you real data.
|
9
|
-
|
10
|
-
unless
|
9
|
+
RedisClassy.redis = Redis.new(db: 15)
|
10
|
+
unless RedisClassy.keys.empty?
|
11
11
|
puts '[ERROR]: Redis database 15 not empty! If you are sure, run "rake flushdb" beforehand.'
|
12
12
|
exit!
|
13
13
|
end
|
metadata
CHANGED
@@ -1,78 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-classy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Kenn Ejima
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-11-23 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: redis-namespace
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '1.0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '1.0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: bundler
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: rake
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
description: Class-style namespace prefixing for Redis
|
@@ -82,44 +73,44 @@ executables: []
|
|
82
73
|
extensions: []
|
83
74
|
extra_rdoc_files: []
|
84
75
|
files:
|
85
|
-
- .gitignore
|
86
|
-
- .rspec
|
87
|
-
- .travis.yml
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- CHANGELOG.md
|
88
80
|
- Gemfile
|
89
81
|
- LICENSE
|
90
82
|
- README.md
|
91
83
|
- Rakefile
|
84
|
+
- UPGRADING.md
|
92
85
|
- lib/redis-classy.rb
|
93
|
-
- lib/
|
94
|
-
- lib/
|
86
|
+
- lib/redis_classy.rb
|
87
|
+
- lib/redis_classy/version.rb
|
95
88
|
- redis-classy.gemspec
|
96
89
|
- spec/redis_classy_spec.rb
|
97
90
|
- spec/spec_helper.rb
|
98
91
|
homepage: http://github.com/kenn/redis-classy
|
99
92
|
licenses: []
|
93
|
+
metadata: {}
|
100
94
|
post_install_message:
|
101
95
|
rdoc_options: []
|
102
96
|
require_paths:
|
103
97
|
- lib
|
104
98
|
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
99
|
requirements:
|
107
|
-
- -
|
100
|
+
- - ">="
|
108
101
|
- !ruby/object:Gem::Version
|
109
102
|
version: '0'
|
110
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
-
none: false
|
112
104
|
requirements:
|
113
|
-
- -
|
105
|
+
- - ">="
|
114
106
|
- !ruby/object:Gem::Version
|
115
107
|
version: '0'
|
116
108
|
requirements: []
|
117
109
|
rubyforge_project:
|
118
|
-
rubygems_version:
|
110
|
+
rubygems_version: 2.2.2
|
119
111
|
signing_key:
|
120
|
-
specification_version:
|
112
|
+
specification_version: 4
|
121
113
|
summary: Class-style namespace prefixing for Redis
|
122
114
|
test_files:
|
123
115
|
- spec/redis_classy_spec.rb
|
124
116
|
- spec/spec_helper.rb
|
125
|
-
has_rdoc:
|
data/lib/redis/classy/version.rb
DELETED
data/lib/redis/classy.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
class Redis
|
2
|
-
class Classy
|
3
|
-
class << self
|
4
|
-
attr_accessor :db
|
5
|
-
|
6
|
-
def inherited(subclass)
|
7
|
-
raise 'Redis::Classy.db is not assigned' unless Redis::Classy.db
|
8
|
-
subclass.db = Redis::Namespace.new(subclass.name, :redis => Redis::Classy.db)
|
9
|
-
end
|
10
|
-
|
11
|
-
def delegatables
|
12
|
-
@delegatables ||= Redis::Classy.db.class.instance_methods(false).map(&:to_sym) # ruby1.8 returns strings
|
13
|
-
end
|
14
|
-
|
15
|
-
def method_missing(command, *args, &block)
|
16
|
-
return super unless delegatables.include?(command)
|
17
|
-
db.send(command, *args, &block)
|
18
|
-
end
|
19
|
-
|
20
|
-
Redis::Namespace::COMMANDS.keys.each do |command|
|
21
|
-
define_method(command) do |*args, &block|
|
22
|
-
db.send(command, *args, &block)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
attr_accessor :key
|
28
|
-
|
29
|
-
def initialize(key)
|
30
|
-
@key = key
|
31
|
-
end
|
32
|
-
|
33
|
-
def method_missing(command, *args, &block)
|
34
|
-
self.class.send(command, @key, *args, &block)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|