pub struct RedisStore { /* private fields */ }Implementations§
Source§impl RedisStore
impl RedisStore
Sourcepub fn new(config: RedisStoreConfig) -> Result<Self, RedisStoreError>
pub fn new(config: RedisStoreConfig) -> Result<Self, RedisStoreError>
Examples found in repository?
7async fn main() -> Result<(), Box<dyn std::error::Error>> {
8 let redis_url = env::var("REDIS_URL").unwrap_or_else(|_| "redis://127.0.0.1/".to_owned());
9 let mongo_url =
10 env::var("MONGODB_URI").unwrap_or_else(|_| "mongodb://127.0.0.1:27017".to_owned());
11 let sqlite_url = env::var("DATABASE_URL").unwrap_or_else(|_| "sqlite::memory:".to_owned());
12
13 let redis = RedisStore::new(RedisStoreConfig::new(redis_url))?;
14 let sql = SqliteStore::connect_sqlite(SqlStoreConfig::new(sqlite_url)).await?;
15 let mongo = MongoStore::connect(MongoStoreConfig::new(mongo_url, "rust_zero_example")).await?;
16
17 redis.ping().await?;
18 sql.health_check().await?;
19 mongo.health_check().await?;
20 println!("Redis, SQLite, and MongoDB are ready");
21 Ok(())
22}Sourcepub fn with_metrics(self, metrics: RedisStoreMetrics) -> Self
pub fn with_metrics(self, metrics: RedisStoreMetrics) -> Self
Installs metrics for commands executed by this store.
Sourcepub async fn ping(&self) -> Result<(), RedisStoreError>
pub async fn ping(&self) -> Result<(), RedisStoreError>
Examples found in repository?
7async fn main() -> Result<(), Box<dyn std::error::Error>> {
8 let redis_url = env::var("REDIS_URL").unwrap_or_else(|_| "redis://127.0.0.1/".to_owned());
9 let mongo_url =
10 env::var("MONGODB_URI").unwrap_or_else(|_| "mongodb://127.0.0.1:27017".to_owned());
11 let sqlite_url = env::var("DATABASE_URL").unwrap_or_else(|_| "sqlite::memory:".to_owned());
12
13 let redis = RedisStore::new(RedisStoreConfig::new(redis_url))?;
14 let sql = SqliteStore::connect_sqlite(SqlStoreConfig::new(sqlite_url)).await?;
15 let mongo = MongoStore::connect(MongoStoreConfig::new(mongo_url, "rust_zero_example")).await?;
16
17 redis.ping().await?;
18 sql.health_check().await?;
19 mongo.health_check().await?;
20 println!("Redis, SQLite, and MongoDB are ready");
21 Ok(())
22}Sourcepub async fn do_command<T: FromRedisValue>(
&self,
command: Cmd,
) -> Result<T, RedisStoreError>
pub async fn do_command<T: FromRedisValue>( &self, command: Cmd, ) -> Result<T, RedisStoreError>
Executes an arbitrary Redis command using this store’s connection and timeout policy.
Arguments are passed through exactly as provided. In particular, keys in a raw command are
not automatically namespaced with RedisStoreConfig::key_prefix; callers can use
Self::prefixed_key when constructing commands that should share the store namespace.
Sourcepub fn prefixed_key(&self, key: &str) -> String
pub fn prefixed_key(&self, key: &str) -> String
Applies this store’s configured namespace to a key for use with Self::do_command.
pub async fn get(&self, key: &str) -> Result<Option<Vec<u8>>, RedisStoreError>
pub async fn get_json<T: DeserializeOwned>( &self, key: &str, ) -> Result<Option<T>, RedisStoreError>
pub async fn get_string( &self, key: &str, ) -> Result<Option<String>, RedisStoreError>
pub async fn set( &self, key: &str, value: impl AsRef<[u8]>, ttl: Option<Duration>, ) -> Result<(), RedisStoreError>
pub async fn set_json<T: Serialize>( &self, key: &str, value: &T, ttl: Option<Duration>, ) -> Result<(), RedisStoreError>
pub async fn set_if_absent( &self, key: &str, value: impl AsRef<[u8]>, ttl: Option<Duration>, ) -> Result<bool, RedisStoreError>
pub async fn get_many( &self, keys: &[&str], ) -> Result<Vec<Option<Vec<u8>>>, RedisStoreError>
pub async fn set_many<V: AsRef<[u8]>>( &self, entries: &[(&str, V)], ) -> Result<(), RedisStoreError>
pub async fn delete(&self, keys: &[&str]) -> Result<u64, RedisStoreError>
pub async fn exists(&self, key: &str) -> Result<bool, RedisStoreError>
pub async fn increment( &self, key: &str, amount: i64, ) -> Result<i64, RedisStoreError>
pub async fn decrement( &self, key: &str, amount: i64, ) -> Result<i64, RedisStoreError>
pub async fn expire( &self, key: &str, ttl: Duration, ) -> Result<bool, RedisStoreError>
pub async fn persist(&self, key: &str) -> Result<bool, RedisStoreError>
pub async fn ttl(&self, key: &str) -> Result<RedisTtl, RedisStoreError>
pub async fn hash_get( &self, key: &str, field: &str, ) -> Result<Option<Vec<u8>>, RedisStoreError>
pub async fn hash_set( &self, key: &str, field: &str, value: impl AsRef<[u8]>, ) -> Result<bool, RedisStoreError>
pub async fn hash_get_all( &self, key: &str, ) -> Result<HashMap<Vec<u8>, Vec<u8>>, RedisStoreError>
pub async fn hash_delete( &self, key: &str, fields: &[&str], ) -> Result<u64, RedisStoreError>
pub async fn hash_increment( &self, key: &str, field: &str, amount: i64, ) -> Result<i64, RedisStoreError>
pub async fn list_push_front<V: AsRef<[u8]>>( &self, key: &str, values: &[V], ) -> Result<u64, RedisStoreError>
pub async fn list_push_back<V: AsRef<[u8]>>( &self, key: &str, values: &[V], ) -> Result<u64, RedisStoreError>
pub async fn list_pop_front( &self, key: &str, ) -> Result<Option<Vec<u8>>, RedisStoreError>
pub async fn list_pop_back( &self, key: &str, ) -> Result<Option<Vec<u8>>, RedisStoreError>
pub async fn list_range( &self, key: &str, start: isize, stop: isize, ) -> Result<Vec<Vec<u8>>, RedisStoreError>
pub async fn list_len(&self, key: &str) -> Result<u64, RedisStoreError>
pub async fn set_add<V: AsRef<[u8]>>( &self, key: &str, members: &[V], ) -> Result<u64, RedisStoreError>
pub async fn set_remove<V: AsRef<[u8]>>( &self, key: &str, members: &[V], ) -> Result<u64, RedisStoreError>
pub async fn set_members( &self, key: &str, ) -> Result<HashSet<Vec<u8>>, RedisStoreError>
pub async fn set_contains( &self, key: &str, member: impl AsRef<[u8]>, ) -> Result<bool, RedisStoreError>
pub async fn set_len(&self, key: &str) -> Result<u64, RedisStoreError>
pub async fn sorted_set_add( &self, key: &str, score: f64, member: impl AsRef<[u8]>, ) -> Result<bool, RedisStoreError>
pub async fn sorted_set_remove<V: AsRef<[u8]>>( &self, key: &str, members: &[V], ) -> Result<u64, RedisStoreError>
pub async fn sorted_set_range_with_scores( &self, key: &str, start: isize, stop: isize, ) -> Result<Vec<(Vec<u8>, f64)>, RedisStoreError>
pub async fn sorted_set_score( &self, key: &str, member: impl AsRef<[u8]>, ) -> Result<Option<f64>, RedisStoreError>
pub async fn sorted_set_len(&self, key: &str) -> Result<u64, RedisStoreError>
pub async fn publish( &self, channel: &str, message: impl AsRef<[u8]>, ) -> Result<u64, RedisStoreError>
Sourcepub async fn subscribe<I, S>(
&self,
channels: I,
config: RedisSubscriptionConfig,
) -> Result<RedisSubscription, RedisStoreError>
pub async fn subscribe<I, S>( &self, channels: I, config: RedisSubscriptionConfig, ) -> Result<RedisSubscription, RedisStoreError>
Subscribes to exact channel names using a reconnecting, bounded receiver.
Sourcepub async fn psubscribe<I, S>(
&self,
patterns: I,
config: RedisSubscriptionConfig,
) -> Result<RedisSubscription, RedisStoreError>
pub async fn psubscribe<I, S>( &self, patterns: I, config: RedisSubscriptionConfig, ) -> Result<RedisSubscription, RedisStoreError>
Subscribes to Redis channel patterns using a reconnecting, bounded receiver.
Sourcepub async fn do_pipeline<T: FromRedisValue>(
&self,
pipeline: &Pipeline,
) -> Result<T, RedisStoreError>
pub async fn do_pipeline<T: FromRedisValue>( &self, pipeline: &Pipeline, ) -> Result<T, RedisStoreError>
Executes a caller-built Redis pipeline using the shared connection and operation timeout.
Like Self::do_command, pipeline keys are passed through unchanged. Use
Self::prefixed_key when adding keys that belong to this store’s namespace.
Sourcepub async fn eval<T: FromRedisValue, K: AsRef<str>, A: AsRef<[u8]>>(
&self,
script: &str,
keys: &[K],
arguments: &[A],
) -> Result<T, RedisStoreError>
pub async fn eval<T: FromRedisValue, K: AsRef<str>, A: AsRef<[u8]>>( &self, script: &str, keys: &[K], arguments: &[A], ) -> Result<T, RedisStoreError>
Evaluates a Lua script with automatically prefixed keys and binary-safe arguments.
Sourcepub async fn stream_add<V: AsRef<[u8]>>(
&self,
key: &str,
id: Option<&str>,
fields: &[(&str, V)],
) -> Result<String, RedisStoreError>
pub async fn stream_add<V: AsRef<[u8]>>( &self, key: &str, id: Option<&str>, fields: &[(&str, V)], ) -> Result<String, RedisStoreError>
Appends a field/value entry to a Redis stream and returns its generated or explicit ID.
Sourcepub async fn stream_read(
&self,
streams: &[(&str, &str)],
count: Option<usize>,
block: Option<Duration>,
) -> Result<StreamReadReply, RedisStoreError>
pub async fn stream_read( &self, streams: &[(&str, &str)], count: Option<usize>, block: Option<Duration>, ) -> Result<StreamReadReply, RedisStoreError>
Reads entries from one or more streams using XREAD.
Sourcepub async fn stream_group_create(
&self,
key: &str,
group: &str,
id: &str,
create_stream: bool,
) -> Result<(), RedisStoreError>
pub async fn stream_group_create( &self, key: &str, group: &str, id: &str, create_stream: bool, ) -> Result<(), RedisStoreError>
Creates a consumer group at id, optionally creating an empty stream first.
Sourcepub async fn stream_group_destroy(
&self,
key: &str,
group: &str,
) -> Result<bool, RedisStoreError>
pub async fn stream_group_destroy( &self, key: &str, group: &str, ) -> Result<bool, RedisStoreError>
Destroys a consumer group and reports whether it existed.
Sourcepub async fn stream_group_read(
&self,
group: &str,
consumer: &str,
streams: &[(&str, &str)],
count: Option<usize>,
block: Option<Duration>,
no_ack: bool,
) -> Result<StreamReadReply, RedisStoreError>
pub async fn stream_group_read( &self, group: &str, consumer: &str, streams: &[(&str, &str)], count: Option<usize>, block: Option<Duration>, no_ack: bool, ) -> Result<StreamReadReply, RedisStoreError>
Reads stream entries as a consumer group member using XREADGROUP.
Sourcepub async fn stream_ack(
&self,
key: &str,
group: &str,
ids: &[&str],
) -> Result<u64, RedisStoreError>
pub async fn stream_ack( &self, key: &str, group: &str, ids: &[&str], ) -> Result<u64, RedisStoreError>
Acknowledges delivered stream entries and returns the number newly acknowledged.
Sourcepub async fn stream_pending(
&self,
key: &str,
group: &str,
) -> Result<Value, RedisStoreError>
pub async fn stream_pending( &self, key: &str, group: &str, ) -> Result<Value, RedisStoreError>
Returns the raw XPENDING summary so callers retain Redis-version-specific fields.
Sourcepub async fn stream_claim(
&self,
key: &str,
group: &str,
consumer: &str,
min_idle: Duration,
ids: &[&str],
) -> Result<Value, RedisStoreError>
pub async fn stream_claim( &self, key: &str, group: &str, consumer: &str, min_idle: Duration, ids: &[&str], ) -> Result<Value, RedisStoreError>
Claims pending entries for another consumer using XCLAIM.
The response remains a raw Redis value because newer Redis versions may add optional fields while retaining wire compatibility.
Sourcepub async fn stream_delete(
&self,
key: &str,
ids: &[&str],
) -> Result<u64, RedisStoreError>
pub async fn stream_delete( &self, key: &str, ids: &[&str], ) -> Result<u64, RedisStoreError>
Deletes stream entries and returns the number removed.
Sourcepub async fn stream_group_set_id(
&self,
key: &str,
group: &str,
id: &str,
) -> Result<(), RedisStoreError>
pub async fn stream_group_set_id( &self, key: &str, group: &str, id: &str, ) -> Result<(), RedisStoreError>
Moves a Redis stream consumer group’s last-delivered cursor.
id accepts Redis stream IDs as well as the special $ and 0 values. This corresponds
to XGROUP SETID, including the helper added by go-zero v1.10.3.
pub fn lock(&self, key: impl Into<String>, ttl: Duration) -> RedisLock
Trait Implementations§
Source§impl Clone for RedisStore
impl Clone for RedisStore
Source§fn clone(&self) -> RedisStore
fn clone(&self) -> RedisStore
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for RedisStore
impl !UnwindSafe for RedisStore
impl Freeze for RedisStore
impl Send for RedisStore
impl Sync for RedisStore
impl Unpin for RedisStore
impl UnsafeUnpin for RedisStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ServiceExt for T
impl<T> ServiceExt for T
Source§fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
Source§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
Source§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
Source§fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.