pub struct RedisActorSessionStore { /* private fields */ }
Expand description

Use Redis as session storage backend.

use actix_web::{web, App, HttpServer, HttpResponse, Error};
use actix_session::{SessionMiddleware, storage::RedisActorSessionStore};
use actix_web::cookie::Key;

// The secret key would usually be read from a configuration file/environment variables.
fn get_secret_key() -> Key {
    // [...]
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    let secret_key = get_secret_key();
    let redis_connection_string = "127.0.0.1:6379";
    HttpServer::new(move ||
            App::new()
            .wrap(
                SessionMiddleware::new(
                    RedisActorSessionStore::new(redis_connection_string),
                    secret_key.clone()
                )
            )
            .default_service(web::to(|| HttpResponse::Ok())))
        .bind(("127.0.0.1", 8080))?
        .run()
        .await
}

Implementation notes

RedisActorSessionStore leverages actix-redis’s RedisActor implementation - each thread worker gets its own connection to Redis.

Limitations

RedisActorSessionStore does not currently support establishing authenticated connections to Redis. Use RedisSessionStore if you need TLS support.

Implementations

A fluent API to configure RedisActorSessionStore.

It takes as input the only required input to create a new instance of RedisActorSessionStore—a connection string for Redis.

Create a new instance of RedisActorSessionStore using the default configuration. It takes as input the only required input to create a new instance of RedisActorSessionStore - a connection string for Redis.

Trait Implementations

Loads the session state associated to a session key.
Persist the session state for a newly created session. Read more
Updates the session state associated to a pre-existing session key.
Updates the TTL of the session state associated to a pre-existing session key.
Deletes a session from the store.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more