spec/redis_spec.rb in winescout-redis-rb-0.0.3 vs spec/redis_spec.rb in winescout-redis-rb-0.0.3.1

- old
+ new

@@ -20,11 +20,11 @@ before(:each) do @r['foo'] = 'bar' end after(:each) do - @r.flush_db + @r.keys('*').each {|k| @r.delete k} end after(:all) do @r.quit end @@ -37,10 +37,17 @@ it "should be able to SET a key" do @r['foo'] = 'nik' @r['foo'].should == 'nik' end + it "should be able to SET a key with an expiry" do + @r.set('foo', 'bar', 1) + @r['foo'].should == 'bar' + sleep 2 + @r['foo'].should == nil + end + it "should be able to SETNX(set_unless_exists)" do @r['foo'] = 'nik' @r['foo'].should == 'nik' @r.set_unless_exists 'foo', 'bar' @r['foo'].should == 'nik' @@ -57,12 +64,11 @@ @r.delete('counter') @r.incr('counter').should == 1 @r.incr('counter').should == 2 @r.incr('counter').should == 3 @r.decr('counter').should == 2 - @r.decr('counter').should == 1 - @r.decr('counter').should == 0 + @r.decr('counter', 2).should == 0 end # it "should be able to RANDKEY(return a random key)" do @r.randkey.should_not be_nil end @@ -82,9 +88,17 @@ @r['bar'] = 'ohai' lambda {@r.rename 'foo', 'bar'}.should raise_error(RedisRenameError) @r['bar'].should == 'ohai' end # + it "should be able to EXPIRE a key" do + @r['foo'] = 'bar' + @r.expire('foo', 1) + @r['foo'].should == "bar" + sleep 2 + @r['foo'].should == nil + end + # it "should be able to EXISTS(check if key exists)" do @r['foo'] = 'nik' @r.key?('foo').should be_true @r.delete 'foo' @r.key?('foo').should be_false \ No newline at end of file