redis-namespace 0.10.0 → 1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of redis-namespace might be problematic. Click here for more details.

data/README.md CHANGED
@@ -5,8 +5,10 @@ Requires the redis gem.
5
5
 
6
6
  Namespaces all Redis calls.
7
7
 
8
- r = Redis::Namespace.new(:ns, :redis => @r)
9
- r['foo'] = 1000
8
+ ``` ruby
9
+ r = Redis::Namespace.new(:ns, :redis => @r)
10
+ r['foo'] = 1000
11
+ ```
10
12
 
11
13
  This will perform the equivalent of:
12
14
 
@@ -21,6 +23,14 @@ Installation
21
23
  $ gem install redis-namespace
22
24
 
23
25
 
26
+
27
+ Testing
28
+ =======
29
+
30
+ $ bundle install
31
+ $ rake
32
+
33
+
24
34
  Author
25
35
  =====
26
36
 
data/Rakefile CHANGED
@@ -3,5 +3,5 @@ task :test => :spec
3
3
 
4
4
  desc "Run specs"
5
5
  task :spec do
6
- exec "spec spec/redis_spec.rb"
6
+ exec "rspec spec/redis_spec.rb"
7
7
  end
@@ -45,6 +45,7 @@ class Redis
45
45
  "blpop" => [ :exclude_last ],
46
46
  "brpop" => [ :exclude_last ],
47
47
  "dbsize" => [],
48
+ "debug" => [ :exclude_first ],
48
49
  "decr" => [ :first ],
49
50
  "decrby" => [ :first ],
50
51
  "del" => [ :all ],
@@ -55,6 +56,7 @@ class Redis
55
56
  "get" => [ :first ],
56
57
  "getset" => [ :first ],
57
58
  "hset" => [ :first ],
59
+ "hsetnx" => [ :first ],
58
60
  "hget" => [ :first ],
59
61
  "hincrby" => [ :first ],
60
62
  "hmget" => [ :first ],
@@ -78,6 +80,7 @@ class Redis
78
80
  "lrem" => [ :first ],
79
81
  "lset" => [ :first ],
80
82
  "ltrim" => [ :first ],
83
+ "mapped_hmset" => [ :first ],
81
84
  "mapped_mget" => [ :all, :all ],
82
85
  "mget" => [ :all ],
83
86
  "monitor" => [ :monitor ],
@@ -122,6 +125,7 @@ class Redis
122
125
  "unsubscribe" => [ :all ],
123
126
  "zadd" => [ :first ],
124
127
  "zcard" => [ :first ],
128
+ "zcount" => [ :first ],
125
129
  "zincrby" => [ :first ],
126
130
  "zrange" => [ :first ],
127
131
  "zrangebyscore" => [ :first ],
@@ -156,8 +160,14 @@ class Redis
156
160
  method_missing(:type, key)
157
161
  end
158
162
 
163
+ alias_method :self_respond_to?, :respond_to?
164
+
159
165
  def respond_to?(command)
160
- @redis.respond_to?(command)
166
+ if self_respond_to?(command)
167
+ true
168
+ else
169
+ @redis.respond_to?(command)
170
+ end
161
171
  end
162
172
 
163
173
  def keys(query = nil)
@@ -165,9 +175,17 @@ class Redis
165
175
  end
166
176
 
167
177
  def method_missing(command, *args, &block)
168
- (before, after) = COMMANDS[command.to_s] ||
178
+ handling = COMMANDS[command.to_s] ||
169
179
  COMMANDS[ALIASES[command.to_s]]
170
180
 
