pub struct SubscriberClient { /* private fields */ }
Available on crate feature subscriber-client only.
Expand description

A subscriber client that will manage subscription state to any pubsub channels or patterns for the caller.

If the connection to the server closes for any reason this struct can automatically re-subscribe, etc.

use fred::clients::SubscriberClient;
use fred::prelude::*;
use futures::stream::StreamExt;

let subscriber = SubscriberClient::new(RedisConfig::default());
let _ = subscriber.connect(Some(ReconnectPolicy::default()));
let _ = subscriber.wait_for_connect().await?;
// spawn a task that will automatically re-subscribe to channels and patterns as needed
let _ = subscriber.manage_subscriptions();

// do pubsub things
let jh = tokio::spawn(subscriber.on_message().for_each_concurrent(10, |(channel, message)| {
  println!("Recv message {:?} on channel {}", message, channel);
  Ok(())
}));

let _ = subscriber.subscribe("foo").await?;
let _ = subscriber.psubscribe("bar*").await?;
// if the subscriber connection closes now for any reason the client will automatically re-subscribe to "foo" and "bar*"

// some convenience functions exist as well
println!("Tracking channels: {:?}", subscriber.tracked_channels());
println!("Tracking patterns: {:?}", subscriber.tracked_patterns());

// or force a re-subscription at any time
let _ = subscriber.resubscribe_all().await?;
// or clear all the local state and unsubscribe
let _ = subscriber.unsubscribe_all().await?;

// basic commands (AUTH, QUIT, INFO, PING, etc) work the same as the `RedisClient`
// additionally, tracing and metrics are supported in the same way as the `RedisClient`
let _ = subscriber.quit().await?;
let _ = jh.await;

Implementations

Create a new client instance without connecting to the server.

Create a new SubscriberClient from the config provided to this client.

The returned client will not be connected to the server, and it will use new connections after connecting. However, it will manage the same channel subscriptions as the original client.

Listen for reconnection notifications.

This function can be used to receive notifications whenever the client successfully reconnects in order to select the right database again, re-subscribe to channels, etc.

A reconnection event is also triggered upon first connecting to the server.

Spawn a task that will automatically re-subscribe to any channels or channel patterns used by the client.

Read the set of channels that this client will manage.

Read the set of channel patterns that this client will manage.

Re-subscribe to any tracked channels and patterns concurrently.

This can be used to sync the client’s subscriptions with the server after calling QUIT, then connect, etc.

Unsubscribe from all tracked channels and patterns, and remove them from the client cache.

Trait Implementations

Request for authentication in a password-protected Redis server. Returns ok if successful. Read more

Switch to a different protocol, optionally authenticating in the process. Read more

The unique ID identifying this client and underlying connections. Read more

Read the config used to initialize the client.

Read the reconnect policy used to initialize the client.

Read the RESP version used by the client when communicating with the server.

Whether or not the client has a reconnection policy.

Whether or not the client will automatically pipeline commands.

Update the internal PerformanceConfig in place with new values.

Read the state of the underlying connection(s). Read more

Whether or not the client has an active connection to the server(s).

Connect to the Redis server with an optional reconnection policy. Read more

Wait for the client to connect to the server, or return an error if the initial connection cannot be established. If the client is already connected this future will resolve immediately. Read more

Listen for protocol and connection errors. This stream can be used to more intelligently handle errors that may not appear in the request-response cycle, and so cannot be handled by response futures. Read more

Close the connection to the Redis server. The returned future resolves when the command has been written to the socket, not when the connection has been fully closed. Some time after this future resolves the future returned by connect will resolve which indicates that the connection has been fully closed. Read more

Shut down the server and quit the client. Read more

Ping the Redis server. Read more

Read info about the server. Read more

Run a custom command that is not yet supported via another interface on this client. This is most useful when interacting with third party modules or extensions. Read more

Run a custom command similar to custom, but return the response frame directly without any parsing. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Read the number of request redeliveries. Read more

Read and reset the number of request redeliveries.

Read the number of buffered commands that have not yet been sent to the server.

Available on crate feature metrics only.

Read latency metrics across all commands. Read more

Available on crate feature metrics only.

