1. Matt Bone
  2. redis-in-py

Commits

Matt Bone  committed b3f971d

sadd, scard

  • Participants
  • Parent commits 2026b58
  • Branches default

Comments (0)

Files changed (2)

File commands.py

View file
     return str(db[key].pop())
 
 
+def sadd(db, key, *args):
+    """
+    See:
+      - http://redis.io/commands/sadd
+    """
+    value = db.setdefault(key, set())
+    for arg in args:
+        value.add(arg)
+    
+    return len(value)
+
+
+def scard(db, key):
+    """
+    See:
+      - http://redis.io/commands/card
+    """
+    return len(db.get(key, set()))
+
+
 def flushdb(db):
     """
     See:
             'flushdb': partial(flushdb, self.db),
             'rpush': partial(rpush, self.db),
             'rpop': partial(rpop, self.db),
+            'sadd': partial(sadd, self.db),
+            'scard': partial(scard, self.db),
             'llen': partial(llen, self.db),
             'ping': ping,
         }

File test_integration.py

View file
     assert redis.rpop("foo") == b"9"
 
     assert redis.llen("foo") == 0
+
+
+def test_sadd(redis):
+    redis.flushdb()  # oops, this needs to be in a setup thing not at collection time
+    assert redis.sadd("newset", "1", "2", "2") == 2
+    assert redis.scard("newset") == 2