spec/keys_spec.rb in fakeredis-0.4.2 vs spec/keys_spec.rb in fakeredis-0.4.3
- old
+ new
@@ -56,15 +56,15 @@
@client.set("key1", "1")
@client.ttl("key1").should be == -1
end
- it "should not have a ttl if expired" do
+ it "should not have a ttl if expired (and thus key does not exist)" do
@client.set("key1", "1")
@client.expireat("key1", Time.now.to_i)
- @client.ttl("key1").should be == -1
+ @client.ttl("key1").should be == -2
end
it "should not find a key if expired" do
@client.set("key1", "1")
@client.expireat("key1", Time.now.to_i)
@@ -100,11 +100,14 @@
@client.set("key:b", "2")
@client.set("key:c", "3")
@client.set("akeyd", "4")
@client.set("key1", "5")
+ @client.mset("database", 1, "above", 2, "suitability", 3, "able", 4)
+
@client.keys("key:*").should =~ ["key:a", "key:b", "key:c"]
+ @client.keys("ab*").should =~ ["above", "able"]
end
it "should remove the expiration from a key" do
@client.set("key1", "1")
@client.expireat("key1", Time.now.to_i + 1)
@@ -145,14 +148,32 @@
it "should sort the elements in a list, set or sorted set" do
pending "SORT Command not implemented yet"
end
it "should determine the type stored at key" do
- @client.set("key1", "1")
+ # Non-existing key
+ @client.type("key0").should be == "none"
+ # String
+ @client.set("key1", "1")
@client.type("key1").should be == "string"
- @client.type("key0").should be == "none"
+
+ # List
+ @client.lpush("key2", "1")
+ @client.type("key2").should be == "list"
+
+ # Set
+ @client.sadd("key3", "1")
+ @client.type("key3").should be == "set"
+
+ # Sorted Set
+ @client.zadd("key4", 1.0, "1")
+ @client.type("key4").should be == "zset"
+
+ # Hash
+ @client.hset("key5", "a", "1")
+ @client.type("key5").should be == "hash"
end
it "should convert the value into a string before storing" do
@client.set("key1", 1)
@client.get("key1").should be == "1"
@@ -162,10 +183,14 @@
@client.getset("key3", 1)
@client.get("key3").should be == "1"
end
+ it "should return 'OK' for the setex command" do
+ @client.setex("key4", 30, 1).should be == "OK"
+ end
+
it "should convert the key into a string before storing" do
@client.set(123, "foo")
@client.keys.should include("123")
@client.get("123").should be == "foo"
@@ -178,15 +203,15 @@
@client.get("789").should be == "foo"
end
it "should only operate against keys containing string values" do
@client.sadd("key1", "one")
- lambda { @client.get("key1") }.should raise_error(Redis::CommandError, "ERR Operation against a key holding the wrong kind of value")
- lambda { @client.getset("key1", 1) }.should raise_error(Redis::CommandError, "ERR Operation against a key holding the wrong kind of value")
+ lambda { @client.get("key1") }.should raise_error(Redis::CommandError, "WRONGTYPE Operation against a key holding the wrong kind of value")
+ lambda { @client.getset("key1", 1) }.should raise_error(Redis::CommandError, "WRONGTYPE Operation against a key holding the wrong kind of value")
@client.hset("key2", "one", "two")
- lambda { @client.get("key2") }.should raise_error(Redis::CommandError, "ERR Operation against a key holding the wrong kind of value")
- lambda { @client.getset("key2", 1) }.should raise_error(Redis::CommandError, "ERR Operation against a key holding the wrong kind of value")
+ lambda { @client.get("key2") }.should raise_error(Redis::CommandError, "WRONGTYPE Operation against a key holding the wrong kind of value")
+ lambda { @client.getset("key2", 1) }.should raise_error(Redis::CommandError, "WRONGTYPE Operation against a key holding the wrong kind of value")
end
it "should move a key from one database to another successfully" do
@client.select(0)
@client.set("key1", "1")