kvx v0.1.3 KVX.Bucket behaviour
Defines a Bucket.
A bucket maps to an underlying data store, controlled by the
adapter. For example, KVX ships with a KVX.Bucket.ExShards
adapter that stores data into ExShards distributed memory
storage – ExShards.
For example, the bucket:
defmodule MyModule do
use use KVX.Bucket
end
Could be configured with:
config :kvx,
adapter: KVX.Bucket.ExShards,
ttl: 10
Most of the configuration that goes into the config is specific to
the adapter, so check KVX.Bucket.ExShards documentation for more
information. However, some configuration is shared across
all adapters, they are:
:ttl- The time in seconds to wait until thekeyexpires. Value:infinitywill wait indefinitely (default: 3600)
Check adapters documentation for more information.
Summary
Callbacks
Store this data, only if it does not already exist. If an item already
exists and an add fails with a KVX.ConflictError exception
Deletes an entire bucket, if it exists
Removes an item from the bucket, if it exists
Returns all objects/tuples {key, value} that matches with the specified
query. The query type/spec depends on each adapter implementation –
:ets.match_spec in case of KVX.Bucket.ExShards
Invalidate all existing cache items
Get the value of key. If the key does not exist the special value nil
is returned
Returns the values of all specified keys. For every key that does not hold
a string value or does not exist, the special value nil is returned.
Because of this, the operation never fails
Store this bulk data, possibly overwriting any existing data
Creates a new bucket if it doesn’t exist. If the bucket already exist, nothing happens – it works as an idempotent operation
Most common command. Store this data, possibly overwriting any existing data
Types
Callbacks
Store this data, only if it does not already exist. If an item already
exists and an add fails with a KVX.ConflictError exception.
If bucket doesn’t exist, it will raise an argument error.
Example
MyBucket.add(:mybucket, "hello", "world")
Deletes an entire bucket, if it exists.
If bucket doesn’t exist, it will raise an argument error.
Example
MyBucket.delete(:mybucket)
Removes an item from the bucket, if it exists.
If bucket doesn’t exist, it will raise an argument error.
Example
MyBucket.delete(:mybucket, "hello")
Returns all objects/tuples {key, value} that matches with the specified
query. The query type/spec depends on each adapter implementation –
:ets.match_spec in case of KVX.Bucket.ExShards.
If bucket doesn’t exist, it will raise an argument error.
Example
MyBucket.find_all(bucket, Ex2ms.fun do object -> object end)
Invalidate all existing cache items.
If bucket doesn’t exist, it will raise an argument error.
Example
MyBucket.flush(:mybucket)
Get the value of key. If the key does not exist the special value nil
is returned.
If bucket doesn’t exist, it will raise an argument error.
Example
MyBucket.get(:mybucket, "hello")
Returns the values of all specified keys. For every key that does not hold
a string value or does not exist, the special value nil is returned.
Because of this, the operation never fails.
If bucket doesn’t exist, it will raise an argument error.
Example
MyBucket.mget(:mybucket, ["hello", "world"])
Store this bulk data, possibly overwriting any existing data.
If bucket doesn’t exist, it will raise an argument error.
Example
MyBucket.mset(:mybucket, [{"a": 1}, {"b", "2"}])