+ end
+
+ it "should be able connect without a timeout" do
+ lambda { Redis.new :timeout => 0 }.should_not raise_error
+ end
+
+ it "should be able to provide a logger" do
+ log = StringIO.new
+ r = Redis.new :db => 15, :logger => Logger.new(log)
+ r.ping
+ log.string.should include("ping")
+ end
it "should store and retrieve all possible characters at the beginning and the end of a string" do
(0..255).each do |char_idx|
string = "#{char_idx.chr}---#{char_idx.chr}"
it "should store and retrieve all possible characters at the beginning and the end of a string" do
(0..255).each do |char_idx|
string = "#{char_idx.chr}---#{char_idx.chr}"
it "should be able to SETNX" do
@r['foo'] = 'nik'
@r['foo'].should == 'nik'
@r.setnx 'foo', 'bar'
@r['foo'].should == 'nik'
end
it "should be able to SETNX" do
@r['foo'] = 'nik'
@r['foo'].should == 'nik'
@r.setnx 'foo', 'bar'
@r['foo'].should == 'nik'
end
it "should be able to INCR a key" do
@r.del('counter')
@r.incr('counter').should == 1
@r.incr('counter').should == 2
@r.incr('counter').should == 3
end
it "should be able to INCR a key" do
@r.del('counter')
@r.incr('counter').should == 1
@r.incr('counter').should == 2
@r.incr('counter').should == 3
end
+ #
+ it "should be able to INCRBY a key" do
+ @r.del('counter')
+ @r.incrby('counter', 1).should == 1
+ @r.incrby('counter', 2).should == 3
+ @r.incrby('counter', 3).should == 6
+ end
+ #
@r.decr('counter').should == 2
@r.decr('counter', 2).should == 0
end
@r.decr('counter').should == 2
@r.decr('counter', 2).should == 0
end
it "should be able to check the TYPE of a key" do
@r['foo'] = 'nik'
@r.type('foo').should == "string"
@r.del 'foo'
@r.type('foo').should == "none"
end
it "should be able to check the TYPE of a key" do
@r['foo'] = 'nik'
@r.type('foo').should == "string"
@r.del 'foo'
@r.type('foo').should == "none"
end
it "should be able to push to the tail of a list (RPUSH)" do
@r.rpush "list", 'hello'
@r.type('list').should == "list"
@r.llen('list').should == 1
end
it "should be able to push to the tail of a list (RPUSH)" do
@r.rpush "list", 'hello'
@r.type('list').should == "list"
@r.llen('list').should == 1
end
it "should be able to pop the tail of a list (RPOP)" do
@r.rpush "list", 'hello'
@r.rpush"list", 'goodbye'
it "should be able to pop the tail of a list (RPOP)" do
@r.rpush "list", 'hello'
@r.rpush"list", 'goodbye'
it "should be able to pop the head of a list (LPOP)" do
@r.rpush "list", 'hello'
@r.rpush "list", 'goodbye'
it "should be able to pop the head of a list (LPOP)" do
@r.rpush "list", 'hello'
@r.rpush "list", 'goodbye'
it "should be able to get the length of a list (LLEN)" do
@r.rpush "list", 'hello'
@r.rpush "list", 'goodbye'
@r.type('list').should == "list"
@r.llen('list').should == 2
end
it "should be able to get the length of a list (LLEN)" do
@r.rpush "list", 'hello'
@r.rpush "list", 'goodbye'
@r.type('list').should == "list"
@r.llen('list').should == 2
end
it "should be able to get a range of values from a list (LRANGE)" do
@r.rpush "list", 'hello'
@r.rpush "list", 'goodbye'
it "should be able to get a range of values from a list (LRANGE)" do
@r.rpush "list", 'hello'
@r.rpush "list", 'goodbye'
@r.llen('list').should == 5
@r.lrange('list', 2, -1).should == ['1', '2', '3']
end
@r.llen('list').should == 5
@r.lrange('list', 2, -1).should == ['1', '2', '3']
end
it "should be able to trim a list (LTRIM)" do
@r.rpush "list", 'hello'
@r.rpush "list", 'goodbye'
it "should be able to trim a list (LTRIM)" do
@r.rpush "list", 'hello'
@r.rpush "list", 'goodbye'
@r.llen('list').should == 2
@r.lrange('list', 0, -1).should == ['hello', 'goodbye']
end
@r.llen('list').should == 2
@r.lrange('list', 0, -1).should == ['hello', 'goodbye']
end
it "should be able to get a value by indexing into a list (LINDEX)" do
@r.rpush "list", 'hello'
@r.rpush "list", 'goodbye'
it "should be able to get a value by indexing into a list (LINDEX)" do
@r.rpush "list", 'hello'
@r.rpush "list", 'goodbye'
@r.llen('list').should == 2
@r.lindex('list', 1).should == 'goodbye'
end
@r.llen('list').should == 2
@r.lindex('list', 1).should == 'goodbye'
end
@r.lset('list', 1, 'goodbye').should == 'OK'
@r.lindex('list', 1).should == 'goodbye'
end
@r.lset('list', 1, 'goodbye').should == 'OK'
@r.lindex('list', 1).should == 'goodbye'
end
it "should be able to remove values from a list (LREM)" do
@r.rpush "list", 'hello'
@r.rpush "list", 'goodbye'
it "should be able to remove values from a list (LREM)" do
@r.rpush "list", 'hello'
@r.rpush "list", 'goodbye'
@r.lrem('list', 1, 'hello').should == 1
@r.lrange('list', 0, -1).should == ['goodbye']
end
@r.lrem('list', 1, 'hello').should == 1
@r.lrange('list', 0, -1).should == ['goodbye']
end
@r.scard('set').should == 2
@r.smembers('set').sort.should == ['key1', 'key2'].sort
end
@r.scard('set').should == 2
@r.smembers('set').sort.should == ['key1', 'key2'].sort
end
it "should be able count the members of a set (SCARD)" do
@r.sadd "set", 'key1'
@r.sadd "set", 'key2'
@r.type('set').should == "set"
@r.scard('set').should == 2
end
it "should be able count the members of a set (SCARD)" do
@r.sadd "set", 'key1'
@r.sadd "set", 'key2'
@r.type('set').should == "set"
@r.scard('set').should == 2
end
@r.sismember('set', 'key2').should be_true
@r.sismember('set', 'notthere').should be_false
end
@r.sismember('set', 'key2').should be_true
@r.sismember('set', 'notthere').should be_false
end
it "should be able to do set intersection (SINTER)" do
@r.sadd "set", 'key1'
@r.sadd "set", 'key2'
@r.sadd "set2", 'key2'
@r.sinter('set', 'set2').should == ['key2']
end
it "should be able to do set intersection (SINTER)" do
@r.sadd "set", 'key1'
@r.sadd "set", 'key2'
@r.sadd "set2", 'key2'
@r.sinter('set', 'set2').should == ['key2']
end
@r.sadd "set2", 'key3'
@r.sunion('set', 'set2').sort.should == ['key1','key2','key3'].sort
end
@r.sadd "set2", 'key3'
@r.sunion('set', 'set2').sort.should == ['key1','key2','key3'].sort
end
@r.sunionstore('newone', 'set', 'set2').should == 3
@r.smembers('newone').sort.should == ['key1','key2','key3'].sort
end
@r.sunionstore('newone', 'set', 'set2').should == 3
@r.smembers('newone').sort.should == ['key1','key2','key3'].sort
end
@r.sdiffstore('newone', 'set', 'set2')
@r.smembers('newone').should == ['a']
end
@r.sdiffstore('newone', 'set', 'set2')
@r.smembers('newone').should == ['a']
end
@r.sismember('set2', 'a').should be_true
@r.delete('set1')
end
#
it "should be able to do crazy SORT queries" do
@r.sismember('set2', 'a').should be_true
@r.delete('set1')
end
#
it "should be able to do crazy SORT queries" do
- @r.rpush 'dogs', 4
- @r.sort('dogs', :get => 'dog_*', :limit => [0,1]).should == ['louie']
- @r.sort('dogs', :get => 'dog_*', :limit => [0,1], :order => 'desc alpha').should == ['taj']
+ @r.rpush 'Dogs', 4
+ @r.sort('Dogs', :get => 'dog_*', :limit => [0,1]).should == ['louie']
+ @r.sort('Dogs', :get => 'dog_*', :limit => [0,1], :order => 'desc alpha').should == ['taj']
@r.sort('dogs', :get => ['dog:*:name', 'dog:*:breed'], :limit => [0,1]).should == ['louie', 'mutt']
@r.sort('dogs', :get => ['dog:*:name', 'dog:*:breed'], :limit => [0,1], :order => 'desc alpha').should == ['taj', 'terrier']
end
@r.sort('dogs', :get => ['dog:*:name', 'dog:*:breed'], :limit => [0,1]).should == ['louie', 'mutt']
@r.sort('dogs', :get => ['dog:*:name', 'dog:*:breed'], :limit => [0,1], :order => 'desc alpha').should == ['taj', 'terrier']
end
[:last_save_time, :redis_version, :total_connections_received, :connected_clients, :total_commands_processed, :connected_slaves, :uptime_in_seconds, :used_memory, :uptime_in_days, :changes_since_last_save].each do |x|
@r.info.keys.should include(x)
end
end
[:last_save_time, :redis_version, :total_connections_received, :connected_clients, :total_commands_processed, :connected_slaves, :uptime_in_seconds, :used_memory, :uptime_in_days, :changes_since_last_save].each do |x|
@r.info.keys.should include(x)
end
end
@r['key1'] = 'keyone'
@r['key2'] = 'keytwo'
@r.keys('*').sort.should == ['foo', 'key1', 'key2'].sort #foo from before
@r.flushdb
@r.keys('*').should == []
end
@r['key1'] = 'keyone'
@r['key2'] = 'keytwo'
@r.keys('*').sort.should == ['foo', 'key1', 'key2'].sort #foo from before
@r.flushdb
@r.keys('*').should == []
end
it "should be able to provide the last save time (LASTSAVE)" do
savetime = @r.lastsave
Time.at(savetime).class.should == Time
Time.at(savetime).should <= Time.now
end
it "should be able to provide the last save time (LASTSAVE)" do
savetime = @r.lastsave
Time.at(savetime).class.should == Time
Time.at(savetime).should <= Time.now
end
it "should be able to MGET keys" do
@r['foo'] = 1000
@r['bar'] = 2000
@r.mget('foo', 'bar').should == ['1000', '2000']
@r.mget('foo', 'bar', 'baz').should == ['1000', '2000', nil]
end
it "should be able to MGET keys" do
@r['foo'] = 1000
@r['bar'] = 2000
@r.mget('foo', 'bar').should == ['1000', '2000']
@r.mget('foo', 'bar', 'baz').should == ['1000', '2000', nil]
end
+
+ it "should be able to mapped MGET keys" do
+ @r['foo'] = 1000
+ @r['bar'] = 2000
+ @r.mapped_mget('foo', 'bar').should == { 'foo' => '1000', 'bar' => '2000'}
+ @r.mapped_mget('foo', 'baz', 'bar').should == { 'foo' => '1000', 'bar' => '2000'}
+ end
+
+
+ it "should be able to ECHO" do
+ @r.echo("message in a bottle\n").should == "message in a bottle\n"
+ end
+
+ it "should raise error when invoke MONITOR" do
+ lambda { @r.monitor }.should raise_error
+ end
+
+ it "should raise error when invoke SYNC" do
+ lambda { @r.sync }.should raise_error
+ end
+
it "should handle multiple servers" do
require 'dist_redis'
@r = DistRedis.new(:hosts=> ['localhost:6379', '127.0.0.1:6379'], :db => 15)
it "should handle multiple servers" do
require 'dist_redis'
@r = DistRedis.new(:hosts=> ['localhost:6379', '127.0.0.1:6379'], :db => 15)
pipeline.lpush 'list', "hello"
pipeline.lpush 'list', 42
end
pipeline.lpush 'list', "hello"
pipeline.lpush 'list', 42
end
@r.type('list').should == "list"
@r.llen('list').should == 2
@r.lpop('list').should == '42'
end
@r.type('list').should == "list"
@r.llen('list').should == 2
@r.lpop('list').should == '42'
end