예제 #1
0
def test_ttl():
    ledis = Ledis()
    ledis.set("str_type", "hello")
    assert ledis.storage["str_type"].expire_at is None

    ledis.expire("str_type", 10)
    assert ledis.ttl("str_type") == 10
예제 #2
0
def test_expire_invalid_seconds():
    ledis = Ledis()
    ledis.set("str_type", "hello")

    with pytest.raises(InvalidValue):
        ledis.expire("str_type", -1)

    with pytest.raises(InvalidValue):
        ledis.expire("str_type", 0)
예제 #3
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
예제 #4
0
def test_expire_key_not_exist():
    ledis = Ledis()
    assert ledis.expire("key_not_found", 1) == -1