-
Notifications
You must be signed in to change notification settings - Fork 0
Python Client
Kyle Hanson edited this page Feb 18, 2022
·
11 revisions
CrissCrossPy is a very thin wrapper around the Redis client. It uses elixir_py to encode between Python and BERT format automatically.
For a full list of commands available see https://github.com/SoCal-Software-Labs/CrissCross/wiki/Redis-API
It is important to always use the raw binary forms of clusters, trees and other values, not their Base58 representation.
>>> client = CrissCross(host=host, port=port, username=username, password=password)>>> client = CrissCross()
>>> location = client.put_multi("", [(("wow", 1.2), {1: (True, None)})])
>>> client.get_multi(location, [("wow", 1.2)])
{1: (True, None)}>> new_location = client.put_multi(location, [("cool", 12345)])
>> client.get(new_location, "cool")
12345Execute SQL write statements with sql to get a new hash back and SQL read statements with sql_read to not modify the tree.
>> client = CrissCross()
>>> location, ret = client.sql("", "CREATE TABLE MyCrissCrossTable (id INTEGER);")
>>> print(ret) # Get the result of the execution
[(Atom(b'ok'), b'Create')]
>>> location2, _ = client.sql(location, "INSERT INTO MyCrissCrossTable VALUES (100);")
>>> location3, _ = client.sql(location2, "INSERT INTO MyCrissCrossTable VALUES (200);")
# When reading from a table, use the read variant to avoid setting TTL on nodes
>>> ret = client.sql_read(location3, "SELECT * FROM MyCrissCrossTable WHERE id > 100;")
>>> print(ret[0][1])
{b'Select': {b'labels': [b'id'], b'rows': [[{b'I64': 200}]]}}Execute many statements at once:
>>> location, sqlreturns = client.sql("", "CREATE TABLE MyCrissCrossTable (id INTEGER);", "INSERT INTO MyCrissCrossTable VALUES (100);", "INSERT INTO MyCrissCrossTable VALUES (200);", "SELECT * FROM MyCrissCrossTable WHERE id > 100;")
>>> print(sqlreturns)
[(Atom(b'ok'), b'Create'), (Atom(b'ok'), {b'Insert': 1}), (Atom(b'ok'), {b'Insert': 1}), (Atom(b'ok'), {b'Select': {b'labels': [b'id'], b'rows': [[{b'I64': 200}]]}})]