diff --git a/examples/redis_remember_bot/src/main.rs b/examples/redis_remember_bot/src/main.rs index 8fe7a1ca..bffaa8aa 100644 --- a/examples/redis_remember_bot/src/main.rs +++ b/examples/redis_remember_bot/src/main.rs @@ -9,7 +9,6 @@ mod transitions; use states::*; use transitions::*; -use std::sync::Arc; use teloxide::{ dispatching::dialogue::{serializer::Bincode, RedisStorage, Storage}, prelude::*, @@ -54,15 +53,13 @@ async fn run() { .await .expect("Something is wrong with the bot!") }, - Arc::new( - // You can also choose serializer::JSON or serializer::CBOR - // All serializers but JSON require enabling feature - // "serializer-", e. g. "serializer-cbor" - // or "serializer-bincode" - RedisStorage::open("redis://127.0.0.1:6379", Bincode) - .await - .unwrap(), - ), + // You can also choose serializer::JSON or serializer::CBOR + // All serializers but JSON require enabling feature + // "serializer-", e. g. "serializer-cbor" + // or "serializer-bincode" + RedisStorage::open("redis://127.0.0.1:6379", Bincode) + .await + .unwrap(), )) .dispatch() .await; diff --git a/src/dispatching/dialogue/storage/redis_storage.rs b/src/dispatching/dialogue/storage/redis_storage.rs index 0fba0736..37c5fd07 100644 --- a/src/dispatching/dialogue/storage/redis_storage.rs +++ b/src/dispatching/dialogue/storage/redis_storage.rs @@ -35,13 +35,13 @@ impl RedisStorage { pub async fn open( url: impl IntoConnectionInfo, serializer: S, - ) -> Result> { - Ok(Self { + ) -> Result, RedisStorageError> { + Ok(Arc::new(Self { conn: Mutex::new( redis::Client::open(url)?.get_async_connection().await?, ), serializer, - }) + })) } } diff --git a/tests/redis.rs b/tests/redis.rs index a5aadc34..61dd6ad1 100644 --- a/tests/redis.rs +++ b/tests/redis.rs @@ -10,25 +10,22 @@ use teloxide::dispatching::dialogue::{ #[tokio::test] async fn test_redis_json() { - let storage = Arc::new( - RedisStorage::open("redis://127.0.0.1:7777", JSON).await.unwrap(), - ); + let storage = + RedisStorage::open("redis://127.0.0.1:7777", JSON).await.unwrap(); test_redis(storage).await; } #[tokio::test] async fn test_redis_bincode() { - let storage = Arc::new( - RedisStorage::open("redis://127.0.0.1:7778", Bincode).await.unwrap(), - ); + let storage = + RedisStorage::open("redis://127.0.0.1:7778", Bincode).await.unwrap(); test_redis(storage).await; } #[tokio::test] async fn test_redis_cbor() { - let storage = Arc::new( - RedisStorage::open("redis://127.0.0.1:7779", CBOR).await.unwrap(), - ); + let storage = + RedisStorage::open("redis://127.0.0.1:7779", CBOR).await.unwrap(); test_redis(storage).await; }