1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-03-21 12:21:58 +01:00

update actix; prep release

This commit is contained in:
Nikolay Kim 2019-12-20 22:09:08 +06:00
parent 8f97550c7a
commit 9b0a0f451b
4 changed files with 69 additions and 73 deletions

View File

@ -1,6 +1,10 @@
# Changes # 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 * Migrate to actix 0.9

View File

@ -1,6 +1,6 @@
[package] [package]
name = "actix-redis" name = "actix-redis"
version = "0.8.0-alpha.1" version = "0.8.0"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"] authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Redis integration for actix framework" description = "Redis integration for actix framework"
license = "MIT/Apache-2.0" 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"] web = ["actix/http", "actix-service", "actix-web", "actix-session/cookie-session", "rand", "serde", "serde_json"]
[dependencies] [dependencies]
actix = "0.9.0-alpha.2" actix = "0.9.0"
actix-utils = "1.0.3" actix-utils = "1.0.3"
log = "0.4.6" log = "0.4.6"
@ -38,13 +38,13 @@ futures = "0.3.1"
redis-async = "0.6.1" redis-async = "0.6.1"
actix-rt = "1.0.0" actix-rt = "1.0.0"
time = "0.1.42" time = "0.1.42"
tokio = "0.2.4" tokio = "0.2.6"
tokio-util = "0.2.0" tokio-util = "0.2.0"
# actix web session # 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-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 } rand = { version = "0.7.0", optional = true }
serde = { version = "1.0.101", optional = true, features = ["derive"] } serde = { version = "1.0.101", optional = true, features = ["derive"] }
serde_json = { version = "1.0.40", optional = true } serde_json = { version = "1.0.40", optional = true }

View File

@ -139,7 +139,7 @@ impl Handler<Command> for RedisActor {
let _ = tx.send(Err(Error::NotConnected)); let _ = tx.send(Err(Error::NotConnected));
} }
Box::new(rx.map(|res| match res { Box::pin(rx.map(|res| match res {
Ok(res) => res, Ok(res) => res,
Err(_) => Err(Error::Disconnected), Err(_) => Err(Error::Disconnected),
})) }))

View File

@ -210,8 +210,7 @@ impl Inner {
async fn load( async fn load(
&self, &self,
req: &ServiceRequest, req: &ServiceRequest,
) -> Result<Option<(HashMap<String, String>, String)>, Error> ) -> Result<Option<(HashMap<String, String>, String)>, Error> {
{
if let Ok(cookies) = req.cookies() { if let Ok(cookies) = req.cookies() {
for cookie in cookies.iter() { for cookie in cookies.iter() {
if cookie.name() == self.name { if cookie.name() == self.name {
@ -220,31 +219,27 @@ impl Inner {
if let Some(cookie) = jar.signed(&self.key).get(&self.name) { if let Some(cookie) = jar.signed(&self.key).get(&self.name) {
let value = cookie.value().to_owned(); let value = cookie.value().to_owned();
let cachekey = (self.cache_keygen)(&cookie.value()); let cachekey = (self.cache_keygen)(&cookie.value());
return return match self
match self.addr.send(Command(resp_array!["GET", cachekey])) .addr
.await { .send(Command(resp_array!["GET", cachekey]))
.await
{
Err(e) => Err(Error::from(e)), Err(e) => Err(Error::from(e)),
Ok(res) => match res { Ok(res) => match res {
Ok(val) => { Ok(val) => {
match val { match val {
RespValue::Error(err) => { RespValue::Error(err) => {
return Err( return Err(
error::ErrorInternalServerError( error::ErrorInternalServerError(err),
err,
),
); );
} }
RespValue::SimpleString(s) => { RespValue::SimpleString(s) => {
if let Ok(val) = if let Ok(val) = serde_json::from_str(&s) {
serde_json::from_str(&s)
{
return Ok(Some((val, value))); return Ok(Some((val, value)));
} }
} }
RespValue::BulkString(s) => { RespValue::BulkString(s) => {
if let Ok(val) = if let Ok(val) = serde_json::from_slice(&s) {
serde_json::from_slice(&s)
{
return Ok(Some((val, value))); return Ok(Some((val, value)));
} }
} }
@ -252,13 +247,11 @@ impl Inner {
} }
Ok(None) Ok(None)
} }
Err(err) => { Err(err) => Err(error::ErrorInternalServerError(err)),
Err(error::ErrorInternalServerError(err))
}
}, },
} };
} else { } else {
return Ok(None) return Ok(None);
} }
} }
} }
@ -311,9 +304,11 @@ impl Inner {
match serde_json::to_string(&state) { match serde_json::to_string(&state) {
Err(e) => Err(e.into()), Err(e) => Err(e.into()),
Ok(body) => { Ok(body) => {
match self.addr match self
.addr
.send(Command(resp_array!["SET", cachekey, body, "EX", &self.ttl])) .send(Command(resp_array!["SET", cachekey, body, "EX", &self.ttl]))
.await { .await
{
Err(e) => Err(Error::from(e)), Err(e) => Err(Error::from(e)),
Ok(redis_result) => match redis_result { Ok(redis_result) => match redis_result {
Ok(_) => { Ok(_) => {
@ -321,8 +316,7 @@ impl Inner {
for cookie in jar.delta() { for cookie in jar.delta() {
let val = let val =
HeaderValue::from_str(&cookie.to_string())?; HeaderValue::from_str(&cookie.to_string())?;
res.headers_mut() res.headers_mut().append(header::SET_COOKIE, val);
.append(header::SET_COOKIE, val);
} }
} }
Ok(res) Ok(res)
@ -338,9 +332,7 @@ impl Inner {
async fn clear_cache(&self, key: String) -> Result<(), Error> { async fn clear_cache(&self, key: String) -> Result<(), Error> {
let cachekey = (self.cache_keygen)(&key); let cachekey = (self.cache_keygen)(&key);
match self.addr match self.addr.send(Command(resp_array!["DEL", cachekey])).await {
.send(Command(resp_array!["DEL", cachekey]))
.await {
Err(e) => Err(Error::from(e)), Err(e) => Err(Error::from(e)),
Ok(res) => { Ok(res) => {
match res { match res {