pub enum Connection {
Embedded(Box<Store>),
Remote(RespClient),
}Expand description
One open connection to a kevy backend, opaque about whether the backend is in-process or over TCP.
Variants§
Embedded(Box<Store>)
In-process kevy_embedded::Store. Boxed because Store is
sizeable (carries its Config, including v1.20 replica
upstream/backoff fields) and dwarfs the RespClient variant.
Remote(RespClient)
Implementations§
Source§impl Connection
impl Connection
Sourcepub fn blpop(
&mut self,
keys: &[&[u8]],
timeout: Option<Duration>,
) -> Result<Option<(Vec<u8>, Vec<u8>)>>
pub fn blpop( &mut self, keys: &[&[u8]], timeout: Option<Duration>, ) -> Result<Option<(Vec<u8>, Vec<u8>)>>
BLPOP key [key ...] timeout — block until one of keys has a
head element (checked in argument order), pop it, and return
(key, value). None = timed out with every list still empty.
timeout = None waits forever. Some(Duration::ZERO) is
rejected with InvalidInput: the wire encodes 0 as “wait
forever”, so a zero duration cannot mean “poll once”.
Sourcepub fn brpop(
&mut self,
keys: &[&[u8]],
timeout: Option<Duration>,
) -> Result<Option<(Vec<u8>, Vec<u8>)>>
pub fn brpop( &mut self, keys: &[&[u8]], timeout: Option<Duration>, ) -> Result<Option<(Vec<u8>, Vec<u8>)>>
BRPOP key [key ...] timeout — symmetric to Self::blpop
from the tail.
Sourcepub fn bzpopmin(
&mut self,
keys: &[&[u8]],
timeout: Option<Duration>,
) -> Result<Option<ZPopHit>>
pub fn bzpopmin( &mut self, keys: &[&[u8]], timeout: Option<Duration>, ) -> Result<Option<ZPopHit>>
BZPOPMIN key [key ...] timeout — block until one of the
sorted sets has a member, then pop the lowest-scored one.
Returns (key, member, score); None on timeout. Timeout
semantics as in Self::blpop. (The server has no BZPOPMAX;
see docs/verb-reference.md.)
Source§impl Connection
impl Connection
Sourcepub fn hset(&mut self, key: &[u8], pairs: &[(&[u8], &[u8])]) -> Result<usize>
pub fn hset(&mut self, key: &[u8], pairs: &[(&[u8], &[u8])]) -> Result<usize>
HSET key field value [field value ...]. Returns the number of
fields that were newly added (not overwrites).
Sourcepub fn hget(&mut self, key: &[u8], field: &[u8]) -> Result<Option<Vec<u8>>>
pub fn hget(&mut self, key: &[u8], field: &[u8]) -> Result<Option<Vec<u8>>>
HGET key field. None when the key or field is absent.
Sourcepub fn hdel(&mut self, key: &[u8], fields: &[&[u8]]) -> Result<usize>
pub fn hdel(&mut self, key: &[u8], fields: &[&[u8]]) -> Result<usize>
HDEL key field [field ...]. Returns the number of fields actually
removed.
Sourcepub fn hlen(&mut self, key: &[u8]) -> Result<usize>
pub fn hlen(&mut self, key: &[u8]) -> Result<usize>
HLEN key. Number of fields in the hash (0 if absent).
Sourcepub fn hgetall(&mut self, key: &[u8]) -> Result<Vec<Vec<u8>>>
pub fn hgetall(&mut self, key: &[u8]) -> Result<Vec<Vec<u8>>>
HGETALL key. Returns a flat [f0, v0, f1, v1, ...] matching the
Redis wire shape; empty when the key is absent.
Sourcepub fn hkeys(&mut self, key: &[u8]) -> Result<Vec<Vec<u8>>>
pub fn hkeys(&mut self, key: &[u8]) -> Result<Vec<Vec<u8>>>
HKEYS key. Returns the hash’s field names (empty if absent).
Sourcepub fn hvals(&mut self, key: &[u8]) -> Result<Vec<Vec<u8>>>
pub fn hvals(&mut self, key: &[u8]) -> Result<Vec<Vec<u8>>>
HVALS key. Returns the hash’s values (empty if absent).
Sourcepub fn lpush(&mut self, key: &[u8], values: &[&[u8]]) -> Result<usize>
pub fn lpush(&mut self, key: &[u8], values: &[&[u8]]) -> Result<usize>
LPUSH key value [value ...]. Returns the new list length.
Sourcepub fn rpush(&mut self, key: &[u8], values: &[&[u8]]) -> Result<usize>
pub fn rpush(&mut self, key: &[u8], values: &[&[u8]]) -> Result<usize>
RPUSH key value [value ...]. Returns the new list length.
Sourcepub fn lpop(&mut self, key: &[u8], count: usize) -> Result<Vec<Vec<u8>>>
pub fn lpop(&mut self, key: &[u8], count: usize) -> Result<Vec<Vec<u8>>>
LPOP key count. Returns up to count values from the head; empty
when the key is absent or already drained.
Sourcepub fn rpop(&mut self, key: &[u8], count: usize) -> Result<Vec<Vec<u8>>>
pub fn rpop(&mut self, key: &[u8], count: usize) -> Result<Vec<Vec<u8>>>
RPOP key count. Symmetric to Self::lpop from the tail.
Sourcepub fn lrange(
&mut self,
key: &[u8],
start: i64,
stop: i64,
) -> Result<Vec<Vec<u8>>>
pub fn lrange( &mut self, key: &[u8], start: i64, stop: i64, ) -> Result<Vec<Vec<u8>>>
LRANGE key start stop. Redis-style indexing — negative offsets
count from the tail (-1 = last element).
Sourcepub fn sadd(&mut self, key: &[u8], members: &[&[u8]]) -> Result<usize>
pub fn sadd(&mut self, key: &[u8], members: &[&[u8]]) -> Result<usize>
SADD key member [member ...]. Returns count of newly added members.
Sourcepub fn srem(&mut self, key: &[u8], members: &[&[u8]]) -> Result<usize>
pub fn srem(&mut self, key: &[u8], members: &[&[u8]]) -> Result<usize>
SREM key member [member ...]. Returns count of removed members.
Sourcepub fn smembers(&mut self, key: &[u8]) -> Result<Vec<Vec<u8>>>
pub fn smembers(&mut self, key: &[u8]) -> Result<Vec<Vec<u8>>>
SMEMBERS key. Order is implementation-defined; empty if absent.
Sourcepub fn sismember(&mut self, key: &[u8], member: &[u8]) -> Result<bool>
pub fn sismember(&mut self, key: &[u8], member: &[u8]) -> Result<bool>
SISMEMBER key member. false when key or member absent.
Sourcepub fn sinter(&mut self, keys: &[&[u8]]) -> Result<Vec<Vec<u8>>>
pub fn sinter(&mut self, keys: &[&[u8]]) -> Result<Vec<Vec<u8>>>
SINTER key [key ...] — intersection of all sets.
Sourcepub fn sunion(&mut self, keys: &[&[u8]]) -> Result<Vec<Vec<u8>>>
pub fn sunion(&mut self, keys: &[&[u8]]) -> Result<Vec<Vec<u8>>>
SUNION key [key ...] — union of all sets.
Sourcepub fn sdiff(&mut self, keys: &[&[u8]]) -> Result<Vec<Vec<u8>>>
pub fn sdiff(&mut self, keys: &[&[u8]]) -> Result<Vec<Vec<u8>>>
SDIFF key [key ...] — members of the first set absent from the rest.
Sourcepub fn zadd(&mut self, key: &[u8], pairs: &[(f64, &[u8])]) -> Result<usize>
pub fn zadd(&mut self, key: &[u8], pairs: &[(f64, &[u8])]) -> Result<usize>
ZADD key score member [score member ...]. Returns count of newly
added members (overwrites don’t count).
Sourcepub fn zrem(&mut self, key: &[u8], members: &[&[u8]]) -> Result<usize>
pub fn zrem(&mut self, key: &[u8], members: &[&[u8]]) -> Result<usize>
ZREM key member [member ...]. Returns count of removed members.
Sourcepub fn zscore(&mut self, key: &[u8], member: &[u8]) -> Result<Option<f64>>
pub fn zscore(&mut self, key: &[u8], member: &[u8]) -> Result<Option<f64>>
ZSCORE key member. None if absent.
Source§impl Connection
impl Connection
Sourcepub fn feed_shards(&mut self) -> Result<usize>
pub fn feed_shards(&mut self) -> Result<usize>
FEED.SHARDS — number of change-feed shards (embedded: always 1).
Sourcepub fn feed_tail(&mut self, shard: usize) -> Result<(u64, u64)>
pub fn feed_tail(&mut self, shard: usize) -> Result<(u64, u64)>
FEED.TAIL shard — the shard’s current (generation, next_offset) cursor: where a consumer starting fresh (or
resuming after a rebuild) begins.
Sourcepub fn feed_read(
&mut self,
shard: usize,
generation: u64,
offset: u64,
count: Option<usize>,
prefixes: &[&[u8]],
) -> Result<FeedBatch>
pub fn feed_read( &mut self, shard: usize, generation: u64, offset: u64, count: Option<usize>, prefixes: &[&[u8]], ) -> Result<FeedBatch>
FEED.READ shard generation offset [COUNT n] [PREFIX p …] —
deliver up to count frames (server default 256) past the
cursor, optionally key-prefix-filtered (fail-open: frames whose
key layout the filter can’t cheaply determine are always
delivered). Resume from (batch.generation, batch.next_offset).
Source§impl Connection
impl Connection
Sourcepub fn hexpire(
&mut self,
key: &[u8],
fields: &[&[u8]],
ttl: Duration,
cond: HExpireCond,
) -> Result<Vec<HExpireCode>>
pub fn hexpire( &mut self, key: &[u8], fields: &[&[u8]], ttl: Duration, cond: HExpireCond, ) -> Result<Vec<HExpireCode>>
HEXPIRE key seconds [NX|XX|GT|LT] FIELDS n field… — set
per-field TTLs, whole-second precision (ttl is truncated
to seconds on both backends, matching the verb; use
Self::hpexpire for milliseconds). One code per field.
Sourcepub fn hpexpire(
&mut self,
key: &[u8],
fields: &[&[u8]],
ttl: Duration,
cond: HExpireCond,
) -> Result<Vec<HExpireCode>>
pub fn hpexpire( &mut self, key: &[u8], fields: &[&[u8]], ttl: Duration, cond: HExpireCond, ) -> Result<Vec<HExpireCode>>
HPEXPIRE key milliseconds [NX|XX|GT|LT] FIELDS n field… —
millisecond-precision variant of Self::hexpire.
Source§impl Connection
impl Connection
Sourcepub fn idx_create_range(
&mut self,
name: &[u8],
prefix: &[u8],
field: &[u8],
ty: IdxType,
) -> Result<()>
pub fn idx_create_range( &mut self, name: &[u8], prefix: &[u8], field: &[u8], ty: IdxType, ) -> Result<()>
IDX.CREATE name ON PREFIX prefix FIELD field TYPE ty KIND range
— declare a plain range index (the common case: range + EQ
queries over one hash field under a key prefix).
Sourcepub fn idx_create_raw(&mut self, args: &[&[u8]]) -> Result<()>
pub fn idx_create_raw(&mut self, args: &[&[u8]]) -> Result<()>
IDX.CREATE <args…> — raw passthrough; args is everything
after the verb (see docs/verb-reference.md for the full
grammar: MAXMEM, DIM/DISTANCE/M/EF for ANN, GROUPBY for agg…).
Sourcepub fn idx_drop(&mut self, name: &[u8]) -> Result<bool>
pub fn idx_drop(&mut self, name: &[u8]) -> Result<bool>
IDX.DROP name — returns whether the index existed.
Sourcepub fn idx_list(&mut self) -> Result<Vec<IdxInfo>>
pub fn idx_list(&mut self) -> Result<Vec<IdxInfo>>
IDX.LIST — declared indexes with build state and stats.
Sourcepub fn idx_query_range(
&mut self,
name: &[u8],
min: &[u8],
max: &[u8],
limit: usize,
cursor: Option<&[u8]>,
) -> Result<IdxPage>
pub fn idx_query_range( &mut self, name: &[u8], min: &[u8], max: &[u8], limit: usize, cursor: Option<&[u8]>, ) -> Result<IdxPage>
IDX.QUERY name RANGE min max [LIMIT n] [CURSOR c] — one page
of (key, value) hits in (value, key) order. min/max are
the wire string forms (e.g. b"18"), coerced server-side per
the index’s declared type. Resume with IdxPage::cursor.
Sourcepub fn idx_query_eq(
&mut self,
name: &[u8],
value: &[u8],
limit: usize,
) -> Result<IdxPage>
pub fn idx_query_eq( &mut self, name: &[u8], value: &[u8], limit: usize, ) -> Result<IdxPage>
IDX.QUERY name EQ value [LIMIT n] — point-lookup page.
Sourcepub fn idx_query_match(
&mut self,
name: &[u8],
text: &[u8],
limit: usize,
) -> Result<Vec<(Vec<u8>, f64)>>
pub fn idx_query_match( &mut self, name: &[u8], text: &[u8], limit: usize, ) -> Result<Vec<(Vec<u8>, f64)>>
IDX.QUERY name MATCH text [LIMIT n] — BM25-ranked full-text
hits as (key, score), best first (needs a KIND text index).
Source§impl Connection
impl Connection
Sourcepub fn pipeline(
&mut self,
build: impl FnOnce(&mut PipelineBuf),
) -> Result<Vec<Reply>>
pub fn pipeline( &mut self, build: impl FnOnce(&mut PipelineBuf), ) -> Result<Vec<Reply>>
Run a pipelined batch: build queues commands into a
PipelineBuf, then the batch is sent as one write and the
per-command replies are returned in queue order.
Error replies to individual commands come back as
Reply::Error entries (they don’t abort the batch) — check
each reply, unlike the typed single-command wraps which map
server errors to io::Error. An empty batch returns Ok(vec![])
without touching the wire.
Source§impl Connection
impl Connection
Sourcepub fn keys(&mut self, pattern: &[u8]) -> Result<Vec<Vec<u8>>>
pub fn keys(&mut self, pattern: &[u8]) -> Result<Vec<Vec<u8>>>
KEYS pattern — every key matching pattern (glob: *, ?,
[abc]). Use sparingly: O(N) over the whole keyspace.
Sourcepub fn scan(
&mut self,
cursor: u64,
pattern: Option<&[u8]>,
count: Option<usize>,
) -> Result<(u64, Vec<Vec<u8>>)>
pub fn scan( &mut self, cursor: u64, pattern: Option<&[u8]>, count: Option<usize>, ) -> Result<(u64, Vec<Vec<u8>>)>
SCAN cursor [MATCH pattern] [COUNT n]. Returns (next_cursor, batch); iterate by re-calling with the returned cursor until
next_cursor == 0.
On the embedded backend the iteration always finishes in one
call — next_cursor is 0 and batch holds every matching key.
count is taken as a hint only.
Source§impl Connection
impl Connection
Sourcepub fn multi(&mut self) -> Result<Transaction<'_>>
pub fn multi(&mut self) -> Result<Transaction<'_>>
Start a MULTI block. Embedded backend returns
io::ErrorKind::Unsupported.
Sourcepub fn watch(&mut self, keys: &[&[u8]]) -> Result<()>
pub fn watch(&mut self, keys: &[&[u8]]) -> Result<()>
WATCH key [key ...] — mark keys for optimistic concurrency.
The next multi on this connection will abort
(EXEC returns Nil) if any watched key was modified between
this call and EXEC. Remote-only.
Per RESP spec, WATCH must be sent before MULTI. Repeated
watch calls accumulate — the abort triggers on any of the
watched keys changing.
Source§impl Connection
impl Connection
Sourcepub fn zinterstore(&mut self, dest: &[u8], keys: &[&[u8]]) -> Result<usize>
pub fn zinterstore(&mut self, dest: &[u8], keys: &[&[u8]]) -> Result<usize>
ZINTERSTORE dest numkeys key… — store the intersection of the
given sorted sets into dest (unweighted, AGGREGATE SUM).
Returns the destination’s cardinality.
Sourcepub fn zinterstore_with(
&mut self,
dest: &[u8],
keys: &[&[u8]],
weights: Option<&[f64]>,
aggregate: ZAggregate,
) -> Result<usize>
pub fn zinterstore_with( &mut self, dest: &[u8], keys: &[&[u8]], weights: Option<&[f64]>, aggregate: ZAggregate, ) -> Result<usize>
ZINTERSTORE dest numkeys key… [WEIGHTS w…] [AGGREGATE SUM|MIN|MAX]
— full option face. weights, when given, must have one entry
per key (the backend rejects a mismatch).
Sourcepub fn zunionstore(&mut self, dest: &[u8], keys: &[&[u8]]) -> Result<usize>
pub fn zunionstore(&mut self, dest: &[u8], keys: &[&[u8]]) -> Result<usize>
ZUNIONSTORE dest numkeys key… — store the union of the given
sorted sets into dest (unweighted, AGGREGATE SUM). Returns
the destination’s cardinality.
Sourcepub fn zunionstore_with(
&mut self,
dest: &[u8],
keys: &[&[u8]],
weights: Option<&[f64]>,
aggregate: ZAggregate,
) -> Result<usize>
pub fn zunionstore_with( &mut self, dest: &[u8], keys: &[&[u8]], weights: Option<&[f64]>, aggregate: ZAggregate, ) -> Result<usize>
ZUNIONSTORE dest numkeys key… [WEIGHTS w…] [AGGREGATE SUM|MIN|MAX]
— full option face, as in Self::zinterstore_with.
Source§impl Connection
impl Connection
Sourcepub fn open(url: &str) -> Result<Self>
pub fn open(url: &str) -> Result<Self>
Open a backend chosen by URL scheme.
See the crate-level docs for the supported URL forms. From v1.3.0,
two Connection::open calls with the same mem://<name> or
file:///path URL share the same backing Store — and the same
pub/sub bus, so Connection::publish reaches a Subscriber::open
opened with the same URL.
Sourcepub fn ping(&mut self) -> Result<()>
pub fn ping(&mut self) -> Result<()>
PING. Returns () on +PONG, propagates any IO or RESP error.
The first thing every healthcheck calls.
Sourcepub fn set(&mut self, key: &[u8], value: &[u8]) -> Result<()>
pub fn set(&mut self, key: &[u8], value: &[u8]) -> Result<()>
SET key value. Unconditional set (no NX/XX). Returns () on success.
Sourcepub fn get(&mut self, key: &[u8]) -> Result<Option<Vec<u8>>>
pub fn get(&mut self, key: &[u8]) -> Result<Option<Vec<u8>>>
GET key. None if absent or expired.
Sourcepub fn del(&mut self, keys: &[&[u8]]) -> Result<usize>
pub fn del(&mut self, keys: &[&[u8]]) -> Result<usize>
DEL key [key ...]. Returns the count of keys that were actually
removed (existing + dropped). Missing keys don’t contribute.
Sourcepub fn exists(&mut self, keys: &[&[u8]]) -> Result<usize>
pub fn exists(&mut self, keys: &[&[u8]]) -> Result<usize>
EXISTS key [key ...]. Count of keys present (a single key can
contribute >1 if passed multiple times, matching Redis semantics).
Sourcepub fn incr(&mut self, key: &[u8]) -> Result<i64>
pub fn incr(&mut self, key: &[u8]) -> Result<i64>
INCR key. Returns the post-increment value. Errors on non-integer
stored value.
Sourcepub fn incr_by(&mut self, key: &[u8], delta: i64) -> Result<i64>
pub fn incr_by(&mut self, key: &[u8], delta: i64) -> Result<i64>
INCRBY key delta. Negative delta is DECRBY. Returns post-value.
Sourcepub fn expire(&mut self, key: &[u8], ttl: Duration) -> Result<bool>
pub fn expire(&mut self, key: &[u8], ttl: Duration) -> Result<bool>
PEXPIRE key ttl_ms. Returns whether the key existed and got a TTL.
Sourcepub fn persist(&mut self, key: &[u8]) -> Result<bool>
pub fn persist(&mut self, key: &[u8]) -> Result<bool>
PERSIST key. Returns whether a TTL was actually removed.
Sourcepub fn ttl_ms(&mut self, key: &[u8]) -> Result<i64>
pub fn ttl_ms(&mut self, key: &[u8]) -> Result<i64>
PTTL key. Returns ms remaining, -2 if no key, -1 if key has no TTL.
Sourcepub fn type_of(&mut self, key: &[u8]) -> Result<String>
pub fn type_of(&mut self, key: &[u8]) -> Result<String>
TYPE key. Returns the value’s type as a Redis-style string (e.g.
"string", "hash", "list", "set", "zset", or "none" if
the key doesn’t exist).
Sourcepub fn flushall(&mut self) -> Result<()>
pub fn flushall(&mut self) -> Result<()>
FLUSHALL. Drops every key. Persistence remains opted-in; embedded
with_persist will rewrite the AOF on its next sync cycle.
Named flushall — not flush — to avoid colliding with
Write::flush’s “sync buffered writes to disk” meaning; this WIPES the
store rather than persisting it.
Sourcepub fn flush(&mut self) -> Result<()>
👎Deprecated since 1.8.0: renamed to flushall: flush collides with Write::flush (sync-to-disk); this WIPES the store
pub fn flush(&mut self) -> Result<()>
renamed to flushall: flush collides with Write::flush (sync-to-disk); this WIPES the store
Deprecated alias for Self::flushall. The old name read like
Write::flush (sync-to-disk) but actually WIPES the store.
Sourcepub fn set_with_ttl(
&mut self,
key: &[u8],
value: &[u8],
ttl: Duration,
) -> Result<()>
pub fn set_with_ttl( &mut self, key: &[u8], value: &[u8], ttl: Duration, ) -> Result<()>
SET key value PX ttl_ms. Convenience for the common
“cache with expiry” pattern; equivalent to set + expire but
atomic.
Sourcepub fn mget(&mut self, keys: &[&[u8]]) -> Result<Vec<Option<Vec<u8>>>>
pub fn mget(&mut self, keys: &[&[u8]]) -> Result<Vec<Option<Vec<u8>>>>
MGET key [key ...] — one reply per key, None for missing /
wrong-type. Returns in the same order as keys.
Sourcepub fn mset(&mut self, pairs: &[(&[u8], &[u8])]) -> Result<()>
pub fn mset(&mut self, pairs: &[(&[u8], &[u8])]) -> Result<()>
MSET key value [key value ...] — set every pair atomically.
Sourcepub fn publish(&mut self, channel: &[u8], message: &[u8]) -> Result<usize>
pub fn publish(&mut self, channel: &[u8], message: &[u8]) -> Result<usize>
PUBLISH channel message. Returns the count of subscribers
that received the message.
As of v1.3.0, the embedded backend has a real in-process pub/sub
bus: when a Subscriber is open against the same mem://<name>
or file:///path URL, this delivers there and returns the actual
receiver count. Anonymous mem:// keeps the old “no subscribers,
returns 0” behaviour (the URL is its own bus, by design).
The pub/sub consumer side lives in Subscriber. On the remote
backend a subscribed TCP connection cannot send normal commands
per the RESP spec; the embedded backend has no such restriction
but Subscriber is still a distinct type for API symmetry.