@@ -12,14 +12,14 @@ use crate::cfg::Configuration;
12
12
pub const REDIS_CONN_TIMEOUT : Duration = Duration :: from_secs ( 2 ) ;
13
13
14
14
#[ derive( Clone , Debug ) ]
15
- pub enum RedisPool {
15
+ pub enum RedisManager {
16
16
Clustered ( ClusteredRedisPool ) ,
17
17
ClusteredUnpooled ( ClusteredRedisUnpooled ) ,
18
18
NonClustered ( NonClusteredRedisPool ) ,
19
19
NonClusteredUnpooled ( NonClusteredRedisUnpooled ) ,
20
20
}
21
21
22
- impl RedisPool {
22
+ impl RedisManager {
23
23
pub async fn get ( & self ) -> Result < PooledConnection < ' _ > , RunError < RedisError > > {
24
24
match self {
25
25
Self :: Clustered ( pool) => pool. get ( ) . await ,
@@ -234,7 +234,7 @@ async fn new_redis_pool_helper(
234
234
redis_dsn : & str ,
235
235
clustered : bool ,
236
236
max_connections : u16 ,
237
- ) -> RedisPool {
237
+ ) -> RedisManager {
238
238
if clustered {
239
239
let mgr = RedisClusterConnectionManager :: new ( redis_dsn)
240
240
. expect ( "Error initializing redis cluster client" ) ;
@@ -244,7 +244,7 @@ async fn new_redis_pool_helper(
244
244
. await
245
245
. expect ( "Error initializing redis cluster connection pool" ) ;
246
246
let pool = ClusteredRedisPool { pool } ;
247
- RedisPool :: Clustered ( pool)
247
+ RedisManager :: Clustered ( pool)
248
248
} else {
249
249
let mgr = RedisConnectionManager :: new ( redis_dsn) . expect ( "Error initializing redis client" ) ;
250
250
let pool = bb8:: Pool :: builder ( )
@@ -253,11 +253,11 @@ async fn new_redis_pool_helper(
253
253
. await
254
254
. expect ( "Error initializing redis connection pool" ) ;
255
255
let pool = NonClusteredRedisPool { pool } ;
256
- RedisPool :: NonClustered ( pool)
256
+ RedisManager :: NonClustered ( pool)
257
257
}
258
258
}
259
259
260
- async fn new_redis_unpooled_helper ( redis_dsn : & str , clustered : bool ) -> RedisPool {
260
+ async fn new_redis_unpooled_helper ( redis_dsn : & str , clustered : bool ) -> RedisManager {
261
261
if clustered {
262
262
let cli = redis:: cluster:: ClusterClient :: builder ( vec ! [ redis_dsn] )
263
263
. retries ( 1 )
@@ -268,7 +268,7 @@ async fn new_redis_unpooled_helper(redis_dsn: &str, clustered: bool) -> RedisPoo
268
268
. get_async_connection ( )
269
269
. await
270
270
. expect ( "Failed to get redis-cluster-unpooled connection" ) ;
271
- RedisPool :: ClusteredUnpooled ( ClusteredRedisUnpooled { con } )
271
+ RedisManager :: ClusteredUnpooled ( ClusteredRedisUnpooled { con } )
272
272
} else {
273
273
let cli = redis:: Client :: open ( redis_dsn) . expect ( "Error initializing redis unpooled client" ) ;
274
274
let con = redis:: aio:: ConnectionManager :: new_with_backoff_and_timeouts (
@@ -281,34 +281,34 @@ async fn new_redis_unpooled_helper(redis_dsn: &str, clustered: bool) -> RedisPoo
281
281
)
282
282
. await
283
283
. expect ( "Failed to get redis-unpooled connection manager" ) ;
284
- RedisPool :: NonClusteredUnpooled ( NonClusteredRedisUnpooled { con } )
284
+ RedisManager :: NonClusteredUnpooled ( NonClusteredRedisUnpooled { con } )
285
285
}
286
286
}
287
287
288
- pub async fn new_redis_clustered_pooled ( redis_dsn : & str , cfg : & Configuration ) -> RedisPool {
288
+ pub async fn new_redis_clustered_pooled ( redis_dsn : & str , cfg : & Configuration ) -> RedisManager {
289
289
new_redis_pool_helper ( redis_dsn, true , cfg. redis_pool_max_size ) . await
290
290
}
291
291
292
- pub async fn new_redis_clustered_unpooled ( redis_dsn : & str ) -> RedisPool {
292
+ pub async fn new_redis_clustered_unpooled ( redis_dsn : & str ) -> RedisManager {
293
293
new_redis_unpooled_helper ( redis_dsn, true ) . await
294
294
}
295
295
296
- pub async fn new_redis_pooled ( redis_dsn : & str , cfg : & Configuration ) -> RedisPool {
296
+ pub async fn new_redis_pooled ( redis_dsn : & str , cfg : & Configuration ) -> RedisManager {
297
297
new_redis_pool_helper ( redis_dsn, false , cfg. redis_pool_max_size ) . await
298
298
}
299
299
300
- pub async fn new_redis_unpooled ( redis_dsn : & str ) -> RedisPool {
300
+ pub async fn new_redis_unpooled ( redis_dsn : & str ) -> RedisManager {
301
301
new_redis_unpooled_helper ( redis_dsn, false ) . await
302
302
}
303
303
304
304
#[ cfg( test) ]
305
305
mod tests {
306
306
use redis:: AsyncCommands ;
307
307
308
- use super :: RedisPool ;
308
+ use super :: RedisManager ;
309
309
use crate :: cfg:: { CacheType , Configuration } ;
310
310
311
- async fn get_pool ( redis_dsn : & str , cfg : & Configuration ) -> RedisPool {
311
+ async fn get_pool ( redis_dsn : & str , cfg : & Configuration ) -> RedisManager {
312
312
match cfg. cache_type {
313
313
CacheType :: RedisCluster => super :: new_redis_clustered_unpooled ( redis_dsn) . await ,
314
314
CacheType :: Redis => super :: new_redis_unpooled ( redis_dsn) . await ,
0 commit comments