mirror of
https://github.com/actix/actix-extras.git
synced 2025-03-20 20:05:18 +01:00
update actix; prep release
This commit is contained in:
parent
8f97550c7a
commit
9b0a0f451b
@ -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
|
||||||
|
|
||||||
|
10
Cargo.toml
10
Cargo.toml
@ -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 }
|
||||||
|
@ -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),
|
||||||
}))
|
}))
|
||||||
|
124
src/session.rs
124
src/session.rs
@ -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,45 +219,39 @@ 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]))
|
||||||
Err(e) => Err(Error::from(e)),
|
.await
|
||||||
Ok(res) => match res {
|
{
|
||||||
Ok(val) => {
|
Err(e) => Err(Error::from(e)),
|
||||||
match val {
|
Ok(res) => match res {
|
||||||
RespValue::Error(err) => {
|
Ok(val) => {
|
||||||
return Err(
|
match val {
|
||||||
error::ErrorInternalServerError(
|
RespValue::Error(err) => {
|
||||||
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)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
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) => {
|
Ok(None)
|
||||||
Err(error::ErrorInternalServerError(err))
|
}
|
||||||
}
|
Err(err) => Err(error::ErrorInternalServerError(err)),
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
} else {
|
} else {
|
||||||
return Ok(None)
|
return Ok(None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -311,25 +304,26 @@ 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)),
|
{
|
||||||
Ok(redis_result) => match redis_result {
|
Err(e) => Err(Error::from(e)),
|
||||||
Ok(_) => {
|
Ok(redis_result) => match redis_result {
|
||||||
if let Some(jar) = jar {
|
Ok(_) => {
|
||||||
for cookie in jar.delta() {
|
if let Some(jar) = jar {
|
||||||
let val =
|
for cookie in jar.delta() {
|
||||||
HeaderValue::from_str(&cookie.to_string())?;
|
let val =
|
||||||
res.headers_mut()
|
HeaderValue::from_str(&cookie.to_string())?;
|
||||||
.append(header::SET_COOKIE, val);
|
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> {
|
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]))
|
Err(e) => Err(Error::from(e)),
|
||||||
.await {
|
Ok(res) => {
|
||||||
Err(e) => Err(Error::from(e)),
|
match res {
|
||||||
Ok(res) => {
|
// redis responds with number of deleted records
|
||||||
match res {
|
Ok(RespValue::Integer(x)) if x > 0 => Ok(()),
|
||||||
// redis responds with number of deleted records
|
_ => Err(error::ErrorInternalServerError(
|
||||||
Ok(RespValue::Integer(x)) if x > 0 => Ok(()),
|
"failed to remove session from cache",
|
||||||
_ => Err(error::ErrorInternalServerError(
|
)),
|
||||||
"failed to remove session from cache",
|
|
||||||
)),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// invalidates session cookie
|
/// invalidates session cookie
|
||||||
|
Loading…
x
Reference in New Issue
Block a user