mirror of
https://github.com/actix/examples
synced 2024-11-23 22:41:07 +01:00
update example redis-session (#545)
Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
parent
b6255d1637
commit
5c9f69bb07
349
Cargo.lock
generated
349
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,12 +1,11 @@
|
||||
[package]
|
||||
name = "redis_session"
|
||||
name = "redis-session-example"
|
||||
version = "1.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "4"
|
||||
actix-session = "0.5"
|
||||
actix-redis = "0.10"
|
||||
actix-session = { version = "0.7", features = ["redis-actor-session"] }
|
||||
|
||||
env_logger = "0.9"
|
||||
log = "0.4"
|
||||
|
@ -4,8 +4,7 @@
|
||||
//! At login, the session key changes and session state in cache re-assigns.
|
||||
//! At logout, session state in cache is removed and cookie is invalidated.
|
||||
//!
|
||||
use actix_redis::RedisSession;
|
||||
use actix_session::Session;
|
||||
use actix_session::{storage::RedisActorSessionStore, Session, SessionMiddleware};
|
||||
use actix_web::{
|
||||
middleware, web,
|
||||
web::{get, post, resource},
|
||||
@ -85,7 +84,13 @@ async fn main() -> std::io::Result<()> {
|
||||
HttpServer::new(move || {
|
||||
App::new()
|
||||
// redis session middleware
|
||||
.wrap(RedisSession::new("127.0.0.1:6379", private_key.master()))
|
||||
.wrap(
|
||||
SessionMiddleware::builder(
|
||||
RedisActorSessionStore::new("127.0.0.1:6379"),
|
||||
private_key.clone(),
|
||||
)
|
||||
.build(),
|
||||
)
|
||||
// enable logger - always register Actix Web Logger middleware last
|
||||
.wrap(middleware::Logger::default())
|
||||
.service(resource("/").route(get().to(index)))
|
||||
@ -115,8 +120,12 @@ mod test {
|
||||
let srv = actix_test::start(move || {
|
||||
App::new()
|
||||
.wrap(
|
||||
RedisSession::new("127.0.0.1:6379", private_key.master())
|
||||
.cookie_name("test-session"),
|
||||
SessionMiddleware::builder(
|
||||
RedisActorSessionStore::new("127.0.0.1:6379"),
|
||||
private_key.clone(),
|
||||
)
|
||||
.cookie_name("test-session".to_string())
|
||||
.build(),
|
||||
)
|
||||
.wrap(middleware::Logger::default())
|
||||
.service(resource("/").route(get().to(index)))
|
||||
|
Loading…
Reference in New Issue
Block a user