From 9b0a0f451b64cd1a673529392fcf89b5cd8260b1 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Fri, 20 Dec 2019 22:09:08 +0600 Subject: [PATCH] update actix; prep release --- CHANGES.md | 6 ++- Cargo.toml | 10 ++-- src/redis.rs | 2 +- src/session.rs | 124 +++++++++++++++++++++++-------------------------- 4 files changed, 69 insertions(+), 73 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index d2e7fa6ea..8e0f972bc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,10 @@ # Changes -## 0.8.0-alpha.1 (2019-12-16) +## [0.8.0] 2019-12-20 + +* Release + +## [0.8.0-alpha.1] 2019-12-16 * Migrate to actix 0.9 diff --git a/Cargo.toml b/Cargo.toml index a10e9aa8e..1de850069 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-redis" -version = "0.8.0-alpha.1" +version = "0.8.0" authors = ["Nikolay Kim "] description = "Redis integration for actix framework" license = "MIT/Apache-2.0" @@ -28,7 +28,7 @@ default = ["web"] web = ["actix/http", "actix-service", "actix-web", "actix-session/cookie-session", "rand", "serde", "serde_json"] [dependencies] -actix = "0.9.0-alpha.2" +actix = "0.9.0" actix-utils = "1.0.3" log = "0.4.6" @@ -38,13 +38,13 @@ futures = "0.3.1" redis-async = "0.6.1" actix-rt = "1.0.0" time = "0.1.42" -tokio = "0.2.4" +tokio = "0.2.6" tokio-util = "0.2.0" # actix web session -actix-web = { version = "2.0.0-alpha.6", optional = true } +actix-web = { version = "2.0.0-rc", optional = true } actix-service = { version = "1.0.0", optional = true } -actix-session = { version = "0.3.0-alpha", optional = true } +actix-session = { version = "0.3.0", optional = true } rand = { version = "0.7.0", optional = true } serde = { version = "1.0.101", optional = true, features = ["derive"] } serde_json = { version = "1.0.40", optional = true } diff --git a/src/redis.rs b/src/redis.rs index c9aa643e7..6a4c81a3f 100644 --- a/src/redis.rs +++ b/src/redis.rs @@ -139,7 +139,7 @@ impl Handler for RedisActor { let _ = tx.send(Err(Error::NotConnected)); } - Box::new(rx.map(|res| match res { + Box::pin(rx.map(|res| match res { Ok(res) => res, Err(_) => Err(Error::Disconnected), })) diff --git a/src/session.rs b/src/session.rs index 5b67f2af5..b7d281dcf 100644 --- a/src/session.rs +++ b/src/session.rs @@ -210,8 +210,7 @@ impl Inner { async fn load( &self, req: &ServiceRequest, - ) -> Result, String)>, Error> - { + ) -> Result, String)>, Error> { if let Ok(cookies) = req.cookies() { for cookie in cookies.iter() { if cookie.name() == self.name { @@ -220,45 +219,39 @@ impl Inner { if let Some(cookie) = jar.signed(&self.key).get(&self.name) { let value = cookie.value().to_owned(); let cachekey = (self.cache_keygen)(&cookie.value()); - return - match self.addr.send(Command(resp_array!["GET", cachekey])) - .await { - Err(e) => Err(Error::from(e)), - Ok(res) => match res { - Ok(val) => { - match val { - RespValue::Error(err) => { - return Err( - error::ErrorInternalServerError( - err, - ), - ); - } - RespValue::SimpleString(s) => { - if let Ok(val) = - serde_json::from_str(&s) - { - return Ok(Some((val, value))); - } - } - RespValue::BulkString(s) => { - if let Ok(val) = - serde_json::from_slice(&s) - { - return Ok(Some((val, value))); - } - } - _ => (), + return match self + .addr + .send(Command(resp_array!["GET", cachekey])) + .await + { + Err(e) => Err(Error::from(e)), + Ok(res) => match res { + Ok(val) => { + match val { + RespValue::Error(err) => { + return Err( + error::ErrorInternalServerError(err), + ); } - Ok(None) + RespValue::SimpleString(s) => { + if let Ok(val) = serde_json::from_str(&s) { + return Ok(Some((val, value))); + } + } + RespValue::BulkString(s) => { + if let Ok(val) = serde_json::from_slice(&s) { + return Ok(Some((val, value))); + } + } + _ => (), } - Err(err) => { - Err(error::ErrorInternalServerError(err)) - } - }, - } + Ok(None) + } + Err(err) => Err(error::ErrorInternalServerError(err)), + }, + }; } else { - return Ok(None) + return Ok(None); } } } @@ -311,25 +304,26 @@ impl Inner { match serde_json::to_string(&state) { Err(e) => Err(e.into()), Ok(body) => { - match self.addr + match self + .addr .send(Command(resp_array!["SET", cachekey, body, "EX", &self.ttl])) - .await { - Err(e) => Err(Error::from(e)), - Ok(redis_result) => match redis_result { - Ok(_) => { - if let Some(jar) = jar { - for cookie in jar.delta() { - let val = - HeaderValue::from_str(&cookie.to_string())?; - res.headers_mut() - .append(header::SET_COOKIE, val); - } + .await + { + Err(e) => Err(Error::from(e)), + Ok(redis_result) => match redis_result { + Ok(_) => { + if let Some(jar) = jar { + for cookie in jar.delta() { + let val = + HeaderValue::from_str(&cookie.to_string())?; + res.headers_mut().append(header::SET_COOKIE, val); } - Ok(res) } - Err(err) => Err(error::ErrorInternalServerError(err)), - }, - } + Ok(res) + } + Err(err) => Err(error::ErrorInternalServerError(err)), + }, + } } } } @@ -338,20 +332,18 @@ impl Inner { async fn clear_cache(&self, key: String) -> Result<(), Error> { let cachekey = (self.cache_keygen)(&key); - match self.addr - .send(Command(resp_array!["DEL", cachekey])) - .await { - Err(e) => Err(Error::from(e)), - Ok(res) => { - match res { - // redis responds with number of deleted records - Ok(RespValue::Integer(x)) if x > 0 => Ok(()), - _ => Err(error::ErrorInternalServerError( - "failed to remove session from cache", - )), - } + match self.addr.send(Command(resp_array!["DEL", cachekey])).await { + Err(e) => Err(Error::from(e)), + Ok(res) => { + match res { + // redis responds with number of deleted records + Ok(RespValue::Integer(x)) if x > 0 => Ok(()), + _ => Err(error::ErrorInternalServerError( + "failed to remove session from cache", + )), } } + } } /// invalidates session cookie