get
async def get(keys = None, key=None) -> dict | Any:
Param | Description |
---|---|
key | Key to retrieve |
keys | Keys to retrieve |
Retrieves keys from the database.
Returns
- If
keys
set, adict
is returned- If a key does not exist, its value is
None
- If a key does not exist, its value is
- If value of
key
is returned- If
key
does not exist,None
is returned
- If
Raises
ResponseError
ValueError
- Both
keys
andkey
are set
- Both
TypeError
keys
not a dictkey
not a str
Examples
Connect and Set
from ndb.client import NdbClient
from ndb.kv import KV
client = NdbClient(debug=False) # toggle for debug
await client.open('ws://127.0.0.1:1987/')
# create API instance
kv = KV(client)
await kv.set({'username':'billy', 'password':'billy_passy'})
Get various
# get single key
value = await kv.get(key='username')
print (value)
# get multiple keys
values = await kv.get(keys=('username', 'password'))
print (values)
Output:
billy
{'password': 'billy_passy', 'username': 'billy'}