Skip to main content

Connection

Enum Connection 

Source
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

Source

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

Source

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.

Source

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

Source

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

Source

pub fn hget(&mut self, key: &[u8], field: &[u8]) -> Result<Option<Vec<u8>>>

HGET key field. None when the key or field is absent.

Source

pub fn hdel(&mut self, key: &[u8], fields: &[&[u8]]) -> Result<usize>

HDEL key field [field ...]. Returns the number of fields actually removed.

Source

pub fn hlen(&mut self, key: &[u8]) -> Result<usize>

HLEN key. Number of fields in the hash (0 if absent).

Source

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.

Source

pub fn hkeys(&mut self, key: &[u8]) -> Result<Vec<Vec<u8>>>

HKEYS key. Returns the hash’s field names (empty if absent).

Source

pub fn hvals(&mut self, key: &[u8]) -> Result<Vec<Vec<u8>>>

HVALS key. Returns the hash’s values (empty if absent).

Source

pub fn lpush(&mut self, key: &[u8], values: &[&[u8]]) -> Result<usize>

LPUSH key value [value ...]. Returns the new list length.

Source

pub fn rpush(&mut self, key: &[u8], values: &[&[u8]]) -> Result<usize>

RPUSH key value [value ...]. Returns the new list length.

Source

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.

Source

pub fn rpop(&mut self, key: &[u8], count: usize) -> Result<Vec<Vec<u8>>>

RPOP key count. Symmetric to Self::lpop from the tail.

Source

pub fn llen(&mut self, key: &[u8]) -> Result<usize>

LLEN key. 0 when the key is absent.

Source

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

Source

pub fn sadd(&mut self, key: &[u8], members: &[&[u8]]) -> Result<usize>

SADD key member [member ...]. Returns count of newly added members.

Source

pub fn srem(&mut self, key: &[u8], members: &[&[u8]]) -> Result<usize>

SREM key member [member ...]. Returns count of removed members.

Source

pub fn smembers(&mut self, key: &[u8]) -> Result<Vec<Vec<u8>>>

SMEMBERS key. Order is implementation-defined; empty if absent.

Source

pub fn scard(&mut self, key: &[u8]) -> Result<usize>

SCARD key. 0 when the key is absent.

Source

pub fn sismember(&mut self, key: &[u8], member: &[u8]) -> Result<bool>

SISMEMBER key member. false when key or member absent.

Source

pub fn sinter(&mut self, keys: &[&[u8]]) -> Result<Vec<Vec<u8>>>

SINTER key [key ...] — intersection of all sets.

Source

pub fn sunion(&mut self, keys: &[&[u8]]) -> Result<Vec<Vec<u8>>>

SUNION key [key ...] — union of all sets.

Source

pub fn sdiff(&mut self, keys: &[&[u8]]) -> Result<Vec<Vec<u8>>>

SDIFF key [key ...] — members of the first set absent from the rest.

Source

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

Source

pub fn zrem(&mut self, key: &[u8], members: &[&[u8]]) -> Result<usize>

ZREM key member [member ...]. Returns count of removed members.

Source

pub fn zscore(&mut self, key: &[u8], member: &[u8]) -> Result<Option<f64>>

ZSCORE key member. None if absent.

Source

pub fn zcard(&mut self, key: &[u8]) -> Result<usize>

ZCARD key. Number of members; 0 if absent.

Source

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.

Source§

impl Connection

Source

pub fn feed_shards(&mut self) -> Result<usize>

FEED.SHARDS — number of change-feed shards (embedded: always 1).

Source

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.

Source

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

Source

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.

Source

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

pub fn hpersist( &mut self, key: &[u8], fields: &[&[u8]], ) -> Result<Vec<HExpireCode>>

HPERSIST key FIELDS n field… — clear per-field TTLs. Codes: -2 missing, -1 had no TTL, 1 cleared.

Source

pub fn httl(&mut self, key: &[u8], fields: &[&[u8]]) -> Result<Vec<i64>>

