pub struct ValkeyConnector { /* private fields */ }Expand description
Reconnecting, multiplexed Valkey database connector.
The connector is cheap to clone and shares one bounded connection manager. Its generic query methods discard driver diagnostics and expose only stable kit errors, while typed convenience methods provide common cache, lease, and counter behavior.
Implementations§
Source§impl ValkeyConnector
impl ValkeyConnector
Sourcepub async fn connect(config: &ValkeyConfig) -> ValkeyResult<Self>
pub async fn connect(config: &ValkeyConfig) -> ValkeyResult<Self>
Establishes and authenticates the initial connection.
Sourcepub async fn health_check(&self) -> ValkeyResult<()>
pub async fn health_check(&self) -> ValkeyResult<()>
Verifies that the server accepts commands on the current connection.
Sourcepub async fn health_report(&self) -> ValkeyResult<ValkeyHealthReport>
pub async fn health_report(&self) -> ValkeyResult<ValkeyHealthReport>
Verifies readiness and returns bounded, non-sensitive connector state.
Sourcepub async fn query<T>(&self, command: &Cmd) -> ValkeyResult<T>where
T: FromRedisValue,
pub async fn query<T>(&self, command: &Cmd) -> ValkeyResult<T>where
T: FromRedisValue,
Executes an app-owned command through the bounded managed connection.
Command names must be fixed by application code. Untrusted data belongs
only in encoded command arguments, never in the command name. Apps that
use keys should call Self::namespaced_key so deployments retain
namespace isolation. Raw driver diagnostics are discarded at this
boundary and never become application errors or logs.
Sourcepub async fn query_pipeline<T>(&self, pipeline: &Pipeline) -> ValkeyResult<T>where
T: FromRedisValue,
pub async fn query_pipeline<T>(&self, pipeline: &Pipeline) -> ValkeyResult<T>where
T: FromRedisValue,
Executes an app-owned pipeline through the bounded managed connection.
A pipeline is not atomic unless the caller explicitly enables
transaction mode on the pipeline. The same namespace and untrusted-input
requirements as Self::query apply.
Sourcepub async fn get(&self, key: &ValkeyKey) -> ValkeyResult<Option<ValkeyValue>>
pub async fn get(&self, key: &ValkeyKey) -> ValkeyResult<Option<ValkeyValue>>
Reads a value, returning None when the key is absent or expired.
Sourcepub async fn set_with_ttl(
&self,
key: &ValkeyKey,
value: &ValkeyValue,
ttl: ValkeyTimeToLive,
) -> ValkeyResult<()>
pub async fn set_with_ttl( &self, key: &ValkeyKey, value: &ValkeyValue, ttl: ValkeyTimeToLive, ) -> ValkeyResult<()>
Stores a value with a mandatory expiration.
Sourcepub async fn set_if_absent_with_ttl(
&self,
key: &ValkeyKey,
value: &ValkeyValue,
ttl: ValkeyTimeToLive,
) -> ValkeyResult<bool>
pub async fn set_if_absent_with_ttl( &self, key: &ValkeyKey, value: &ValkeyValue, ttl: ValkeyTimeToLive, ) -> ValkeyResult<bool>
Acquires a lease only when its key is absent, always with an expiration.
Sourcepub async fn delete(&self, key: &ValkeyKey) -> ValkeyResult<bool>
pub async fn delete(&self, key: &ValkeyKey) -> ValkeyResult<bool>
Deletes a key and reports whether it existed.
Sourcepub async fn release_lease(
&self,
key: &ValkeyKey,
lease_token: &ValkeyValue,
) -> ValkeyResult<bool>
pub async fn release_lease( &self, key: &ValkeyKey, lease_token: &ValkeyValue, ) -> ValkeyResult<bool>
Atomically releases a lease only when the stored token still matches.
Sourcepub async fn increment_with_ttl(
&self,
key: &ValkeyKey,
increment: NonZeroU64,
ttl: ValkeyTimeToLive,
) -> ValkeyResult<u64>
pub async fn increment_with_ttl( &self, key: &ValkeyKey, increment: NonZeroU64, ttl: ValkeyTimeToLive, ) -> ValkeyResult<u64>
Atomically increments a counter and sets its TTL only when first created.
Sourcepub fn namespaced_key(
&self,
key: &ValkeyKey,
) -> ValkeyResult<Zeroizing<Vec<u8>>>
pub fn namespaced_key( &self, key: &ValkeyKey, ) -> ValkeyResult<Zeroizing<Vec<u8>>>
Builds the deployment namespace plus a validated application key.
The returned buffer clears its allocation on drop and can be passed directly to a Valkey command as binary data.
Trait Implementations§
Source§impl Clone for ValkeyConnector
impl Clone for ValkeyConnector
Source§fn clone(&self) -> ValkeyConnector
fn clone(&self) -> ValkeyConnector
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more