Struct teloxide::dispatching::dialogue::RedisStorage
source · 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: impl IntoConnectionInfo,
serializer: S
) -> Result<Arc<Self>, RedisStorageError<Infallible>>
pub async fn open( url: impl IntoConnectionInfo, serializer: S ) -> Result<Arc<Self>, RedisStorageError<Infallible>>
Examples found in repository?
examples/db_remember.rs (line 41)
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
async fn main() {
pretty_env_logger::init();
log::info!("Starting DB remember bot...");
let bot = Bot::from_env();
let storage: MyStorage = if std::env::var("DB_REMEMBER_REDIS").is_ok() {
RedisStorage::open("redis://127.0.0.1:6379", Bincode).await.unwrap().erase()
} else {
SqliteStorage::open("db.sqlite", Json).await.unwrap().erase()
};
let handler = Update::filter_message()
.enter_dialogue::<Message, ErasedStorage<State>, State>()
.branch(dptree::case![State::Start].endpoint(start))
.branch(
dptree::case![State::GotNumber(n)]
.branch(dptree::entry().filter_command::<Command>().endpoint(got_number))
.branch(dptree::endpoint(invalid_command)),
);
Dispatcher::builder(bot, handler)
.dependencies(dptree::deps![storage])
.enable_ctrlc_handler()
.build()
.dispatch()
.await;
}
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 more