Ejemplo n.º 1
0
def test_bad_command(db: RadishStore):
    try:
        db.process_command(b"BAD")
    except Exception as e:
        exc = e
    else:
        exc = None
    assert isinstance(exc, RadishBadRequest)
Ejemplo n.º 2
0
def test_quit(db: RadishStore):
    try:
        db.quit()
    except Exception as e:
        exc = e
    else:
        exc = None
    assert isinstance(exc, RadishConnectionError)
Ejemplo n.º 3
0
def test_mset(db: RadishStore):
    assert db.mset(b"key", b"val", b"key2", b"val2") == b"OK"
    assert db._store == {b"key": b"val", b"key2": b"val2"}
    try:
        db.mset(b"key2", b"val", b"key4")
    except Exception as e:
        exc = e
    else:
        exc = None
    assert isinstance(exc, RadishBadRequest)
    assert db._store == {b"key": b"val", b"key2": b"val2"}
Ejemplo n.º 4
0
"""
Example of Radish DB usage with own storage object:
"""
from radish.database import Server, RadishStore

if __name__ == "__main__":
    my_storage = {}
    radish_store = RadishStore(my_storage)
    server = Server(host="127.0.0.1", port=7272, storage=radish_store)
    server.run()
Ejemplo n.º 5
0
def test_strlen(db: RadishStore):
    db._store = {b"k1": b"Hello, I am byte string"}
    assert db.strlen(b"k1") == 23
    assert db.strlen(b"k3") == 0
Ejemplo n.º 6
0
def test_mget(db: RadishStore):
    db._store = {b"k1": b"1", b"k2": b"2", b"k3": b"3"}
    assert db.mget(b"k2", b"k1") == [b"2", b"1"]
    assert db.mget(b"k2", b"k5") == [b"2", None]
Ejemplo n.º 7
0
def db():
    return RadishStore()
Ejemplo n.º 8
0
def test_ping(db: RadishStore):
    assert db.ping() == b"PONG"
Ejemplo n.º 9
0
def test_echo(db: RadishStore):
    assert db.echo(b"hello") == b"hello"
Ejemplo n.º 10
0
def test_exists(db: RadishStore):
    db._store = {b"k1": b"1", b"k2": b"1", b"k3": b"1"}
    assert db.exists(b"key") == 0
    assert db.exists(b"k1") == 1
    assert db.exists(b"k1", b"k2") == 2
    assert db.exists(b"k1", b"k2", b"key") == 2
Ejemplo n.º 11
0
def test_flush(db: RadishStore):
    assert db.flush() == 0
    db._store = {b"k1": b"1", b"k2": b"1", b"k3": b"1"}
    assert db.flush() == 3
    assert db._store == {}
Ejemplo n.º 12
0
def test_delete(db: RadishStore):
    assert db.delete(b"key") == 0
    db._store = {b"key": b"val"}
    assert db.delete(b"key") == 1
Ejemplo n.º 13
0
def test_get(db: RadishStore):
    assert db.get(b"key") is None
    db._store = {b"key": b"val"}
    assert db.get(b"key") == b"val"
Ejemplo n.º 14
0
def test_set(db: RadishStore):
    assert db.set(b"key", b"val") == 1
    assert db._store == {b"key": b"val"}