1. Matt Bone
  2. redis-in-py

Commits

Matt Bone  committed 9d984b7

hgetall

  • Participants
  • Parent commits 2a7ede6
  • Branches default

Comments (0)

Files changed (3)

File backend.py

View file
  • Ignore whitespace
 
 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, hdel, hexists, hkeys, hvals
+from commands.hashes import hset, hget, hlen, hdel, hexists, hkeys, hvals, hgetall
 from commands.lists import rpush, rpop, llen
 from commands.sets import sadd, scard, sismember
 from commands.connection import ping, echo
             'hexists': partial(hexists, self.db),
             'hkeys': partial(hkeys, self.db),
             'hvals': partial(hvals, self.db),
+            'hgetall': partial(hgetall, self.db),
 
             # lists
             'rpush': partial(rpush, self.db),

File commands/hashes.py

View file
  • Ignore whitespace
     """
     # TODO shouldn't need to explictly create a list here...
     return list(db.get(hash_key, {}).values())
+
+
+def hgetall(db, hash_key):
+    """
+    See:
+      - http://redis.io/commands/hgetall
+    """
+    keys_and_values = []
+    for key, value in db.get(hash_key, {}).items():
+        keys_and_values.append(key)
+        keys_and_values.append(value)
+    return keys_and_values

File test_integration.py

View file
  • Ignore whitespace
     assert b"biz" in values
 
 
+def test_hgetall(redis):
+    redis.hset("hash1", "foo", "bar")
+    redis.hset("hash1", "baz", "biz")
+
+    assert redis.hgetall("hash1") == {b'foo': b'bar',
+                                      b'baz': b'biz'}
+
+
 def test_dbsize(redis):
     redis.set("foo", "bar")
     redis.set("baz", "biz")