Esempio n. 1
0
def test_restore(test_snapshot_filename):
    ledis = Ledis()
    ledis.set("hello", "world")
    ledis.sadd("set_type", 1, 2, 3)
    ledis.save(test_snapshot_filename)

    # Clear current state
    ledis.storage = {}
    assert ledis.get("hello") is None
    assert ledis.get("set_type") is None

    # Restore from persistent data
    ledis.restore(test_snapshot_filename)
    assert ledis.get("hello") == "world"
    assert ledis.smembers("set_type") == [1, 2, 3]
Esempio n. 2
0
def test_expire_str():
    ledis = Ledis()
    ledis.set("str_type", "hello")
    assert ledis.expire("str_type", 1) == 1
    sleep(2)

    # The key will only be lazy-deleted
    # if the key is called in any operations
    assert "str_type" in ledis.storage
    assert ledis.get("str_type") is None
    assert "str_type" not in ledis.storage