Skip to main content

Connection

Enum Connection 

Source
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

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 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 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 flush(&mut self) -> Result<()>

FLUSHDB. Drops every key. Persistence remains opted-in; embedded with_persist will rewrite the AOF on its next sync cycle.

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.