HTTL key FIELDS n field… — remaining TTL per field in milliseconds (-2 key/field missing, -1 no TTL).

Source§

impl Connection

Source

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

Source

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

Source

pub fn idx_drop(&mut self, name: &[u8]) -> Result<bool>

IDX.DROP name — returns whether the index existed.

Source

pub fn idx_list(&mut self) -> Result<Vec<IdxInfo>>

IDX.LIST — declared indexes with build state and stats.

Source

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.

Source

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.

Source

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

pub fn idx_query_knn( &mut self, name: &[u8], vector: &[f32], k: usize, ) -> Result<Vec<(Vec<u8>, f64)>>

IDX.QUERY name KNN vector [LIMIT k] — nearest neighbours as (key, distance), closest first (needs a KIND ann index). vector is encoded as the f32 little-endian blob the index stores.

Source

pub fn idx_query_raw(&mut self, args: &[&[u8]]) -> Result<Reply>

IDX.QUERY <args…> — raw passthrough returning the raw Reply; args is everything after the verb. The escape hatch for COMPOSE / HYBRID / GROUPS / FIELDS hydration and any future query shape.

Source§

impl Connection

Source

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

Source

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.

Source

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

pub fn randomkey(&mut self) -> Result<Option<Vec<u8>>>

RANDOMKEY — sample one key, or None if the keyspace is empty.

Embed returns the lexicographically-first key (deterministic, no RNG); the server returns a truly random key. Both honour empty.

Source§

impl Connection

Source

pub fn multi(&mut self) -> Result<Transaction<'_>>

Start a MULTI block. Embedded backend returns io::ErrorKind::Unsupported.

Source

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

pub fn unwatch(&mut self) -> Result<()>

UNWATCH — drop every WATCH set on this connection without running a transaction. Remote-only.

Source§

impl Connection

Source

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.

Source

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

Source

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.

Source

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

pub fn zintercard( &mut self, keys: &[&[u8]], limit: Option<usize>, ) -> Result<usize>

ZINTERCARD numkeys key… [LIMIT n] — cardinality of the intersection without materialising it. limit = None counts everything; Some(n) short-circuits at n.

Source§

impl Connection

Source

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.

Source

pub fn ping(&mut self) -> Result<()>

PING. Returns () on +PONG, propagates any IO or RESP error. The first thing every healthcheck calls.

Source

pub fn set(&mut self, key: &[u8], value: &[u8]) -> Result<()>

SET key value. Unconditional set (no NX/XX). Returns () on success.

Source

pub fn get(&mut self, key: &[u8]) -> Result<Option<Vec<u8>>>

GET key. None if absent or expired.

Source

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.

Source

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

Source

pub fn incr(&mut self, key: &[u8]) -> Result<i64>

INCR key. Returns the post-increment value. Errors on non-integer stored value.

Source

pub fn incr_by(&mut self, key: &[u8], delta: i64) -> Result<i64>

INCRBY key delta. Negative delta is DECRBY. Returns post-value.

Source

pub fn expire(&mut self, key: &[u8], ttl: Duration) -> Result<bool>

PEXPIRE key ttl_ms. Returns whether the key existed and got a TTL.

Source

pub fn persist(&mut self, key: &[u8]) -> Result<bool>

PERSIST key. Returns whether a TTL was actually removed.

Source

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.

Source

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

Source

pub fn dbsize(&mut self) -> Result<usize>

DBSIZE. Total live keys at the time of the call.

Source

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 flushallnot flush — to avoid colliding with Write::flush’s “sync buffered writes to disk” meaning; this WIPES the store rather than persisting it.

Source

pub 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

Deprecated alias for Self::flushall. The old name read like Write::flush (sync-to-disk) but actually WIPES the store.

Source

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.

Source

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.

Source

pub fn mset(&mut self, pairs: &[(&[u8], &[u8])]) -> Result<()>

MSET key value [key value ...] — set every pair atomically.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.