Struct CustomRedisAdapter

Source
pub struct CustomRedisAdapter<E, R> { /* private fields */ }
Expand description

The redis adapter implementation. It is generic over the Driver used to communicate with the redis server. And over the SocketEmitter used to communicate with the local server. This allows to avoid cyclic dependencies between the adapter, socketioxide-core and socketioxide crates.

Trait Implementations§

Source§

impl<E: SocketEmitter, R: Driver> CoreAdapter<E> for CustomRedisAdapter<E, R>

Source§

async fn server_count(&self) -> Result<u16, Self::Error>

Get the number of servers by getting the number of subscribers to the request channel.

Source§

async fn broadcast( &self, packet: Packet, opts: BroadcastOptions, ) -> Result<(), BroadcastError>

Broadcast a packet to all the servers to send them through their sockets.

Source§

async fn broadcast_with_ack( &self, packet: Packet, opts: BroadcastOptions, timeout: Option<Duration>, ) -> Result<Self::AckStream, Self::Error>

Broadcast a packet to all the servers to send them through their sockets.

Returns a Stream that is a combination of the local ack stream and a remote MessageStream. Here is a specific protocol in order to know how many message the server expect to close the stream at the right time:

  • Get the number n of remote servers.
  • Send the broadcast request.
  • Expect n BroadcastAckCount response in the stream to know the number m of expected ack responses.
  • Expect sum(m) broadcast counts sent by the servers.

Example with 3 remote servers (n = 3):

+---+                   +---+                   +---+
| A |                   | B |                   | C |
+---+                   +---+                   +---+
  |                       |                       |
  |---BroadcastWithAck--->|                       |
  |---BroadcastWithAck--------------------------->|
  |                       |                       |
  |<-BroadcastAckCount(2)-|     (n = 2; m = 2)    |
  |<-BroadcastAckCount(2)-------(n = 2; m = 4)----|
  |                       |                       |
  |<----------------Ack---------------------------|
  |<----------------Ack---|                       |
  |                       |                       |
  |<----------------Ack---------------------------|
  |<----------------Ack---|                       |
Source§

type Error = Error<R>

An error that can occur when using the adapter.
Source§

type State = RedisAdapterCtr<R>

A shared state between all the namespace CoreAdapter. This can be used to share a connection for example.
Source§

type AckStream = AckStream<<E as SocketEmitter>::AckStream>

A stream that emits the acknowledgments of multiple sockets.
Source§

type InitRes = InitRes<R>

A named result type for the initialization of the adapter.
Source§

fn new(state: &Self::State, local: CoreLocalAdapter<E>) -> Self

Creates a new adapter with the given state and local adapter. Read more
Source§

fn init( self: Arc<Self>, on_success: impl FnOnce() + Send + 'static, ) -> Self::InitRes

Initializes the adapter. The on_success callback should be called when the adapter ready.
Source§

async fn close(&self) -> Result<(), Self::Error>

Closes the adapter.
Source§

async fn disconnect_socket( &self, opts: BroadcastOptions, ) -> Result<(), BroadcastError>

Disconnects the sockets that match the BroadcastOptions.
Source§

async fn rooms(&self, opts: BroadcastOptions) -> Result<Vec<Room>, Self::Error>

Fetches rooms that match the BroadcastOptions
Source§

async fn add_sockets( &self, opts: BroadcastOptions, rooms: impl RoomParam, ) -> Result<(), Self::Error>

Adds the sockets that match the BroadcastOptions to the rooms.
Source§

async fn del_sockets( &self, opts: BroadcastOptions, rooms: impl RoomParam, ) -> Result<(), Self::Error>

Removes the sockets that match the BroadcastOptions from the rooms.
Source§

async fn fetch_sockets( &self, opts: BroadcastOptions, ) -> Result<Vec<RemoteSocketData>, Self::Error>

Fetches remote sockets that match the BroadcastOptions.
Source§

fn get_local(&self) -> &CoreLocalAdapter<E>

Returns the local adapter. Used to enable default behaviors.
Source§

impl<E, R> DefinedAdapter for CustomRedisAdapter<E, R>

Auto Trait Implementations§

§

impl<E, R> !Freeze for CustomRedisAdapter<E, R>

§

impl<E, R> RefUnwindSafe for CustomRedisAdapter<E, R>

§

impl<E, R> Send for CustomRedisAdapter<E, R>
where R: Send, E: Send,

§

impl<E, R> Sync for CustomRedisAdapter<E, R>
where R: Sync, E: Sync,

§

impl<E, R> Unpin for CustomRedisAdapter<E, R>
where R: Unpin, E: Unpin,

§

impl<E, R> UnwindSafe for CustomRedisAdapter<E, R>
where R: UnwindSafe, E: UnwindSafe,

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T