kvx v0.1.0 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.Shards
adapter that stores data into a shards
distributed memory
storage – shards.
For example, the bucket:
defmodule MyModule do
use use KVX.Bucket
end
Could be configured with:
config :kvx,
adapter: KVX.Bucket.Shards,
ttl: 10
Most of the configuration that goes into the config
is specific
to the adapter, so check KVX.Bucket.Shards
documentation for more
information. However, some configuration is shared across
all adapters, they are:
:ttl
- The time in seconds to wait until thekey
expires. Value:infinity
will 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 an exception
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.Shards
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 an exception.
If bucket
doesn’t exist, it will raise an argument error.
Example
MyBucket.add(:mybucket, "hello", "world")
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.Shards
.
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"}])
Creates a new bucket if it doesn’t exist. If the bucket already exist, nothing happens – it works as an idempotent operation.
Example
MyBucket.new(:mybucket)