Commits

Matt Bone committed 00b3b5e

rename

Comments (0)

Files changed (3)

 
 from functools import partial
 
-from commands.keys import delete
+from commands.keys import delete, rename
 from commands.strings import incr, get, strlen, append, sset, mset, mget, keys
 from commands.hashes import hset, hget, hlen
 from commands.lists import rpush, rpop, llen
         self.commands = {
             #keys
             'del': partial(delete, self.db),
+            'rename': partial(rename, self.db),
 
             # strings
             'incr': partial(incr, self.db),
             removed_count += 1
 
     return removed_count
+
+
+def rename(db, key, newkey):
+    value = db[key]
+    del db[key]
+    db[newkey] = value

test_integration.py

     only_contains([key.encode() for key in test_data.keys()], redis.keys("*"))
     only_contains([b"hello1", b"hello2", b"hello3"], redis.keys("hello[1-9]"))
     only_contains([b"helloA",], redis.keys("hello[A-Z]"))
+
+
+def test_rename(redis):
+    redis.set("foo", "bar")
+
+    redis.rename("foo", "baz")
+
+    assert redis.get("foo") is None
+    assert redis.get("baz") == b"bar"