Skip to content

Commit

Permalink
add support for missing commands
Browse files Browse the repository at this point in the history
  • Loading branch information
yaauie authored and hone committed May 25, 2012
1 parent fb00b43 commit 7597f90
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/redis/namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@ class Namespace
# Add the namespace to all elements returned, e.g.
# key1 key2 => namespace:key1 namespace:key2
COMMANDS = {
"append" => [:first],
"auth" => [],
"bgrewriteaof" => [],
"bgsave" => [],
"blpop" => [ :exclude_last, :first ],
"brpop" => [ :exclude_last ],
"brpoplpush" => [ :exclude_last ],
"config" => [],
"dbsize" => [],
"debug" => [ :exclude_first ],
"decr" => [ :first ],
Expand All @@ -60,6 +63,8 @@ class Namespace
"flushall" => [],
"flushdb" => [],
"get" => [ :first ],
"getbit" => [ :first ],
"getrange" => [ :first ],
"getset" => [ :first ],
"hset" => [ :first ],
"hsetnx" => [ :first ],
Expand All @@ -79,9 +84,11 @@ class Namespace
"keys" => [ :first, :all ],
"lastsave" => [],
"lindex" => [ :first ],
"linsert" => [ :first ],
"llen" => [ :first ],
"lpop" => [ :first ],
"lpush" => [ :first ],
"lpushx" => [ :first ],
"lrange" => [ :first ],
"lrem" => [ :first ],
"lset" => [ :first ],
Expand All @@ -93,6 +100,7 @@ class Namespace
"move" => [ :first ],
"mset" => [ :alternate ],
"msetnx" => [ :alternate ],
"ping" => [],
"psubscribe" => [ :all ],
"publish" => [ :first ],
"punsubscribe" => [ :all ],
Expand All @@ -103,15 +111,18 @@ class Namespace
"rpop" => [ :first ],
"rpoplpush" => [ :all ],
"rpush" => [ :first ],
"rpushx" => [ :first ],
"sadd" => [ :first ],
"save" => [],
"scard" => [ :first ],
"sdiff" => [ :all ],
"sdiffstore" => [ :all ],
"select" => [],
"set" => [ :first ],
"setbit" => [ :first ],
"setex" => [ :first ],
"setnx" => [ :first ],
"setrange" => [ :first ],
"shutdown" => [],
"sinter" => [ :all ],
"sinterstore" => [ :all ],
Expand Down
60 changes: 60 additions & 0 deletions spec/redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,66 @@
@namespaced['baz'].should == nil
end

it 'should be able to use a namespace with append' do
@namespaced['foo'] = 'bar'
@namespaced.append('foo','n').should == 4
@namespaced['foo'].should == 'barn'
@redis['foo'].should == 'bar'
end

it 'should be able to use a namespace with brpoplpush' do
@namespaced.lpush('foo','bar')
@namespaced.brpoplpush('foo','bar',0).should == 'bar'
@namespaced.lrange('foo',0,-1).should == []
@namespaced.lrange('bar',0,-1).should == ['bar']
end

it 'should be able to use a namespace with getbit' do
@namespaced.set('foo','bar')
@namespaced.getbit('foo',1).should == 1
end

it 'should be able to use a namespace with getrange' do
@namespaced.set('foo','bar')
@namespaced.getrange('foo',0,-1).should == 'bar'
end

it 'should be able to use a namespace with linsert' do
@namespaced.rpush('foo','bar')
@namespaced.rpush('foo','barn')
@namespaced.rpush('foo','bart')
@namespaced.linsert('foo','BEFORE','barn','barf').should == 4
@namespaced.lrange('foo',0,-1).should == ['bar','barf','barn','bart']
end

it 'should be able to use a namespace with lpushx' do
@namespaced.lpushx('foo','bar').should == 0
@namespaced.lpush('foo','boo')
@namespaced.lpushx('foo','bar').should == 2
@namespaced.lrange('foo',0,-1).should == ['bar','boo']
end

it 'should be able to use a namespace with rpushx' do
@namespaced.rpushx('foo','bar').should == 0
@namespaced.lpush('foo','boo')
@namespaced.rpushx('foo','bar').should == 2
@namespaced.lrange('foo',0,-1).should == ['boo','bar']
end

it 'should be able to use a namespace with setbit' do
@namespaced.setbit('virgin_key', 1, 1)
@namespaced.exists('virgin_key').should be_true
@namespaced.get('virgin_key').should == @namespaced.getrange('virgin_key',0,-1)
end

it 'should be able to use a namespace with setrange' do
@namespaced.setrange('foo', 0, 'bar')
@namespaced['foo'].should == 'bar'

@namespaced.setrange('bar', 2, 'foo')
@namespaced['bar'].should == "\000\000foo"
end

it "should be able to use a namespace with mget" do
@namespaced['foo'] = 1000
@namespaced['bar'] = 2000
Expand Down

0 comments on commit 7597f90

Please sign in to comment.