Skip to content

Commit b09b317

Browse files
committed
Update r2d2_redis and use exported r2d2 from it
1 parent 4fdd4e7 commit b09b317

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ matrix:
1111
include:
1212
- rust: stable
1313
env: FMT=1
14-
install:
1514
before_script:
1615
- rustup component add rustfmt
1716
script:

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ rand = "0.7"
1919
serde = "1.0"
2020
serde_json = "1.0"
2121
r2d2 = "0.8"
22-
r2d2_redis = "0.9"
22+
r2d2_redis = "0.11"

src/sidekiq/mod.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ use std::error::Error;
44
use std::fmt;
55
use std::time::{SystemTime, UNIX_EPOCH};
66

7-
use r2d2::Error as PoolError;
8-
use r2d2::{Pool, PooledConnection};
9-
use r2d2_redis::{redis, RedisConnectionManager};
7+
use r2d2_redis::{r2d2, redis, RedisConnectionManager};
108
use rand::distributions::Alphanumeric;
119
use rand::{thread_rng, Rng};
1210
use serde::ser::SerializeStruct;
@@ -16,8 +14,8 @@ use Value;
1614

1715
const REDIS_URL_ENV: &str = "REDIS_URL";
1816
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>;
2119

2220
#[derive(Debug)]
2321
pub struct ClientError {
@@ -27,15 +25,15 @@ pub struct ClientError {
2725
#[derive(Debug)]
2826
enum ErrorKind {
2927
Redis(redis::RedisError),
30-
PoolInit(PoolError),
28+
PoolInit(r2d2::Error),
3129
}
3230

3331
pub fn create_redis_pool() -> Result<RedisPool, ClientError> {
3432
let redis_url =
3533
&env::var(&REDIS_URL_ENV.to_owned()).unwrap_or_else(|_| REDIS_URL_DEFAULT.to_owned());
3634
let url = redis::parse_redis_url(redis_url).unwrap();
3735
let manager = RedisConnectionManager::new(url).unwrap();
38-
Pool::new(manager).map_err(|err| ClientError {
36+
r2d2::Pool::new(manager).map_err(|err| ClientError {
3937
kind: ErrorKind::PoolInit(err),
4038
})
4139
}
@@ -67,7 +65,7 @@ impl Error for ClientError {
6765
}
6866
}
6967

70-
fn cause(&self) -> Option<&Error> {
68+
fn cause(&self) -> Option<&dyn Error> {
7169
match self.kind {
7270
ErrorKind::Redis(ref err) => Some(err),
7371
ErrorKind::PoolInit(ref err) => Some(err),
@@ -83,8 +81,8 @@ impl From<redis::RedisError> for ClientError {
8381
}
8482
}
8583

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 {
8886
ClientError {
8987
kind: ErrorKind::PoolInit(error),
9088
}
@@ -235,7 +233,7 @@ impl Client {
235233
.map(|entry| serde_json::to_string(&entry).unwrap())
236234
.collect::<Vec<_>>();
237235
match self.connect() {
238-
Ok(conn) => redis::pipe()
236+
Ok(mut conn) => redis::pipe()
239237
.atomic()
240238
.cmd("SADD")
241239
.arg("queues")
@@ -244,7 +242,7 @@ impl Client {
244242
.cmd("LPUSH")
245243
.arg(self.queue_name(&payload.queue))
246244
.arg(to_push)
247-
.query(&*conn)
245+
.query(&mut *conn)
248246
.map_err(|err| ClientError {
249247
kind: ErrorKind::Redis(err),
250248
}),

0 commit comments

Comments
 (0)