[−][src]Struct actix_redis::Command
pub struct Command(pub RespValue);
Command for send data to Redis
Trait Implementations
impl Debug for Command
[src]
fn fmt(&self, f: &mut Formatter<'_>) -> Result
[src]
Formats the value using the given formatter. Read more
-impl Handler<Command> for RedisActor
[src]
type Result = ResponseFuture<Result<RespValue, Error>>
The type of value that this handler will return. Read more
-fn handle(&mut self, msg: Command, _: &mut Self::Context) -> Self::Result
[src]
This method is called for every message received by this actor.
+impl Handler<Command> for RedisActor
[src]
type Result = ResponseFuture<Result<RespValue, Error>>
The type of value that this handler will return. Read more
+fn handle(&mut self, msg: Command, _: &mut Self::Context) -> Self::Result
[src]
This method is called for every message received by this actor.
impl Message for Command
[src]
Auto Trait Implementations
impl RefUnwindSafe for Command
impl Send for Command
impl Sync for Command
impl Unpin for Command
impl UnwindSafe for Command
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
[src]
Gets the TypeId
of self
. Read more
[−][src]Struct actix_redis::RedisActor
pub struct RedisActor { /* fields omitted */ }
Redis comminucation actor
-Implementations
impl RedisActor
[src]
pub fn start<S: Into<String>>(addr: S) -> Addr<RedisActor>
[src]
Start new Supervisor
with RedisActor
.
Trait Implementations
impl Actor for RedisActor
[src]
type Context = Context<Self>
Actor execution context type
-fn started(&mut self, ctx: &mut Context<Self>)
[src]
Called when an actor gets polled the first time.
+Implementations
impl RedisActor
[src]
pub fn start<S: Into<String>>(addr: S) -> Addr<RedisActor>
[src]
Start new Supervisor
with RedisActor
.
Trait Implementations
impl Actor for RedisActor
[src]
type Context = Context<Self>
Actor execution context type
+fn started(&mut self, ctx: &mut Context<Self>)
[src]
Called when an actor gets polled the first time.
fn stopping(&mut self, ctx: &mut Self::Context) -> Running
Called after an actor is in Actor::Stopping
state. Read more
fn stopped(&mut self, ctx: &mut Self::Context)
Called after an actor is stopped. Read more
fn start(self) -> Addr<Self> where
Self: Actor<Context = Context<Self>>,
Self: Actor<Context = Context<Self>>,
Start a new asynchronous actor, returning its address. Read more
@@ -12,15 +12,15 @@ address. Read morefn start_in_arbiter<F>(arb: &Arbiter, f: F) -> Addr<Self> where
F: FnOnce(&mut Context<Self>) -> Self + Send + 'static,
Self: Actor<Context = Context<Self>>,
F: FnOnce(&mut Context<Self>) -> Self + Send + 'static,
Self: Actor<Context = Context<Self>>,
Start new actor in arbiter's thread.
fn create<F>(f: F) -> Addr<Self> where
F: FnOnce(&mut Context<Self>) -> Self,
Self: Actor<Context = Context<Self>>,
F: FnOnce(&mut Context<Self>) -> Self,
Self: Actor<Context = Context<Self>>,
Start a new asynchronous actor given a Context
. Read more
impl Handler<Command> for RedisActor
[src]
type Result = ResponseFuture<Result<RespValue, Error>>
The type of value that this handler will return. Read more
-fn handle(&mut self, msg: Command, _: &mut Self::Context) -> Self::Result
[src]
This method is called for every message received by this actor.
-impl StreamHandler<Result<RespValue, Error>> for RedisActor
[src]
fn handle(&mut self, msg: Result<RespValue, RespError>, ctx: &mut Self::Context)
[src]
Method is called for every message received by this Actor
+impl Handler<Command> for RedisActor
[src]
type Result = ResponseFuture<Result<RespValue, Error>>
The type of value that this handler will return. Read more
+fn handle(&mut self, msg: Command, _: &mut Self::Context) -> Self::Result
[src]
This method is called for every message received by this actor.
+impl StreamHandler<Result<RespValue, Error>> for RedisActor
[src]
fn handle(&mut self, msg: Result<RespValue, RespError>, ctx: &mut Self::Context)
[src]
Method is called for every message received by this Actor
fn started(&mut self, ctx: &mut Self::Context)
Method is called when stream get polled first time.
fn finished(&mut self, ctx: &mut Self::Context)
Method is called when stream finishes. Read more
fn add_stream<S>(fut: S, ctx: &mut Self::Context) -> SpawnHandle where
I: 'static,
S: Stream<Item = I> + 'static,
Self::Context: AsyncContext<Self>,
I: 'static,
S: Stream<Item = I> + 'static,
Self::Context: AsyncContext<Self>,
This method register stream to an actor context and
allows to handle Stream
in similar way as normal actor messages. Read more
impl Supervised for RedisActor
[src]
fn restarting(&mut self, _: &mut Self::Context)
[src]
Called when the supervisor restarts a failed actor.
-impl WriteHandler<Error> for RedisActor
[src]
fn error(&mut self, err: Error, _: &mut Self::Context) -> Running
[src]
Called when the writer emits error. Read more
+impl Supervised for RedisActor
[src]
fn restarting(&mut self, _: &mut Self::Context)
[src]
Called when the supervisor restarts a failed actor.
+impl WriteHandler<Error> for RedisActor
[src]
Auto Trait Implementations
impl !RefUnwindSafe for RedisActor
impl !Send for RedisActor
impl !Sync for RedisActor
impl Unpin for RedisActor
impl !UnwindSafe for RedisActor
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow(&self) -> &T
[src]
Immutably borrows from an owned value. Read more
diff --git a/search-index.js b/search-index.js index 0ce8bf97c..62f3c9fe2 100644 --- a/search-index.js +++ b/search-index.js @@ -1,4 +1,4 @@ var searchIndex = JSON.parse('{\ -"actix_redis":{"doc":"Redis integration for Actix framework.","i":[[4,"SameSite","actix_redis","The `SameSite` cookie attribute.",null,null],[13,"Strict","","The \\\"Strict\\\" `SameSite` attribute.",0,null],[13,"Lax","","The \\\"Lax\\\" `SameSite` attribute.",0,null],[13,"None","","The \\\"None\\\" `SameSite` attribute.",0,null],[4,"RespError","","",null,null],[13,"Internal","","A non-specific internal error that prevented an operation…",1,null],[13,"IO","","An IO error occurred",1,null],[13,"RESP","","A RESP parsing/serialising error occurred",1,null],[13,"Remote","","A remote error",1,null],[13,"Connection","","Error creating a connection, or an error with a connection…",1,null],[13,"Unexpected","","An unexpected error. In this context \\\"unexpected\\\" means…",1,null],[4,"RespValue","","A single RESP value, this owns the data that is read/to-be…",null,null],[13,"Nil","","",2,null],[13,"Array","","Zero, one or more other `RespValue`s.",2,null],[13,"BulkString","","A bulk string. In Redis terminology a string is a…",2,null],[13,"Error","","An error from the Redis server",2,null],[13,"Integer","","Redis documentation defines an integer as being a signed…",2,null],[13,"SimpleString","","",2,null],[3,"Command","","Command for send data to Redis",null,null],[12,"0","","",3,null],[3,"RedisActor","","Redis comminucation actor",null,null],[3,"RedisSession","","Use redis as session storage.",null,null],[4,"Error","","General purpose actix redis error",null,null],[13,"Redis","","",4,null],[13,"NotConnected","","Receiving message during reconnecting",4,null],[13,"Disconnected","","Cancel all waters when connection get dropped",4,null],[11,"start","","Start new `Supervisor` with `RedisActor`.",5,[[["into",8],["string",3]],[["redisactor",3],["addr",3]]]],[11,"new","","Create new redis session backend",6,[[["into",8],["string",3]],["redissession",3]]],[11,"ttl","","Set time to live in seconds for session value",6,[[]]],[11,"cookie_name","","Set custom cookie name for session id",6,[[]]],[11,"cookie_path","","Set custom cookie path",6,[[]]],[11,"cookie_domain","","Set custom cookie domain",6,[[]]],[11,"cookie_secure","","Set custom cookie secure If the `secure` field is set, a…",6,[[]]],[11,"cookie_max_age","","Set custom cookie max-age",6,[[["duration",3]]]],[11,"cookie_same_site","","Set custom cookie SameSite",6,[[["samesite",4]]]],[11,"cookie_http_only","","Set custom cookie HttpOnly policy",6,[[]]],[11,"cache_keygen","","Set a custom cache key generation strategy, expecting…",6,[[["box",3],["fn",8]]]],[11,"from","","",0,[[]]],[11,"into","","",0,[[]]],[11,"to_owned","","",0,[[]]],[11,"clone_into","","",0,[[]]],[11,"to_string","","",0,[[],["string",3]]],[11,"borrow","","",0,[[]]],[11,"borrow_mut","","",0,[[]]],[11,"try_from","","",0,[[],["result",4]]],[11,"try_into","","",0,[[],["result",4]]],[11,"type_id","","",0,[[],["typeid",3]]],[11,"vzip","","",0,[[]]],[11,"equivalent","","",0,[[]]],[11,"from","","",1,[[]]],[11,"into","","",1,[[]]],[11,"to_string","","",1,[[],["string",3]]],[11,"borrow","","",1,[[]]],[11,"borrow_mut","","",1,[[]]],[11,"try_from","","",1,[[],["result",4]]],[11,"try_into","","",1,[[],["result",4]]],[11,"type_id","","",1,[[],["typeid",3]]],[11,"vzip","","",1,[[]]],[11,"from","","",2,[[]]],[11,"into","","",2,[[]]],[11,"to_owned","","",2,[[]]],[11,"clone_into","","",2,[[]]],[11,"borrow","","",2,[[]]],[11,"borrow_mut","","",2,[[]]],[11,"try_from","","",2,[[],["result",4]]],[11,"try_into","","",2,[[],["result",4]]],[11,"type_id","","",2,[[],["typeid",3]]],[11,"vzip","","",2,[[]]],[11,"equivalent","","",2,[[]]],[11,"from","","",3,[[]]],[11,"into","","",3,[[]]],[11,"borrow","","",3,[[]]],[11,"borrow_mut","","",3,[[]]],[11,"try_from","","",3,[[],["result",4]]],[11,"try_into","","",3,[[],["result",4]]],[11,"type_id","","",3,[[],["typeid",3]]],[11,"vzip","","",3,[[]]],[11,"from","","",5,[[]]],[11,"into","","",5,[[]]],[11,"borrow","","",5,[[]]],[11,"borrow_mut","","",5,[[]]],[11,"try_from","","",5,[[],["result",4]]],[11,"try_into","","",5,[[],["result",4]]],[11,"type_id","","",5,[[],["typeid",3]]],[11,"vzip","","",5,[[]]],[11,"from","","",6,[[]]],[11,"into","","",6,[[]]],[11,"borrow","","",6,[[]]],[11,"borrow_mut","","",6,[[]]],[11,"try_from","","",6,[[],["result",4]]],[11,"try_into","","",6,[[],["result",4]]],[11,"type_id","","",6,[[],["typeid",3]]],[11,"vzip","","",6,[[]]],[11,"from","","",4,[[]]],[11,"into","","",4,[[]]],[11,"to_string","","",4,[[],["string",3]]],[11,"borrow","","",4,[[]]],[11,"borrow_mut","","",4,[[]]],[11,"try_from","","",4,[[],["result",4]]],[11,"try_into","","",4,[[],["result",4]]],[11,"type_id","","",4,[[],["typeid",3]]],[11,"vzip","","",4,[[]]],[11,"from","","",2,[[],["respvalue",4]]],[11,"from","","",1,[[["error",3]],["error",4]]],[11,"from","","",1,[[["trysenderror",3]],["error",4]]],[11,"from","","",2,[[["string",3]],["respvalue",4]]],[11,"from","","",2,[[],["respvalue",4]]],[11,"from","","",2,[[["string",3]],["respvalue",4]]],[11,"from","","",2,[[["vec",3]],["respvalue",4]]],[11,"from","","",2,[[],["respvalue",4]]],[11,"fmt","","",1,[[["formatter",3]],[["result",4],["error",3]]]],[11,"eq","","",2,[[["respvalue",4]]]],[11,"ne","","",2,[[["respvalue",4]]]],[11,"clone","","",2,[[],["respvalue",4]]],[11,"from_resp_int","","",2,[[["respvalue",4]],[["result",4],["respvalue",4],["error",4]]]],[11,"source","","",1,[[],[["option",4],["error",8]]]],[11,"fmt","","",2,[[["formatter",3]],[["result",4],["error",3]]]],[11,"fmt","","",1,[[["formatter",3]],[["result",4],["error",3]]]],[11,"hash","","",0,[[]]],[11,"fmt","","",0,[[["formatter",3]],[["result",4],["error",3]]]],[11,"eq","","",0,[[["samesite",4]]]],[11,"clone","","",0,[[],["samesite",4]]],[11,"fmt","","",0,[[["formatter",3]],[["result",4],["error",3]]]],[11,"from","","",4,[[["error",4]],["error",4]]],[11,"fmt","","",3,[[["formatter",3]],["result",6]]],[11,"fmt","","",4,[[["formatter",3]],["result",6]]],[11,"fmt","","",4,[[["formatter",3]],["result",6]]],[11,"started","","",5,[[["context",3]]]],[11,"restarting","","",5,[[]]],[11,"handle","","",5,[[["command",3]]]],[11,"handle","","",5,[[["resperror",4],["respvalue",4],["result",4]]]],[11,"error","","",5,[[["error",3]],["running",4]]],[11,"new_transform","","",6,[[]]],[11,"is_strict","","Returns `true` if `self` is `SameSite::Strict` and `false`…",0,[[]]],[11,"is_lax","","Returns `true` if `self` is `SameSite::Lax` and `false`…",0,[[]]],[11,"is_none","","Returns `true` if `self` is `SameSite::None` and `false`…",0,[[]]],[11,"append","","Convenience function for building dynamic Redis commands…",2,[[],["respvalue",4]]]],"p":[[4,"SameSite"],[4,"RespError"],[4,"RespValue"],[3,"Command"],[4,"Error"],[3,"RedisActor"],[3,"RedisSession"]]}\ +"actix_redis":{"doc":"Redis integration for Actix framework.","i":[[4,"SameSite","actix_redis","The `SameSite` cookie attribute.",null,null],[13,"Strict","","The \\\"Strict\\\" `SameSite` attribute.",0,null],[13,"Lax","","The \\\"Lax\\\" `SameSite` attribute.",0,null],[13,"None","","The \\\"None\\\" `SameSite` attribute.",0,null],[4,"RespError","","",null,null],[13,"Internal","","A non-specific internal error that prevented an operation…",1,null],[13,"IO","","An IO error occurred",1,null],[13,"RESP","","A RESP parsing/serialising error occurred",1,null],[13,"Remote","","A remote error",1,null],[13,"Connection","","Error creating a connection, or an error with a connection…",1,null],[13,"Unexpected","","An unexpected error. In this context \\\"unexpected\\\" means…",1,null],[4,"RespValue","","A single RESP value, this owns the data that is read/to-be…",null,null],[13,"Nil","","",2,null],[13,"Array","","Zero, one or more other `RespValue`s.",2,null],[13,"BulkString","","A bulk string. In Redis terminology a string is a…",2,null],[13,"Error","","An error from the Redis server",2,null],[13,"Integer","","Redis documentation defines an integer as being a signed…",2,null],[13,"SimpleString","","",2,null],[3,"Command","","Command for send data to Redis",null,null],[12,"0","","",3,null],[3,"RedisActor","","Redis comminucation actor",null,null],[3,"RedisSession","","Use redis as session storage.",null,null],[4,"Error","","General purpose actix redis error",null,null],[13,"Redis","","",4,null],[13,"NotConnected","","Receiving message during reconnecting",4,null],[13,"Disconnected","","Cancel all waters when connection get dropped",4,null],[11,"start","","Start new `Supervisor` with `RedisActor`.",5,[[["into",8],["string",3]],[["redisactor",3],["addr",3]]]],[11,"new","","Create new redis session backend",6,[[["into",8],["string",3]],["redissession",3]]],[11,"ttl","","Set time to live in seconds for session value",6,[[]]],[11,"cookie_name","","Set custom cookie name for session id",6,[[]]],[11,"cookie_path","","Set custom cookie path",6,[[]]],[11,"cookie_domain","","Set custom cookie domain",6,[[]]],[11,"cookie_secure","","Set custom cookie secure If the `secure` field is set, a…",6,[[]]],[11,"cookie_max_age","","Set custom cookie max-age",6,[[["duration",3]]]],[11,"cookie_same_site","","Set custom cookie SameSite",6,[[["samesite",4]]]],[11,"cookie_http_only","","Set custom cookie HttpOnly policy",6,[[]]],[11,"cache_keygen","","Set a custom cache key generation strategy, expecting…",6,[[["box",3],["fn",8]]]],[11,"from","","",0,[[]]],[11,"into","","",0,[[]]],[11,"to_owned","","",0,[[]]],[11,"clone_into","","",0,[[]]],[11,"to_string","","",0,[[],["string",3]]],[11,"borrow","","",0,[[]]],[11,"borrow_mut","","",0,[[]]],[11,"try_from","","",0,[[],["result",4]]],[11,"try_into","","",0,[[],["result",4]]],[11,"type_id","","",0,[[],["typeid",3]]],[11,"vzip","","",0,[[]]],[11,"equivalent","","",0,[[]]],[11,"from","","",1,[[]]],[11,"into","","",1,[[]]],[11,"to_string","","",1,[[],["string",3]]],[11,"borrow","","",1,[[]]],[11,"borrow_mut","","",1,[[]]],[11,"try_from","","",1,[[],["result",4]]],[11,"try_into","","",1,[[],["result",4]]],[11,"type_id","","",1,[[],["typeid",3]]],[11,"vzip","","",1,[[]]],[11,"from","","",2,[[]]],[11,"into","","",2,[[]]],[11,"to_owned","","",2,[[]]],[11,"clone_into","","",2,[[]]],[11,"borrow","","",2,[[]]],[11,"borrow_mut","","",2,[[]]],[11,"try_from","","",2,[[],["result",4]]],[11,"try_into","","",2,[[],["result",4]]],[11,"type_id","","",2,[[],["typeid",3]]],[11,"vzip","","",2,[[]]],[11,"equivalent","","",2,[[]]],[11,"from","","",3,[[]]],[11,"into","","",3,[[]]],[11,"borrow","","",3,[[]]],[11,"borrow_mut","","",3,[[]]],[11,"try_from","","",3,[[],["result",4]]],[11,"try_into","","",3,[[],["result",4]]],[11,"type_id","","",3,[[],["typeid",3]]],[11,"vzip","","",3,[[]]],[11,"from","","",5,[[]]],[11,"into","","",5,[[]]],[11,"borrow","","",5,[[]]],[11,"borrow_mut","","",5,[[]]],[11,"try_from","","",5,[[],["result",4]]],[11,"try_into","","",5,[[],["result",4]]],[11,"type_id","","",5,[[],["typeid",3]]],[11,"vzip","","",5,[[]]],[11,"from","","",6,[[]]],[11,"into","","",6,[[]]],[11,"borrow","","",6,[[]]],[11,"borrow_mut","","",6,[[]]],[11,"try_from","","",6,[[],["result",4]]],[11,"try_into","","",6,[[],["result",4]]],[11,"type_id","","",6,[[],["typeid",3]]],[11,"vzip","","",6,[[]]],[11,"from","","",4,[[]]],[11,"into","","",4,[[]]],[11,"to_string","","",4,[[],["string",3]]],[11,"borrow","","",4,[[]]],[11,"borrow_mut","","",4,[[]]],[11,"try_from","","",4,[[],["result",4]]],[11,"try_into","","",4,[[],["result",4]]],[11,"type_id","","",4,[[],["typeid",3]]],[11,"vzip","","",4,[[]]],[11,"from","","",1,[[["trysenderror",3]],["error",4]]],[11,"from","","",2,[[["string",3]],["respvalue",4]]],[11,"from","","",2,[[],["respvalue",4]]],[11,"from","","",1,[[["error",3]],["error",4]]],[11,"from","","",2,[[["string",3]],["respvalue",4]]],[11,"from","","",2,[[],["respvalue",4]]],[11,"from","","",2,[[["vec",3]],["respvalue",4]]],[11,"from","","",2,[[],["respvalue",4]]],[11,"fmt","","",1,[[["formatter",3]],[["result",4],["error",3]]]],[11,"eq","","",2,[[["respvalue",4]]]],[11,"ne","","",2,[[["respvalue",4]]]],[11,"clone","","",2,[[],["respvalue",4]]],[11,"from_resp_int","","",2,[[["respvalue",4]],[["result",4],["respvalue",4],["error",4]]]],[11,"source","","",1,[[],[["option",4],["error",8]]]],[11,"fmt","","",1,[[["formatter",3]],[["result",4],["error",3]]]],[11,"fmt","","",2,[[["formatter",3]],[["result",4],["error",3]]]],[11,"hash","","",0,[[]]],[11,"fmt","","",0,[[["formatter",3]],[["result",4],["error",3]]]],[11,"eq","","",0,[[["samesite",4]]]],[11,"clone","","",0,[[],["samesite",4]]],[11,"fmt","","",0,[[["formatter",3]],[["result",4],["error",3]]]],[11,"from","","",4,[[["error",4]],["error",4]]],[11,"fmt","","",3,[[["formatter",3]],["result",6]]],[11,"fmt","","",4,[[["formatter",3]],["result",6]]],[11,"fmt","","",4,[[["formatter",3]],["result",6]]],[11,"started","","",5,[[["context",3]]]],[11,"restarting","","",5,[[]]],[11,"handle","","",5,[[["command",3]]]],[11,"handle","","",5,[[["resperror",4],["respvalue",4],["result",4]]]],[11,"error","","",5,[[["error",3]],["running",4]]],[11,"new_transform","","",6,[[]]],[11,"is_strict","","Returns `true` if `self` is `SameSite::Strict` and `false`…",0,[[]]],[11,"is_lax","","Returns `true` if `self` is `SameSite::Lax` and `false`…",0,[[]]],[11,"is_none","","Returns `true` if `self` is `SameSite::None` and `false`…",0,[[]]],[11,"append","","Convenience function for building dynamic Redis commands…",2,[[],["respvalue",4]]]],"p":[[4,"SameSite"],[4,"RespError"],[4,"RespValue"],[3,"Command"],[4,"Error"],[3,"RedisActor"],[3,"RedisSession"]]}\ }'); addSearchOptions(searchIndex);initSearch(searchIndex); \ No newline at end of file diff --git a/src/actix_redis/redis.rs.html b/src/actix_redis/redis.rs.html index fd809c6ca..2f6fca1b7 100644 --- a/src/actix_redis/redis.rs.html +++ b/src/actix_redis/redis.rs.html @@ -149,6 +149,8 @@ 146 147 148 +149 +150use std::collections::VecDeque; use std::io; @@ -189,8 +191,10 @@ pub fn start<S: Into<String>>(addr: S) -> Addr<RedisActor> { let addr = addr.into(); - let mut backoff = ExponentialBackoff::default(); - backoff.max_elapsed_time = None; + let backoff = ExponentialBackoff { + max_elapsed_time: None, + ..Default::default() + }; Supervisor::start(|_| RedisActor { addr, diff --git a/src/actix_redis/session.rs.html b/src/actix_redis/session.rs.html index 029303c3a..b2b8f1f5b 100644 --- a/src/actix_redis/session.rs.html +++ b/src/actix_redis/session.rs.html @@ -670,6 +670,7 @@ 667 668 669 +670
use std::cell::RefCell; use std::pin::Pin; @@ -894,51 +895,56 @@ &self, req: &ServiceRequest, ) -> Result<Option<(HashMap<String, String>, String)>, Error> { - if let Ok(cookies) = req.cookies() { - for cookie in cookies.iter() { - if cookie.name() == self.name { - let mut jar = CookieJar::new(); - jar.add_original(cookie.clone()); - 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))); - } - } - _ => (), - } - Ok(None) - } - Err(err) => Err(error::ErrorInternalServerError(err)), - }, - }; - } else { - return Ok(None); - } + // wrapped in block to avoid holding `Ref` (from `req.cookies`) across await point + let (value, cache_key) = { + let cookies = if let Ok(cookies) = req.cookies() { + cookies + } else { + return Ok(None); + }; + + if let Some(cookie) = + cookies.iter().find(|&cookie| cookie.name() == self.name) + { + let mut jar = CookieJar::new(); + jar.add_original(cookie.clone()); + + if let Some(cookie) = jar.signed(&self.key).get(&self.name) { + let value = cookie.value().to_owned(); + let cache_key = (self.cache_keygen)(&cookie.value()); + (value, cache_key) + } else { + return Ok(None); + } + } else { + return Ok(None); + } + }; + + let res = self + .addr + .send(Command(resp_array!["GET", cache_key])) + .await?; + + let val = res.map_err(error::ErrorInternalServerError)?; + + 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))); + } + } + _ => {} } + Ok(None) } @@ -981,41 +987,37 @@ (value, Some(jar)) }; - let cachekey = (self.cache_keygen)(&value); + let cache_key = (self.cache_keygen)(&value); let state: HashMap<_, _> = state.collect(); - match serde_json::to_string(&state) { - Err(e) => Err(e.into()), - Ok(body) => { - 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); - } - } - Ok(res) - } - Err(err) => Err(error::ErrorInternalServerError(err)), - }, - } + + let body = match serde_json::to_string(&state) { + Err(e) => return Err(e.into()), + Ok(body) => body, + }; + + let cmd = Command(resp_array!["SET", cache_key, body, "EX", &self.ttl]); + + self.addr + .send(cmd) + .await? + .map_err(error::ErrorInternalServerError)?; + + 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) } /// removes cache entry async fn clear_cache(&self, key: String) -> Result<(), Error> { - let cachekey = (self.cache_keygen)(&key); + let cache_key = (self.cache_keygen)(&key); - match self.addr.send(Command(resp_array!["DEL", cachekey])).await { + match self.addr.send(Command(resp_array!["DEL", cache_key])).await { Err(e) => Err(Error::from(e)), Ok(res) => { match res { @@ -1118,7 +1120,7 @@ } #[actix_rt::test] - async fn test_workflow() { + async fn test_session_workflow() { // Step 1: GET index // - set-cookie actix-session will be in response (session cookie #1) // - response should be: {"counter": 0, "user_id": None}