Commits

Matt Bone  committed 206e6ed

hexists

  • Participants
  • Parent commits 577ee37

Comments (0)

Files changed (3)

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

File commands/hashes.py

         if key in hash:
             removed_count += 1
             del hash[key]
-    return removed_count
+    return removed_count
+
+
+def hexists(db, hash_key, key):
+    """
+    See:
+      - http://redis.io/commands/hexists
+    """
+    hash = db.get(hash_key, {})
+
+    if key in hash:
+        return 1
+    else:
+        return 0

File test_integration.py

     assert redis.hlen("hash1") == 0
 
 
+def test_hexists(redis):
+    redis.hset("hash1", "foo", "bar")
+
+    assert redis.hexists("hash1", "foo") == 1
+    assert redis.hexists("hash1", "bar") == 0
+
+
 def test_dbsize(redis):
     redis.set("foo", "bar")
     redis.set("baz", "biz")