Database struct is the primary entry point for the embedded API. It owns a multi-threaded shard engine and document engine, exposing typed methods for key-value, list, hash, set, vector, and document operations.
All methods are safe to call from multiple threads simultaneously. Key-value operations route through per-shard channels and block the caller until the owning shard worker completes the command.
Opening a Database
Database::open
config.shard_count background worker threads that remain alive for the lifetime of the returned Database.
Example:
String Operations
get
key, or None if the key does not exist.
Example:
set
set_ex
ttl.
Example:
del
true if the key existed.
Example:
exists
key exists in the store.
Example:
incr
decr
incrby
delta, returning the new value.
Example:
decrby
delta, returning the new value.
getset
key to value and return the previous value, if any.
Example:
append
value to the string stored at key, returning the new byte length.
Example:
strlen
mget
None, preserving positional correspondence with keys.
Example:
mset
setnx
true if the key was set, false if it already existed.
Example:
expire
key. Returns true if the key exists.
Example:
persist
key, making it persistent. Returns true if the key existed and had a TTL.
ttl
key. Returns None if the key does not exist or has no TTL set.
key_type
key (e.g. "string", "list", "hash", "set", "none").
keys
List Operations
lpush
rpush
lrange
-1 is the last element).
Example:
lpop
rpop
llen
lindex
index in a list, or None if out of range.
Example:
Hash Operations
hset
hget
None if the field or hash does not exist.
hdel
hgetall
hlen
hexists
hincrby
delta, returning the new value.
Example:
Set Operations
sadd
smembers
srem
sismember
member belongs to the set stored at key.
Example:
scard
Vector Operations
vector_set
vector_search
(id, distance) pairs sorted by distance.
Example:
vector_del
true if it existed.
Example:
Server Operations
db_size
flush_db
Engine Access
engine
shared_engine
Arc clone, such as hybrid server mode or custom command dispatch layers.
shared_doc_engine
RwLock appropriately.
Hybrid Mode
start_listener
addr for hybrid embedded + network mode. Returns a JoinHandle for the background server task and a watch::Sender that shuts the server down when true is sent.
Note: the server creates its own shard stores — data is not shared with the embedded Database key-value store. This is intended for scenarios where external clients need independent access.
Requires the server Cargo feature.
Example: