bagua.torch_api.contrib.utils.store¶
Module Contents¶
- class bagua.torch_api.contrib.utils.store.ClusterStore(stores)¶
Bases:
Store
Base class for distributed key-value stores.
In cluster store, entries will be sharded equally among multiple store instances based on their keys.
- Parameters:
stores (List[Store]) – A list of stores to shard entries on.
- class bagua.torch_api.contrib.utils.store.Store¶
Base class for key-value store implementations. Entries are added to store with
set
ormset
, and retrieved withget
ormget
.- clear()¶
Delete all keys in the current store.
- get(key)¶
Returns the value associated with
key
, orNone
if the key doesn’t exist.- Parameters:
key (str) –
- Return type:
Optional[Union[str, bytes]]
- mget(keys)¶
Retrieve each key’s corresponding value and return them in a list with the same order as
keys
.- Parameters:
keys (List[str]) –
- Return type:
List[Optional[Union[str, bytes]]]
- mset(dictionary)¶
Set multiple entries at once with a dictionary. Each key-value pair in the
dictionary
will be set.- Parameters:
dictionary (Dict[str, Union[str, bytes]]) –
- num_keys()¶
Returns the number of keys in the current store.
- Return type:
int
- set(key, value)¶
Set a key-value pair.
- Parameters:
key (str) –
value (Union[str, bytes]) –
- shutdown()¶
Shutdown the managed store instances. Unmanaged instances will not be killed.
- status()¶
Returns
True
if the current store is alive.- Return type:
bool