pub struct RedisStorage<S> { /* private fields */ }Available on crate feature
redis-storage only.Expand description
A dialogue storage based on Redis.
Ordinary dialogue keys are unprefixed decimal chat IDs; business keys
start with teloxide:dialogue:business:. Use a dedicated Redis database
if other applications store keys in these namespaces.
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>,
key: DialogueKey,
) -> BoxFuture<'static, Result<(), Self::Error>>
fn remove_dialogue( self: Arc<Self>, key: DialogueKey, ) -> BoxFuture<'static, Result<(), Self::Error>>
Removes a dialogue indexed by
key. Read moreSource§fn update_dialogue(
self: Arc<Self>,
key: DialogueKey,
dialogue: D,
) -> BoxFuture<'static, Result<(), Self::Error>>
fn update_dialogue( self: Arc<Self>, key: DialogueKey, dialogue: D, ) -> BoxFuture<'static, Result<(), Self::Error>>
Updates a dialogue indexed by
key with dialogue.Source§fn get_dialogue(
self: Arc<Self>,
key: DialogueKey,
) -> BoxFuture<'static, Result<Option<D>, Self::Error>>
fn get_dialogue( self: Arc<Self>, key: DialogueKey, ) -> BoxFuture<'static, Result<Option<D>, Self::Error>>
Returns the dialogue indexed by
key.Source§fn get_or_insert_dialogue(
self: Arc<Self>,
key: DialogueKey,
default: fn() -> D,
reset_incompatible: bool,
) -> BoxFuture<'static, Result<D, Self::Error>>
fn get_or_insert_dialogue( self: Arc<Self>, key: DialogueKey, default: fn() -> D, reset_incompatible: bool, ) -> BoxFuture<'static, Result<D, Self::Error>>
Returns the stored dialogue or initializes it with
default if absent.
Implementations must not overwrite a concurrently inserted dialogue.
When reset_incompatible is true, implementations may also replace a
state that fails to deserialize, but must not ignore other errors or
overwrite a concurrent update.Source§fn erase(self: Arc<Self>) -> Arc<ErasedStorage<D>> ⓘ
fn erase(self: Arc<Self>) -> Arc<ErasedStorage<D>> ⓘ
Erases
Self::Error to std::error::Error.Source§impl<S: Send + Sync + 'static> StorageKeys for RedisStorage<S>
impl<S: Send + Sync + 'static> StorageKeys for RedisStorage<S>
Auto Trait Implementations§
impl<S> !RefUnwindSafe for RedisStorage<S>
impl<S> !UnwindSafe for RedisStorage<S>
impl<S> Forget for RedisStorage<S>
impl<S> Freeze for RedisStorage<S>where
*const ArcInner<PoolInner<Manager>> is !null: Freeze,
PhantomData<ArcInner<PoolInner<Manager>>>: Freeze,
PhantomData<fn() -> Connection>: Freeze,
S: Freeze,
impl<S> Move for RedisStorage<S>
impl<S> Send for RedisStorage<S>
impl<S> Sync for RedisStorage<S>
impl<S> Unpin for RedisStorage<S>
impl<S> UnsafeUnpin for RedisStorage<S>where
*const ArcInner<PoolInner<Manager>> is !null: UnsafeUnpin,
PhantomData<ArcInner<PoolInner<Manager>>>: UnsafeUnpin,
PhantomData<fn() -> Connection>: UnsafeUnpin,
S: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Erasable for T
impl<T> Erasable for T
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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