181
+ if handling.nil?
182
+ warn("redis-namespace does not know how to handle '#{command}' command.
183
+ Passing it to redis as is.")
184
+ return
185
+ end
186
+
187
+ (before, after) = handling
188
+
171
189
  # Add the namespace to any parameters that are keys.
172
190
  case before
173
191
  when :first
@@ -184,6 +202,11 @@ class Redis
184
202
  args.push(last) if last
185
203
  when :alternate
186
204
  args.each_with_index { |a, i| args[i] = add_namespace(a) if i.even? }
205
+ when :sort
206
+ args[0] = add_namespace(args[0]) if args[0]
207
+ [:by, :get, :store].each do |key|
208
+ args[1][key] = add_namespace(args[1][key]) if args[1][key]
209
+ end if args[1].is_a?(Hash)
187
210
  end
188
211
 
189
212
  # Dispatch the command to Redis and store the result.
data/spec/redis_spec.rb CHANGED
@@ -1,6 +1,4 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
- require 'redis/namespace'
3
- require 'logger'
4
2
 
5
3
  describe "redis" do
6
4
  before(:all) do
@@ -79,6 +77,14 @@ describe "redis" do
79
77
  @namespaced.hincrby('bar', 'a_number', 3)
80
78
  @namespaced.hmget('bar', 'a_number').should == ['4']
81
79
  @namespaced.hgetall('bar').should == {'key' => 'value', 'key1' => 'value1', 'a_number' => '4'}
80
+
81
+ @namespaced.hsetnx('foonx','nx',10).should be_true
82
+ @namespaced.hsetnx('foonx','nx',12).should be_false
83
+ @namespaced.hget('foonx','nx').should == "10"
84
+ @namespaced.hkeys('foonx').should == %w{ nx }
85
+ @namespaced.hvals('foonx').should == %w{ 10 }
86
+ @namespaced.mapped_hmset('baz', {'key' => 'value', 'key1' => 'value1', 'a_number' => 4})
87
+ @namespaced.hgetall('baz').should == {'key' => 'value', 'key1' => 'value1', 'a_number' => '4'}
82
88
  end
83
89
 
84
90
  it "should properly intersect three sets" do
@@ -101,6 +107,24 @@ describe "redis" do
101
107
  @namespaced.sunion('foo', 'bar').sort.should == %w( 1 2 3 4 )
102
108
  end
103
109
 
110
+ it "should add namespace to sort" do
111
+ @namespaced.sadd('foo', 1)
112
+ @namespaced.sadd('foo', 2)
113
+ @namespaced.set('weight_1', 2)
114
+ @namespaced.set('weight_2', 1)
115
+ @namespaced.set('value_1', 'a')
116
+ @namespaced.set('value_2', 'b')
117
+
118
+ @namespaced.sort('foo').should == %w( 1 2 )
119
+ @namespaced.sort('foo', :limit => [0, 1]).should == %w( 1 )
120
+ @namespaced.sort('foo', :order => 'desc').should == %w( 2 1 )
121
+ @namespaced.sort('foo', :by => 'weight_*').should == %w( 2 1 )
122
+ @namespaced.sort('foo', :get => 'value_*').should == %w( a b )
123
+
124
+ @namespaced.sort('foo', :store => 'result')
125
+ @namespaced.lrange('result', 0, -1).should == %w( 1 2 )
126
+ end
127
+
104
128
  it "should yield the correct list of keys" do
105
129
  @namespaced["foo"] = 1
106
130
  @namespaced["bar"] = 2
@@ -123,6 +147,10 @@ describe "redis" do
123
147
  @namespaced['foo'].should == 'chris'
124
148
  end
125
149
 
150
+ it "should respond to :namespace=" do
151
+ @namespaced.respond_to?(:namespace=).should == true
152
+ end
153
+
126
154
  # Only test aliasing functionality for Redis clients that support aliases.
127
155
  unless Redis::Namespace::ALIASES.empty?
128
156
  it "should support command aliases (delete)" do
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,17 @@
1
1
  require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.setup(:default, :test)
4
+ Bundler.require(:default, :test)
5
+
6
+ require 'rspec'
7
+ require 'redis'
8
+ require 'logger'
9
+
2
10
  $TESTING=true
3
11
  $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
- require 'redis'
12
+ require 'redis/namespace'
5
13
 
6
- Spec::Matchers.define :have_key do |expected|
14
+ RSpec::Matchers.define :have_key do |expected|
7
15
  match do |redis|
8
16
  redis.exists(expected)
9
17
  end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-namespace
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 15
5
+ prerelease:
5
6
  segments:
7
+ - 1
6
8
  - 0
7
- - 10
8
- - 0
9
- version: 0.10.0
9
+ version: "1.0"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Chris Wanstrath
@@ -14,16 +14,18 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-23 00:00:00 -07:00
17
+ date: 2011-05-16 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: redis
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
24
25
  requirements:
25
26
  - - <
26
27
  - !ruby/object:Gem::Version
28
+ hash: 7
27
29
  segments:
28
30
  - 3
29
31
  - 0
@@ -61,23 +63,27 @@ rdoc_options: []
61
63
  require_paths:
62
64
  - lib
63
65
  required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
64
67
  requirements:
65
68
  - - ">="
66
69
  - !ruby/object:Gem::Version
70
+ hash: 3
67
71
  segments:
68
72
  - 0
69
73
  version: "0"
70
74
  required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
71
76
  requirements:
72
77
  - - ">="
73
78
  - !ruby/object:Gem::Version
79
+ hash: 3
74
80
  segments:
75
81
  - 0
76
82
  version: "0"
77
83
  requirements: []
78
84
 
79
85
  rubyforge_project:
80
- rubygems_version: 1.3.6
86
+ rubygems_version: 1.5.2
81
87
  signing_key:
82
88
  specification_version: 3
83
89
  summary: Namespaces Redis commands.