pub struct RedisStorage<S> { /* private fields */ }
Available on crate feature
redis-storage
only.Expand description
A dialogue storage based on Redis.
Implementations§
Source§impl<S> RedisStorage<S>
impl<S> RedisStorage<S>
Sourcepub async fn open(
url: &str,
serializer: S,
) -> Result<Arc<Self>, RedisStorageError<Infallible>>
pub async fn open( url: &str, serializer: S, ) -> Result<Arc<Self>, RedisStorageError<Infallible>>
Examples found in repository?
examples/db_remember.rs (line 42)
35async fn main() {
36 pretty_env_logger::init();
37 log::info!("Starting DB remember bot...");
38
39 let bot = Bot::from_env();
40
41 let storage: MyStorage = if std::env::var("DB_REMEMBER_REDIS").is_ok() {
42 RedisStorage::open("redis://127.0.0.1:6379", Bincode).await.unwrap().erase()
43 } else {
44 SqliteStorage::open("db.sqlite", Json).await.unwrap().erase()
45 };
46
47 let handler = Update::filter_message()
48 .enter_dialogue::<Message, ErasedStorage<State>, State>()
49 .branch(dptree::case![State::Start].endpoint(start))
50 .branch(
51 dptree::case![State::GotNumber(n)]
52 .branch(dptree::entry().filter_command::<Command>().endpoint(got_number))
53 .branch(dptree::endpoint(invalid_command)),
54 );
55
56 Dispatcher::builder(bot, handler)
57 .dependencies(dptree::deps![storage])
58 .enable_ctrlc_handler()
59 .build()
60 .dispatch()
61 .await;
62}
Trait Implementations§
Source§impl<S, D> Storage<D> for RedisStorage<S>where
S: Send + Sync + Serializer<D> + 'static,
D: Send + Serialize + DeserializeOwned + 'static,
<S as Serializer<D>>::Error: Debug + Display,
impl<S, D> Storage<D> for RedisStorage<S>where
S: Send + Sync + Serializer<D> + 'static,
D: Send + Serialize + DeserializeOwned + 'static,
<S as Serializer<D>>::Error: Debug + Display,
type Error = RedisStorageError<<S as Serializer<D>>::Error>
Source§fn remove_dialogue(
self: Arc<Self>,
ChatId: ChatId,
) -> BoxFuture<'static, Result<(), Self::Error>>
fn remove_dialogue( self: Arc<Self>, ChatId: ChatId, ) -> BoxFuture<'static, Result<(), Self::Error>>
Removes a dialogue indexed by
chat_id
. Read moreSource§fn update_dialogue(
self: Arc<Self>,
ChatId: ChatId,
dialogue: D,
) -> BoxFuture<'static, Result<(), Self::Error>>
fn update_dialogue( self: Arc<Self>, ChatId: ChatId, dialogue: D, ) -> BoxFuture<'static, Result<(), Self::Error>>
Updates a dialogue indexed by
chat_id
with dialogue
.Auto Trait Implementations§
impl<S> Freeze for RedisStorage<S>where
S: Freeze,
impl<S> !RefUnwindSafe for RedisStorage<S>
impl<S> Send for RedisStorage<S>where
S: Send,
impl<S> Sync for RedisStorage<S>where
S: Sync,
impl<S> Unpin for RedisStorage<S>where
S: Unpin,
impl<S> !UnwindSafe for RedisStorage<S>
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
Mutably borrows from an owned value. Read more
Source§impl<T> Erasable for T
impl<T> Erasable for T
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>
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 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>
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