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
keysset, adictis returned- If a key does not exist, its value is
None
- If a key does not exist, its value is
- If value of
keyis returned- If
keydoes not exist,Noneis returned
- If
Raises
ResponseErrorValueError- Both
keysandkeyare set
- Both
TypeErrorkeysnot a dictkeynot 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'}