Commits

Matt Bone committed 77a668c

more commands, tests pass

Comments (0)

Files changed (1)

     return value
 
 
+def append(db, key, append_value):
+    """
+    See:
+      - http://redis.io/commands/append
+    """
+    value = db.get(key, "")
+    new_value = value + append_value
+    db[key] = new_value
+    return len(new_value)
+
+
 def strlen(db, key):
     """
     See:
     return len(db[key])
 
 
+def hset(db, key, field, value):
+    """
+    See:
+      - http://redis.io/commands/hset
+    """
+    hash = db.setdefault(key, {})
+
+    if field in hash:
+        hash[field] = value
+        return 0
+    else:
+        hash[field] = value
+        return 1
+
+
+def hget(db, key, field):
+    """
+    See:
+      - http://redis.io/commands/hset
+    """
+    if key not in db:
+        return None
+
+    hash = db[key]
+    if field in hash:
+        return hash[field]
+    else:
+        return None
+
+
+def hlen(db, key):
+    """
+    See:
+      - http://redis.io/commands/hlen
+    """
+    return len(db.get(key, {}))
+
+
 def rpush(db, key, *args):
     """
     See:
     return len(value)
 
 
+def sismember(db, key, member):
+    """
+    See:
+      - http://redis.io/commands/sismember
+    """
+    value = db.get(key, set())
+    if member in value:
+        return 1
+    else:
+        return 0
+
+
 def scard(db, key):
     """
     See:
     return "PONG"
 
 
+def echo(arg):
+    """
+    See:
+      - http://redis.io/commands/echo
+    """
+    return arg
+
+
 def dbsize(db):
     """
     See:
             'set': partial(sset, self.db),
             'get': partial(get, self.db),
             'strlen': partial(strlen, self.db),
+            'append': partial(append, self.db),
+
+            # hashes
+            'hset': partial(hset, self.db),
+            'hget': partial(hget, self.db),
+            'hlen': partial(hlen, self.db),
 
             # lists
             'rpush': partial(rpush, self.db),
             #sets
             'sadd': partial(sadd, self.db),
             'scard': partial(scard, self.db),
+            'sismember': partial(sismember, self.db),
 
             # connection
             'ping': ping,
+            'echo': echo,
 
             # server
             'flushdb': partial(flushdb, self.db),