pub struct Bucket { /* private fields */ }Expand description
A bucket is a collection of key-value pairs. Each key-value pair is stored as a entry in the bucket, and the bucket itself acts as a collection of all these entries.
It is worth noting that the exact terminology for bucket in key-value stores can very depending on the specific implementation. For example:
- Amazon DynamoDB calls a collection of key-value pairs a table
- Redis has hashes, sets, and sorted sets as different types of collections
- Cassandra calls a collection of key-value pairs a column family
- MongoDB calls a collection of key-value pairs a collection
- Riak calls a collection of key-value pairs a bucket
- Memcached calls a collection of key-value pairs a slab
- Azure Cosmos DB calls a collection of key-value pairs a container
In this interface, we use the term bucket to refer to a collection of key-value pairs
Implementations§
Source§impl Bucket
impl Bucket
Sourcepub fn get(&self, key: &str) -> Result<Option<Vec<u8>>, Error>
pub fn get(&self, key: &str) -> Result<Option<Vec<u8>>, Error>
Get the value associated with the specified key
The value is returned as an option. If the key-value pair exists in the
store, it returns Ok(value). If the key does not exist in the
store, it returns Ok(none).
If any other error occurs, it returns an Err(error).
Source§impl Bucket
impl Bucket
Sourcepub fn set(&self, key: &str, value: &[u8]) -> Result<(), Error>
pub fn set(&self, key: &str, value: &[u8]) -> Result<(), Error>
Set the value associated with the key in the store. If the key already exists in the store, it overwrites the value.
If the key does not exist in the store, it creates a new key-value pair.
If any other error occurs, it returns an Err(error).
Source§impl Bucket
impl Bucket
Sourcepub fn list_keys(&self, cursor: Option<u64>) -> Result<KeyResponse, Error>
pub fn list_keys(&self, cursor: Option<u64>) -> Result<KeyResponse, Error>
Get all the keys in the store with an optional cursor (for use in pagination). It
returns a list of keys. Please note that for most KeyValue implementations, this is a
can be a very expensive operation and so it should be used judiciously. Implementations
can return any number of keys in a single response, but they should never attempt to
send more data than is reasonable (i.e. on a small edge device, this may only be a few
KB, while on a large machine this could be several MB). Any response should also return
a cursor that can be used to fetch the next page of keys. See the key-response record
for more information.
Note that the keys are not guaranteed to be returned in any particular order.
If the store is empty, it returns an empty list.
MAY show an out-of-date list of keys if there are concurrent writes to the store.
If any error occurs, it returns an Err(error).