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 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 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 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 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 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.