@@ -4,9 +4,7 @@ use std::error::Error;
4
4
use std:: fmt;
5
5
use std:: time:: { SystemTime , UNIX_EPOCH } ;
6
6
7
- use r2d2:: Error as PoolError ;
8
- use r2d2:: { Pool , PooledConnection } ;
9
- use r2d2_redis:: { redis, RedisConnectionManager } ;
7
+ use r2d2_redis:: { r2d2, redis, RedisConnectionManager } ;
10
8
use rand:: distributions:: Alphanumeric ;
11
9
use rand:: { thread_rng, Rng } ;
12
10
use serde:: ser:: SerializeStruct ;
@@ -16,8 +14,8 @@ use Value;
16
14
17
15
const REDIS_URL_ENV : & str = "REDIS_URL" ;
18
16
const REDIS_URL_DEFAULT : & str = "redis://127.0.0.1/" ;
19
- pub type RedisPooledConnection = PooledConnection < RedisConnectionManager > ;
20
- pub type RedisPool = Pool < RedisConnectionManager > ;
17
+ pub type RedisPooledConnection = r2d2 :: PooledConnection < RedisConnectionManager > ;
18
+ pub type RedisPool = r2d2 :: Pool < RedisConnectionManager > ;
21
19
22
20
#[ derive( Debug ) ]
23
21
pub struct ClientError {
@@ -27,15 +25,15 @@ pub struct ClientError {
27
25
#[ derive( Debug ) ]
28
26
enum ErrorKind {
29
27
Redis ( redis:: RedisError ) ,
30
- PoolInit ( PoolError ) ,
28
+ PoolInit ( r2d2 :: Error ) ,
31
29
}
32
30
33
31
pub fn create_redis_pool ( ) -> Result < RedisPool , ClientError > {
34
32
let redis_url =
35
33
& env:: var ( & REDIS_URL_ENV . to_owned ( ) ) . unwrap_or_else ( |_| REDIS_URL_DEFAULT . to_owned ( ) ) ;
36
34
let url = redis:: parse_redis_url ( redis_url) . unwrap ( ) ;
37
35
let manager = RedisConnectionManager :: new ( url) . unwrap ( ) ;
38
- Pool :: new ( manager) . map_err ( |err| ClientError {
36
+ r2d2 :: Pool :: new ( manager) . map_err ( |err| ClientError {
39
37
kind : ErrorKind :: PoolInit ( err) ,
40
38
} )
41
39
}
@@ -67,7 +65,7 @@ impl Error for ClientError {
67
65
}
68
66
}
69
67
70
- fn cause ( & self ) -> Option < & Error > {
68
+ fn cause ( & self ) -> Option < & dyn Error > {
71
69
match self . kind {
72
70
ErrorKind :: Redis ( ref err) => Some ( err) ,
73
71
ErrorKind :: PoolInit ( ref err) => Some ( err) ,
@@ -83,8 +81,8 @@ impl From<redis::RedisError> for ClientError {
83
81
}
84
82
}
85
83
86
- impl From < PoolError > for ClientError {
87
- fn from ( error : PoolError ) -> ClientError {
84
+ impl From < r2d2 :: Error > for ClientError {
85
+ fn from ( error : r2d2 :: Error ) -> ClientError {
88
86
ClientError {
89
87
kind : ErrorKind :: PoolInit ( error) ,
90
88
}
@@ -235,7 +233,7 @@ impl Client {
235
233
. map ( |entry| serde_json:: to_string ( & entry) . unwrap ( ) )
236
234
. collect :: < Vec < _ > > ( ) ;
237
235
match self . connect ( ) {
238
- Ok ( conn) => redis:: pipe ( )
236
+ Ok ( mut conn) => redis:: pipe ( )
239
237
. atomic ( )
240
238
. cmd ( "SADD" )
241
239
. arg ( "queues" )
@@ -244,7 +242,7 @@ impl Client {
244
242
. cmd ( "LPUSH" )
245
243
. arg ( self . queue_name ( & payload. queue ) )
246
244
. arg ( to_push)
247
- . query ( & * conn)
245
+ . query ( & mut * conn)
248
246
. map_err ( |err| ClientError {
249
247
kind : ErrorKind :: Redis ( err) ,
250
248
} ) ,
0 commit comments