pub enum Connection {
Embedded(Store),
Remote(RespClient),
}Expand description
One open connection to a kevy backend, opaque about whether the backend is in-process or over TCP.
Variants§
Implementations§
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.
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 flush(&mut self) -> Result<()>
pub fn flush(&mut self) -> Result<()>
FLUSHDB. Drops every key. Persistence remains opted-in; embedded
with_persist will rewrite the AOF on its next sync cycle.
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 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 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.
Sourcepub fn zcard(&mut self, key: &[u8]) -> Result<usize>
pub fn zcard(&mut self, key: &[u8]) -> Result<usize>
ZCARD key. Number of members; 0 if absent.
Sourcepub fn zrange(
&mut self,
key: &[u8],
start: i64,
stop: i64,
) -> Result<Vec<Vec<u8>>>
pub fn zrange( &mut self, key: &[u8], start: i64, stop: i64, ) -> Result<Vec<Vec<u8>>>
ZRANGE key start stop. Ascending-score order; negative indices
count from the tail.
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.
On the embedded backend there are no subscribers (single process,
no reactor), so this returns Ok(0) — matching Redis’s
“publish to a channel with no listeners” semantic.
The pub/sub consumer side lives in Subscriber, which takes
its own dedicated TCP connection: a subscribed connection cannot
send normal commands per the Redis/RESP spec, so it can’t share
a socket with this Connection.