defunkt-redis 0.2.1 → 0.2.2
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.markdown +18 -3
- data/lib/redis.rb +3 -13
- data/spec/redis_spec.rb +3 -2
- metadata +1 -1
data/README.markdown
CHANGED
@@ -10,11 +10,12 @@ Redis is a key value store with some interesting features:
|
|
10
10
|
|
11
11
|
See [redis on code.google.com](http://code.google.com/p/redis/wiki/README) for more information.
|
12
12
|
|
13
|
-
See the build on [RunCodeRun](http://runcoderun.com/
|
13
|
+
See the build on [RunCodeRun](http://runcoderun.com/defunkt/redis-rb)
|
14
14
|
|
15
15
|
## Dependencies
|
16
16
|
|
17
|
-
1. rspec -
|
17
|
+
1. rspec -
|
18
|
+
|
18
19
|
sudo gem install rspec
|
19
20
|
|
20
21
|
2. redis -
|
@@ -33,4 +34,18 @@ Use the tasks mentioned above (in Dependencies) to get your machine setup.
|
|
33
34
|
|
34
35
|
## Examples
|
35
36
|
|
36
|
-
Check the examples/ directory. *Note* you need to have redis-server
|
37
|
+
Check the examples/ directory. *Note* you need to have redis-server
|
38
|
+
running first.
|
39
|
+
|
40
|
+
## Differences from ezmobius/redis-rb
|
41
|
+
|
42
|
+
* Connection is deferred until you use the library. a420731
|
43
|
+
* You may pass `:namespace` to the initializer to scope all keys. 73b9ae3
|
44
|
+
* You may pass `:thread_safe` to the initializer to make Redis thread
|
45
|
+
safe. 1d0c44c
|
46
|
+
|
47
|
+
I will continue to merge in changes from ezmobius/redis-rb.
|
48
|
+
|
49
|
+
## Installation
|
50
|
+
|
51
|
+
gem install defunkt-redis
|
data/lib/redis.rb
CHANGED
@@ -107,7 +107,6 @@ class Redis
|
|
107
107
|
@timeout = (options[:timeout] || 5).to_i
|
108
108
|
@password = options[:password]
|
109
109
|
@logger = options[:logger]
|
110
|
-
@namespace = options[:namespace]
|
111
110
|
@thread_safe = options[:thread_safe]
|
112
111
|
|
113
112
|
@logger.info { self.to_s } if @logger
|
@@ -160,7 +159,7 @@ class Redis
|
|
160
159
|
call_command(argv)
|
161
160
|
end
|
162
161
|
|
163
|
-
def call_command(argv
|
162
|
+
def call_command(argv)
|
164
163
|
@logger.debug { argv.inspect } if @logger
|
165
164
|
|
166
165
|
# this wrapper to raw_call_command handle reconnection on socket
|
@@ -169,7 +168,7 @@ class Redis
|
|
169
168
|
connect_to_server if !@sock
|
170
169
|
|
171
170
|
begin
|
172
|
-
raw_call_command(argv.dup
|
171
|
+
raw_call_command(argv.dup)
|
173
172
|
rescue Errno::ECONNRESET, Errno::EPIPE
|
174
173
|
@sock.close
|
175
174
|
@sock = nil
|
@@ -178,7 +177,7 @@ class Redis
|
|
178
177
|
end
|
179
178
|
end
|
180
179
|
|
181
|
-
def raw_call_command(argvp
|
180
|
+
def raw_call_command(argvp)
|
182
181
|
pipeline = argvp[0].is_a?(Array)
|
183
182
|
|
184
183
|
unless pipeline
|
@@ -199,10 +198,6 @@ class Redis
|
|
199
198
|
argv[-1] = bulk.respond_to?(:bytesize) ? bulk.bytesize : bulk.size
|
200
199
|
end
|
201
200
|
|
202
|
-
if @namespace && argv[1] && use_namespace
|
203
|
-
argv[1] = "#{@namespace}:#{argv[1]}"
|
204
|
-
end
|
205
|
-
|
206
201
|
command << "#{argv.join(' ')}\r\n"
|
207
202
|
command << "#{bulk}\r\n" if bulk
|
208
203
|
end
|
@@ -276,11 +271,6 @@ class Redis
|
|
276
271
|
result
|
277
272
|
end
|
278
273
|
|
279
|
-
def mget(*keys)
|
280
|
-
keys = keys.map { |key| "#{@namespace}:#{key}"} if @namespace
|
281
|
-
call_command([:mget] + keys, false)
|
282
|
-
end
|
283
|
-
|
284
274
|
# Ruby defines a now deprecated type method so we need to override it here
|
285
275
|
# since it will never hit method_missing
|
286
276
|
def type(key)
|
data/spec/redis_spec.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
require 'redis/raketasks'
|
3
|
+
require 'redis/namespace'
|
3
4
|
require 'logger'
|
4
5
|
|
5
6
|
class Foo
|
@@ -489,7 +490,7 @@ describe "redis" do
|
|
489
490
|
end
|
490
491
|
|
491
492
|
it "should be able to use a namespace" do
|
492
|
-
r = Redis.new(:
|
493
|
+
r = Redis::Namespace.new(:ns, :redis => @r)
|
493
494
|
r.flushdb
|
494
495
|
|
495
496
|
r['foo'].should == nil
|
@@ -504,7 +505,7 @@ describe "redis" do
|
|
504
505
|
end
|
505
506
|
|
506
507
|
it "should be able to use a namespace with mget" do
|
507
|
-
r = Redis.new(:
|
508
|
+
r = Redis::Namespace.new(:ns, :redis => @r)
|
508
509
|
|
509
510
|
r['foo'] = 1000
|
510
511
|
r['bar'] = 2000
|