Read and consume latency metrics, resetting their values afterwards.

Available on crate feature metrics only.

Read network latency metrics across all commands. Read more

Available on crate feature metrics only.

Read and consume network latency metrics, resetting their values afterwards.

Available on crate feature metrics only.

Read request payload size metrics across all commands.

Available on crate feature metrics only.

Read and consume request payload size metrics, resetting their values afterwards.

Available on crate feature metrics only.

Read response payload size metrics across all commands.

Available on crate feature metrics only.

Read and consume response payload size metrics, resetting their values afterwards.

Subscribe to a channel on the PubSub interface, returning the number of channels to which the client is subscribed. Read more

Subscribes the client to the given patterns. Read more

Unsubscribe from a channel on the PubSub interface, returning the number of channels to which hte client is subscribed. Read more

Unsubscribes the client from the given patterns, or from all of them if none is given. Read more

Listen for (channel, message) tuples on the publish-subscribe interface. Keyspace events are not sent on this interface. Read more

Listen for keyspace and keyevent notifications on the publish subscribe interface. Read more

Publish a message on the PubSub interface, returning the number of clients that received the message. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Converts self into T using Into<T>. Read more

Converts self into a target type. Read more

Causes self to use its Binary implementation when Debug-formatted.

Causes self to use its Display implementation when Debug-formatted. Read more

Causes self to use its LowerExp implementation when Debug-formatted. Read more

Causes self to use its LowerHex implementation when Debug-formatted. Read more

Causes self to use its Octal implementation when Debug-formatted.

Causes self to use its Pointer implementation when Debug-formatted. Read more

Causes self to use its UpperExp implementation when Debug-formatted. Read more

Causes self to use its UpperHex implementation when Debug-formatted. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

Pipes by value. This is generally the method you want to use. Read more

Borrows self and passes that borrow into the pipe function. Read more

Mutably borrows self and passes that borrow into the pipe function. Read more

Borrows self, then passes self.borrow() into the pipe function. Read more

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more

Borrows self, then passes self.as_ref() into the pipe function.

Mutably borrows self, then passes self.as_mut() into the pipe function. Read more

Borrows self, then passes self.deref() into the pipe function.

Mutably borrows self, then passes self.deref_mut() into the pipe function. Read more

Pipes a value into a function that cannot ordinarily be called in suffix position. Read more

Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more

Pipes a dereference into a function that cannot normally be called in suffix position. Read more

Pipes a mutable dereference into a function that cannot normally be called in suffix position. Read more

Pipes a reference into a function that cannot ordinarily be called in suffix position. Read more

Pipes a mutable reference into a function that cannot ordinarily be called in suffix position. Read more

Should always be Self

Immutable access to a value. Read more

Mutable access to a value. Read more

Immutable access to the Borrow<B> of a value. Read more

Mutable access to the BorrowMut<B> of a value. Read more

Immutable access to the AsRef<R> view of a value. Read more

Mutable access to the AsMut<R> view of a value. Read more

Immutable access to the Deref::Target of a value. Read more

Mutable access to the Deref::Target of a value. Read more

Calls .tap() only in debug builds, and is erased in release builds.

Calls .tap_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref_mut() only in debug builds, and is erased in release builds. Read more

Provides immutable access for inspection. Read more

Calls tap in debug builds, and does nothing in release builds.

Provides mutable access for modification. Read more

Calls tap_mut in debug builds, and does nothing in release builds.

Provides immutable access to the reference for inspection.

Calls tap_ref in debug builds, and does nothing in release builds.

Provides mutable access to the reference for modification.

Calls tap_ref_mut in debug builds, and does nothing in release builds.

Provides immutable access to the borrow for inspection. Read more

Calls tap_borrow in debug builds, and does nothing in release builds.

Provides mutable access to the borrow for modification.

Calls tap_borrow_mut in debug builds, and does nothing in release builds. Read more

Immutably dereferences self for inspection.

Calls tap_deref in debug builds, and does nothing in release builds.

Mutably dereferences self for modification.

Calls tap_deref_mut in debug builds, and does nothing in release builds. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Attempts to convert self into T using TryInto<T>. Read more

Attempts to convert self into a target type. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more