Beispiel #1
0
 def test_multi(self):
     r = Client()
     r.set("v1", 11)
     r.set("v2", 22)
     assert r.get("v1", "v3", "v2") == [11, None, 22]
     assert r.delete("v1", "v3", "v2") == True
     assert r.get("v1", "v3", "v2") == [None, None, None]
Beispiel #2
0
 def test_set_delete(self):
     r = Client()
     r.delete("ll")
     r.sadd("ll", 42) == 1
     assert r.get("ll") == {42}
     assert r.delete("ll")
     assert r.get("ll") == None
Beispiel #3
0
 def test_cache2(self):
     r = Client()
     r.setex("kiki", 0.05, 42)
     assert r.incr("kiki", 6) == 48
     assert r.get("kiki") == 48
     time.sleep(0.05)
     assert r.get("kiki") == None
Beispiel #4
0
 def test_queue_delete(self):
     r = Client()
     r.delete("ll")
     r.rpush("ll", 42) == 1
     assert r.get("ll") == [42]
     assert r.delete("ll")
     assert r.get("ll") == None
Beispiel #5
0
 def test_queues(self):
     r = Client()
     r.delete("ll")
     assert r.rpush("ll", 42) == 1
     assert r.rpush("ll", 43) == 2
     assert r.lpush("ll", 41) == 3
     assert r.get("ll") == [41, 42, 43]
     assert r.rpop("ll") == 43
     assert r.lpop("ll") == 41
     assert r.get("ll") == [42]
     assert r.lpop("ll") == 42
     assert r.get("ll") == None
     assert r.lpop("ll") == None
     assert r.rpop("ll") == None
Beispiel #6
0
 def test_x(self):
     r1 = Client()
     r2 = Client()
     r3 = Client()
     assert r1.set("yo", 666) == True
     assert r2.get("yo") == 666
     assert "yo" in r3.keys()
Beispiel #7
0
    def test_cant_mutate_set(self):
        r = Client()
        r.set("jo", {42, 43})
        assert r.get("jo") == {42, 43}
        with self.assertRaises(Exception) as context:
            r.srem("jo", 42)  # jo is a real set, not a redys set

        with self.assertRaises(Exception) as context:
            r.sadd("jo", 44)  # jo is a real set, not a redys set
Beispiel #8
0
    def test_2(self):
        r = Client()
        assert r.set("kkk", "v") == True

        assert r.get("kkk") == "v"

        assert "kkk" in r.keys()

        assert r.delete("kkk") == True

        assert "kkk" not in r.keys()
Beispiel #9
0
    def test_set_method(self):
        r = Client()
        r.delete("a_set")

        assert r.sadd("a_set", 42) == 1
        assert r.sadd("a_set", 43) == 2
        assert r.sadd("a_set", 42) == 2

        assert r.get("a_set") == set((43, 42))

        assert r.srem("a_set", 666) == 2  # 666 not in set, len is the same

        assert r.srem("a_set", 42) == 1
        assert r.srem("a_set", 42) == 1
        assert r.srem("a_set", 43) == 0

        with self.assertRaises(Exception) as context:
            r.srem("a_set", 43)  # the set is dead

        assert r.get("a_set") == None
Beispiel #10
0
    def test_try_queue_method_with_bad_type(self):
        r = Client()
        r.set("kiki", "hello")

        with self.assertRaises(Exception) as context:
            r.rpop("kiki")

        with self.assertRaises(Exception) as context:
            r.rpush("kiki", 42)

        assert r.get("kiki") == "hello"
Beispiel #11
0
    def test_cant_mutate_queue(self):
        r = Client()
        r.set("jo", [42, 43])
        assert r.get("jo") == [42, 43]
        with self.assertRaises(Exception) as context:
            r.rpush("jo", 44)

        with self.assertRaises(Exception) as context:
            r.lpush("jo", 44)

        with self.assertRaises(Exception) as context:
            r.rpop("jo")

        with self.assertRaises(Exception) as context:
            l.rpop("jo")
Beispiel #12
0
    def test_incdec(self):
        r = Client()
        r.delete("val")
        assert r.get("val") == None

        assert r.incr("val") == 1
        assert r.get("val") == 1

        assert r.incr("val") == 2
        assert r.get("val") == 2

        assert r.decr("val") == 1
        assert r.get("val") == 1

        r.delete("val")
        assert r.get("val") == None

        r.decr("val")
        assert r.get("val") == -1
Beispiel #13
0
 def test_1(self):
     c = Client()
     assert c.get("xxx") == None
Beispiel #14
0
 def test_cache(self):
     r = Client()
     r.setex("kiki", 0.05, "hello")
     assert r.get("kiki") == "hello"
     time.sleep(0.05)
     assert r.get("kiki") == None