From f250348e573aa67ac9be580037cdaf40648e4903 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Tue, 12 Mar 2024 23:30:06 +0000 Subject: [PATCH] chore: remove actix-redis crate (#408) --- .github/workflows/ci-post-merge.yml | 2 +- .github/workflows/ci.yml | 2 +- Cargo.toml | 2 - README.md | 2 - actix-redis/CHANGES.md | 154 ----------------------- actix-redis/Cargo.toml | 48 ------- actix-redis/LICENSE-APACHE | 1 - actix-redis/LICENSE-MIT | 1 - actix-redis/README.md | 18 --- actix-redis/src/lib.rs | 32 ----- actix-redis/src/redis.rs | 143 --------------------- actix-redis/tests/test_redis.rs | 42 ------- actix-session/CHANGES.md | 2 + actix-session/Cargo.toml | 12 +- actix-session/README.md | 8 -- actix-session/examples/authentication.rs | 20 +-- actix-session/examples/basic.rs | 10 +- actix-session/src/lib.rs | 9 -- actix-session/src/middleware.rs | 62 +++++---- actix-session/src/storage/mod.rs | 7 +- actix-session/src/storage/redis_rs.rs | 4 +- 21 files changed, 54 insertions(+), 527 deletions(-) delete mode 100644 actix-redis/CHANGES.md delete mode 100644 actix-redis/Cargo.toml delete mode 120000 actix-redis/LICENSE-APACHE delete mode 120000 actix-redis/LICENSE-MIT delete mode 100644 actix-redis/README.md delete mode 100644 actix-redis/src/lib.rs delete mode 100644 actix-redis/src/redis.rs delete mode 100644 actix-redis/tests/test_redis.rs diff --git a/.github/workflows/ci-post-merge.yml b/.github/workflows/ci-post-merge.yml index bd349de96..9cc3f8546 100644 --- a/.github/workflows/ci-post-merge.yml +++ b/.github/workflows/ci-post-merge.yml @@ -92,7 +92,7 @@ jobs: - name: tests timeout-minutes: 40 - run: cargo ci-test --exclude=actix-redis --exclude=actix-session --exclude=actix-limitation -- --nocapture + run: cargo ci-test --exclude=actix-session --exclude=actix-limitation -- --nocapture - name: CI cache clean run: cargo-ci-cache-clean diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 846a64eba..6c9462b58 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -118,7 +118,7 @@ jobs: - name: tests timeout-minutes: 40 - run: cargo ci-test --exclude=actix-redis --exclude=actix-session --exclude=actix-limitation + run: cargo ci-test --exclude=actix-session --exclude=actix-limitation - name: CI cache clean run: cargo-ci-cache-clean diff --git a/Cargo.toml b/Cargo.toml index b16e1fa3a..c26ec3660 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,6 @@ members = [ "actix-identity", "actix-limitation", "actix-protobuf", - "actix-redis", "actix-session", "actix-settings", "actix-web-httpauth", @@ -23,7 +22,6 @@ actix-cors = { path = "./actix-cors" } actix-identity = { path = "./actix-identity" } actix-limitation = { path = "./actix-limitation" } actix-protobuf = { path = "./actix-protobuf" } -actix-redis = { path = "./actix-redis" } actix-session = { path = "./actix-session" } actix-settings = { path = "./actix-settings" } actix-web-httpauth = { path = "./actix-web-httpauth" } diff --git a/README.md b/README.md index 2771e49c5..85e48ef7d 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,6 @@ | [actix-identity] | [![crates.io](https://img.shields.io/crates/v/actix-identity?label=latest)](https://crates.io/crates/actix-identity) [![dependency status](https://deps.rs/crate/actix-identity/latest/status.svg)](https://deps.rs/crate/actix-identity) | Identity management. | | [actix-limitation] | [![crates.io](https://img.shields.io/crates/v/actix-limitation?label=latest)](https://crates.io/crates/actix-limitation) [![dependency status](https://deps.rs/crate/actix-limitation/latest/status.svg)](https://deps.rs/crate/actix-limitation) | Rate-limiting using a fixed window counter for arbitrary keys, backed by Redis. | | [actix-protobuf] | [![crates.io](https://img.shields.io/crates/v/actix-protobuf?label=latest)](https://crates.io/crates/actix-protobuf) [![dependency status](https://deps.rs/crate/actix-protobuf/latest/status.svg)](https://deps.rs/crate/actix-protobuf) | Protobuf payload extractor. | -| [actix-redis] | [![crates.io](https://img.shields.io/crates/v/actix-redis?label=latest)](https://crates.io/crates/actix-redis) [![dependency status](https://deps.rs/crate/actix-redis/latest/status.svg)](https://deps.rs/crate/actix-redis) | Actor-based Redis client. | | [actix-session] | [![crates.io](https://img.shields.io/crates/v/actix-session?label=latest)](https://crates.io/crates/actix-session) [![dependency status](https://deps.rs/crate/actix-session/latest/status.svg)](https://deps.rs/crate/actix-session) | Session management. | | [actix-settings] | [![crates.io](https://img.shields.io/crates/v/actix-settings?label=latest)](https://crates.io/crates/actix-settings) [![dependency status](https://deps.rs/crate/actix-settings/latest/status.svg)](https://deps.rs/crate/actix-settings) | Easily manage Actix Web's settings from a TOML file and environment variables. | | [actix-web-httpauth] | [![crates.io](https://img.shields.io/crates/v/actix-web-httpauth?label=latest)](https://crates.io/crates/actix-web-httpauth) [![dependency status](https://deps.rs/crate/actix-web-httpauth/latest/status.svg)](https://deps.rs/crate/actix-web-httpauth) | HTTP authentication schemes. | @@ -62,7 +61,6 @@ To add a crate to this list, submit a pull request. [actix-identity]: ./actix-identity [actix-limitation]: ./actix-limitation [actix-protobuf]: ./actix-protobuf -[actix-redis]: ./actix-redis [actix-session]: ./actix-session [actix-settings]: ./actix-settings [actix-web-httpauth]: ./actix-web-httpauth diff --git a/actix-redis/CHANGES.md b/actix-redis/CHANGES.md deleted file mode 100644 index 672db04ab..000000000 --- a/actix-redis/CHANGES.md +++ /dev/null @@ -1,154 +0,0 @@ -# Changes - -## Unreleased - -- Minimum supported Rust version (MSRV) is now 1.75. - -## 0.13.0 - -- Update `redis-async` dependency to `0.16`. -- Minimum supported Rust version (MSRV) is now 1.68. - -## 0.12.0 - -- Update `actix` dependency to `0.13`. -- Update `redis-async` dependency to `0.13`. -- Update `tokio-util` dependency to `0.7`. -- Minimum supported Rust version (MSRV) is now 1.57 due to transitive `time` dependency. - -## 0.11.0 - -### Removed - -- `RedisSession` has been removed. Check out `RedisActorSessionStore` in `actix-session` for a session store backed by Redis using `actix-redis`. [#212] - -### Changed - -- Update `redis-async` dependency to `0.12`. [#212] - -[#212]: https://github.com/actix/actix-extras/pull/212 - -## 0.10.0 - -- Update `actix-web` dependency to `4`. - -## 0.10.0-beta.6 - -- Update `actix-web` dependency to `4.0.0-rc.1`. - -## 0.10.0-beta.5 - -- Update `actix-web` dependency to `4.0.0.beta-18`. [#218] -- Minimum supported Rust version (MSRV) is now 1.54. - -[#218]: https://github.com/actix/actix-extras/pull/218 - -## 0.10.0-beta.4 - -- A session will be created in Redis if and only if there is some data inside the session state. This reduces the performance impact of `RedisSession` on routes that do not leverage sessions. [#207] -- Update `actix-web` dependency to `4.0.0.beta-14`. [#209] - -[#207]: https://github.com/actix/actix-extras/pull/207 -[#209]: https://github.com/actix/actix-extras/pull/209 - -## 0.10.0-beta.3 - -- Update `actix-web` dependency to v4.0.0-beta.10. [#203] -- Minimum supported Rust version (MSRV) is now 1.52. - -[#203]: https://github.com/actix/actix-extras/pull/203 - -## 0.10.0-beta.2 - -- No notable changes. - -## 0.10.0-beta.1 - -- Update `actix-web` dependency to 4.0.0 beta. -- Minimum supported Rust version (MSRV) is now 1.46.0. - -## 0.9.2 - -- Implement `std::error::Error` for `Error` [#135] -- Allow the removal of `Max-Age` for session-only cookies. [#161] - -[#135]: https://github.com/actix/actix-extras/pull/135 -[#161]: https://github.com/actix/actix-extras/pull/161 - -## 0.9.1 - -- Enforce minimum redis-async version of 0.6.3 to workaround breaking patch change. - -## 0.9.0 - -- Update `actix-web` dependency to 3.0.0. -- Minimize `futures` dependency. - -## 0.9.0-alpha.2 - -- Add `cookie_http_only` functionality to RedisSession builder, setting this to false allows JavaScript to access cookies. Defaults to true. -- Change type of parameter of ttl method to u32. -- Update `actix` to 0.10.0-alpha.3 -- Update `tokio-util` to 0.3 -- Minimum supported Rust version(MSRV) is now 1.40.0. - -## 0.9.0-alpha.1 - -- Update `actix` to 0.10.0-alpha.2 -- Update `actix-session` to 0.4.0-alpha.1 -- Update `actix-web` to 3.0.0-alpha.1 -- Update `time` to 0.2.9 - -## 0.8.1 - -- Move `env_logger` dependency to dev-dependencies and update to 0.7 -- Update `actix_web` to 2.0.0 from 2.0.0-rc -- Move repository to actix-extras - -## 0.8.0 - 2019-12-20 - -- Release - -## 0.8.0-alpha.1 - 2019-12-16 - -- Migrate to actix 0.9 - -## 0.7.0 - 2019-09-25 - -- added cache_keygen functionality to RedisSession builder, enabling support for customizable cache key creation - -## 0.6.1 - 2019-07-19 - -- remove ClonableService usage -- added comprehensive tests for session workflow - -## 0.6.0 - 2019-07-08 - -- actix-web 1.0.0 compatibility -- Upgraded logic that evaluates session state, including new SessionStatus field, and introduced `session.renew()` and `session.purge()` functionality. Use `renew()` to cycle the session key at successful login. `renew()` keeps a session's state while replacing the old cookie and session key with new ones. Use `purge()` at logout to invalidate the session cookie and remove the session's redis cache entry. - -## 0.5.1 - 2018-08-02 - -- Use cookie 0.11 - -## 0.5.0 - 2018-07-21 - -- Session cookie configuration -- Actix/Actix-web 0.7 compatibility - -## 0.4.0 - 2018-05-08 - -- Actix web 0.6 compatibility - -## 0.3.0 - 2018-04-10 - -- Actix web 0.5 compatibility - -## 0.2.0 - 2018-02-28 - -- Use resolver actor from actix -- Use actix web 0.5 - -## 0.1.0 - 2018-01-23 - -- First release diff --git a/actix-redis/Cargo.toml b/actix-redis/Cargo.toml deleted file mode 100644 index 1507d3295..000000000 --- a/actix-redis/Cargo.toml +++ /dev/null @@ -1,48 +0,0 @@ -[package] -name = "actix-redis" -version = "0.13.0" -authors = ["Nikolay Kim "] -description = "Actor-based Redis client" -keywords = ["actix", "redis", "async"] -homepage = "https://actix.rs" -repository = "https://github.com/actix/actix-extras.git" -categories = ["network-programming", "asynchronous"] -license.workspace = true -edition.workspace = true -rust-version.workspace = true - -[package.metadata.docs.rs] -rustdoc-args = ["--cfg", "docsrs"] -all-features = true - -[lib] -name = "actix_redis" -path = "src/lib.rs" - -[features] -default = ["web"] - -# actix-web integration -web = ["actix-web"] - -[dependencies] -actix = { version = "0.13", default-features = false } -actix-rt = { version = "2.1", default-features = false } -actix-service = "2" -actix-tls = { version = "3", default-features = false, features = ["connect"] } - -log = "0.4.6" -backoff = "0.4.0" -derive_more = "0.99.7" -futures-core = "0.3.17" -redis-async = "0.16" -time = "0.3" -tokio = { version = "1.18.4", features = ["sync"] } -tokio-util = "0.7" -actix-web = { version = "4", default-features = false, optional = true } - -[dev-dependencies] -actix-test = "0.1.0-beta.12" -actix-web = { version = "4", default-features = false, features = ["macros"] } -env_logger = "0.11" -serde = { version = "1.0.101", features = ["derive"] } diff --git a/actix-redis/LICENSE-APACHE b/actix-redis/LICENSE-APACHE deleted file mode 120000 index 965b606f3..000000000 --- a/actix-redis/LICENSE-APACHE +++ /dev/null @@ -1 +0,0 @@ -../LICENSE-APACHE \ No newline at end of file diff --git a/actix-redis/LICENSE-MIT b/actix-redis/LICENSE-MIT deleted file mode 120000 index 76219eb72..000000000 --- a/actix-redis/LICENSE-MIT +++ /dev/null @@ -1 +0,0 @@ -../LICENSE-MIT \ No newline at end of file diff --git a/actix-redis/README.md b/actix-redis/README.md deleted file mode 100644 index af4fbaaaa..000000000 --- a/actix-redis/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# actix-redis - -> Actor-based Redis client. - - - -[![crates.io](https://img.shields.io/crates/v/actix-redis?label=latest)](https://crates.io/crates/actix-redis) -[![Documentation](https://docs.rs/actix-redis/badge.svg?version=0.13.0)](https://docs.rs/actix-redis/0.13.0) -![Apache 2.0 or MIT licensed](https://img.shields.io/crates/l/actix-redis) -[![Dependency Status](https://deps.rs/crate/actix-redis/0.13.0/status.svg)](https://deps.rs/crate/actix-redis/0.13.0) - - - -## Documentation & Resources - -- [API Documentation](https://docs.rs/actix-redis) -- [Example Project](https://github.com/actix/examples/tree/master/auth/redis-session) -- Minimum Supported Rust Version (MSRV): 1.57 diff --git a/actix-redis/src/lib.rs b/actix-redis/src/lib.rs deleted file mode 100644 index 1d3856443..000000000 --- a/actix-redis/src/lib.rs +++ /dev/null @@ -1,32 +0,0 @@ -//! Redis integration for `actix`. - -#![forbid(unsafe_code)] -#![deny(rust_2018_idioms, nonstandard_style)] -#![warn(future_incompatible)] -#![doc(html_logo_url = "https://actix.rs/img/logo.png")] -#![doc(html_favicon_url = "https://actix.rs/favicon.ico")] -#![cfg_attr(docsrs, feature(doc_auto_cfg))] - -use derive_more::{Display, Error, From}; -pub use redis_async::{error::Error as RespError, resp::RespValue, resp_array}; - -mod redis; -pub use self::redis::{Command, RedisActor}; - -/// General purpose `actix-redis` error. -#[derive(Debug, Display, Error, From)] -pub enum Error { - #[display(fmt = "Redis error: {_0}")] - Redis(redis_async::error::Error), - - /// Receiving message during reconnecting. - #[display(fmt = "Redis: Not connected")] - NotConnected, - - /// Cancel all waiters when connection is dropped. - #[display(fmt = "Redis: Disconnected")] - Disconnected, -} - -#[cfg(feature = "web")] -impl actix_web::ResponseError for Error {} diff --git a/actix-redis/src/redis.rs b/actix-redis/src/redis.rs deleted file mode 100644 index 5f59ea00f..000000000 --- a/actix-redis/src/redis.rs +++ /dev/null @@ -1,143 +0,0 @@ -use std::{collections::VecDeque, io}; - -use actix::prelude::*; -use actix_rt::net::TcpStream; -use actix_service::boxed::{self, BoxService}; -use actix_tls::connect::{ConnectError, ConnectInfo, Connection, ConnectorService}; -use backoff::{backoff::Backoff, ExponentialBackoff}; -use log::{error, info, warn}; -use redis_async::{ - error::Error as RespError, - resp::{RespCodec, RespValue}, -}; -use tokio::{ - io::{split, WriteHalf}, - sync::oneshot, -}; -use tokio_util::codec::FramedRead; - -use crate::Error; - -/// Command for sending data to Redis. -#[derive(Debug)] -pub struct Command(pub RespValue); - -impl Message for Command { - type Result = Result; -} - -/// Redis communication actor. -pub struct RedisActor { - addr: String, - connector: BoxService, Connection, ConnectError>, - backoff: ExponentialBackoff, - cell: Option, RespCodec>>, - queue: VecDeque>>, -} - -impl RedisActor { - /// Start new `Supervisor` with `RedisActor`. - pub fn start>(addr: S) -> Addr { - let addr = addr.into(); - - let backoff = ExponentialBackoff { - max_elapsed_time: None, - ..Default::default() - }; - - Supervisor::start(|_| RedisActor { - addr, - connector: boxed::service(ConnectorService::default()), - cell: None, - backoff, - queue: VecDeque::new(), - }) - } -} - -impl Actor for RedisActor { - type Context = Context; - - fn started(&mut self, ctx: &mut Context) { - let req = ConnectInfo::new(self.addr.to_owned()); - self.connector - .call(req) - .into_actor(self) - .map(|res, act, ctx| match res { - Ok(conn) => { - let stream = conn.into_parts().0; - info!("Connected to redis server: {}", act.addr); - - let (r, w) = split(stream); - - // configure write side of the connection - let framed = actix::io::FramedWrite::new(w, RespCodec, ctx); - act.cell = Some(framed); - - // read side of the connection - ctx.add_stream(FramedRead::new(r, RespCodec)); - - act.backoff.reset(); - } - Err(err) => { - error!("Can not connect to redis server: {}", err); - // re-connect with backoff time. - // we stop current context, supervisor will restart it. - if let Some(timeout) = act.backoff.next_backoff() { - ctx.run_later(timeout, |_, ctx| ctx.stop()); - } - } - }) - .wait(ctx); - } -} - -impl Supervised for RedisActor { - fn restarting(&mut self, _: &mut Self::Context) { - self.cell.take(); - for tx in self.queue.drain(..) { - let _ = tx.send(Err(Error::Disconnected)); - } - } -} - -impl actix::io::WriteHandler for RedisActor { - fn error(&mut self, err: io::Error, _: &mut Self::Context) -> Running { - warn!("Redis connection dropped: {} error: {}", self.addr, err); - Running::Stop - } -} - -impl StreamHandler> for RedisActor { - fn handle(&mut self, msg: Result, ctx: &mut Self::Context) { - match msg { - Err(e) => { - if let Some(tx) = self.queue.pop_front() { - let _ = tx.send(Err(e.into())); - } - ctx.stop(); - } - Ok(val) => { - if let Some(tx) = self.queue.pop_front() { - let _ = tx.send(Ok(val)); - } - } - } - } -} - -impl Handler for RedisActor { - type Result = ResponseFuture>; - - fn handle(&mut self, msg: Command, _: &mut Self::Context) -> Self::Result { - let (tx, rx) = oneshot::channel(); - if let Some(ref mut cell) = self.cell { - self.queue.push_back(tx); - cell.write(msg.0); - } else { - let _ = tx.send(Err(Error::NotConnected)); - } - - Box::pin(async move { rx.await.map_err(|_| Error::Disconnected)? }) - } -} diff --git a/actix-redis/tests/test_redis.rs b/actix-redis/tests/test_redis.rs deleted file mode 100644 index fa2f88f26..000000000 --- a/actix-redis/tests/test_redis.rs +++ /dev/null @@ -1,42 +0,0 @@ -#[macro_use] -extern crate redis_async; - -use actix_redis::{Command, Error, RedisActor, RespValue}; - -#[actix_web::test] -async fn test_error_connect() { - let addr = RedisActor::start("localhost:54000"); - let _addr2 = addr.clone(); - - let res = addr.send(Command(resp_array!["GET", "test"])).await; - match res { - Ok(Err(Error::NotConnected)) => (), - _ => panic!("Should not happen {:?}", res), - } -} - -#[actix_web::test] -async fn test_redis() { - env_logger::init(); - - let addr = RedisActor::start("127.0.0.1:6379"); - let res = addr - .send(Command(resp_array!["SET", "test", "value"])) - .await; - - match res { - Ok(Ok(resp)) => { - assert_eq!(resp, RespValue::SimpleString("OK".to_owned())); - - let res = addr.send(Command(resp_array!["GET", "test"])).await; - match res { - Ok(Ok(resp)) => { - println!("RESP: {resp:?}"); - assert_eq!(resp, RespValue::BulkString((&b"value"[..]).into())); - } - _ => panic!("Should not happen {:?}", res), - } - } - _ => panic!("Should not happen {:?}", res), - } -} diff --git a/actix-session/CHANGES.md b/actix-session/CHANGES.md index c8d412fc1..4c1138e41 100644 --- a/actix-session/CHANGES.md +++ b/actix-session/CHANGES.md @@ -2,6 +2,8 @@ ## Unreleased +- Remove `redis-actor-session` crate feature (and, therefore, the `actix-redis` based storage backend). + ## 0.9.0 - Remove use of `async-trait` on `SessionStore` trait. diff --git a/actix-session/Cargo.toml b/actix-session/Cargo.toml index f1baaeba0..38a5ec928 100644 --- a/actix-session/Cargo.toml +++ b/actix-session/Cargo.toml @@ -20,7 +20,6 @@ all-features = true [features] default = [] cookie-session = [] -redis-actor-session = ["actix-redis", "actix", "futures-core", "rand"] redis-rs-session = ["redis", "rand"] redis-rs-tls-session = ["redis-rs-session", "redis/tokio-native-tls-comp"] @@ -36,16 +35,11 @@ serde = { version = "1" } serde_json = { version = "1" } tracing = { version = "0.1.30", default-features = false, features = ["log"] } -# redis-actor-session -actix = { version = "0.13", default-features = false, optional = true } -actix-redis = { version = "0.12", optional = true } -futures-core = { version = "0.3.17", optional = true } - # redis-rs-session redis = { version = "0.24", default-features = false, features = ["tokio-comp", "connection-manager"], optional = true } [dev-dependencies] -actix-session = { path = ".", features = ["cookie-session", "redis-actor-session", "redis-rs-session"] } +actix-session = { path = ".", features = ["cookie-session", "redis-rs-session"] } actix-test = "0.1.0-beta.10" actix-web = { version = "4", default-features = false, features = ["cookies", "secure-cookies", "macros"] } env_logger = "0.11" @@ -53,8 +47,8 @@ log = "0.4" [[example]] name = "basic" -required-features = ["redis-actor-session"] +required-features = ["redis-rs-session"] [[example]] name = "authentication" -required-features = ["redis-actor-session"] +required-features = ["redis-rs-session"] diff --git a/actix-session/README.md b/actix-session/README.md index 6c45f29ad..ee6fa5b8c 100644 --- a/actix-session/README.md +++ b/actix-session/README.md @@ -100,14 +100,6 @@ By default, `actix-session` does not provide any storage backend to retrieve and actix-session = { version = "...", features = ["cookie-session"] } ``` -- a Redis-based backend via [`actix-redis`](https://docs.rs/actix-redis), [`RedisActorSessionStore`], using the `redis-actor-session` feature flag. - - ```toml - [dependencies] - # ... - actix-session = { version = "...", features = ["redis-actor-session"] } - ``` - - a Redis-based backend via [`redis-rs`](https://docs.rs/redis-rs), [`RedisSessionStore`], using the `redis-rs-session` feature flag. ```toml diff --git a/actix-session/examples/authentication.rs b/actix-session/examples/authentication.rs index 400971051..329d63126 100644 --- a/actix-session/examples/authentication.rs +++ b/actix-session/examples/authentication.rs @@ -1,4 +1,4 @@ -use actix_session::{storage::RedisActorSessionStore, Session, SessionMiddleware}; +use actix_session::{storage::RedisSessionStore, Session, SessionMiddleware}; use actix_web::{ cookie::{Key, SameSite}, error::InternalError, @@ -76,6 +76,9 @@ async fn main() -> std::io::Result<()> { // The signing key would usually be read from a configuration file/environment variables. let signing_key = Key::generate(); + log::info!("setting up Redis session storage"); + let storage = RedisSessionStore::new("127.0.0.1:6379").await.unwrap(); + log::info!("starting HTTP server at http://localhost:8080"); HttpServer::new(move || { @@ -84,15 +87,12 @@ async fn main() -> std::io::Result<()> { .wrap(middleware::Logger::default()) // cookie session middleware .wrap( - SessionMiddleware::builder( - RedisActorSessionStore::new("127.0.0.1:6379"), - signing_key.clone(), - ) - // allow the cookie to be accessed from javascript - .cookie_http_only(false) - // allow the cookie only from the current domain - .cookie_same_site(SameSite::Strict) - .build(), + SessionMiddleware::builder(storage.clone(), signing_key.clone()) + // allow the cookie to be accessed from javascript + .cookie_http_only(false) + // allow the cookie only from the current domain + .cookie_same_site(SameSite::Strict) + .build(), ) .route("/login", web::post().to(login)) .route("/secret", web::get().to(secret)) diff --git a/actix-session/examples/basic.rs b/actix-session/examples/basic.rs index f1f08ae66..a8a6aa847 100644 --- a/actix-session/examples/basic.rs +++ b/actix-session/examples/basic.rs @@ -1,4 +1,4 @@ -use actix_session::{storage::RedisActorSessionStore, Session, SessionMiddleware}; +use actix_session::{storage::RedisSessionStore, Session, SessionMiddleware}; use actix_web::{cookie::Key, middleware, web, App, Error, HttpRequest, HttpServer, Responder}; /// simple handler @@ -23,6 +23,9 @@ async fn main() -> std::io::Result<()> { // The signing key would usually be read from a configuration file/environment variables. let signing_key = Key::generate(); + log::info!("setting up Redis session storage"); + let storage = RedisSessionStore::new("127.0.0.1:6379").await.unwrap(); + log::info!("starting HTTP server at http://localhost:8080"); HttpServer::new(move || { @@ -30,10 +33,7 @@ async fn main() -> std::io::Result<()> { // enable logger .wrap(middleware::Logger::default()) // cookie session middleware - .wrap(SessionMiddleware::new( - RedisActorSessionStore::new("127.0.0.1:6379"), - signing_key.clone(), - )) + .wrap(SessionMiddleware::new(storage.clone(), signing_key.clone())) // register simple route, handle all methods .service(web::resource("/").to(index)) }) diff --git a/actix-session/src/lib.rs b/actix-session/src/lib.rs index 31665e524..4ad2c5ebe 100644 --- a/actix-session/src/lib.rs +++ b/actix-session/src/lib.rs @@ -106,15 +106,6 @@ attached to your sessions. You can enable: actix-session = { version = "...", features = ["cookie-session"] } ``` -- a Redis-based backend via [`actix-redis`](https://docs.rs/actix-redis), - [`RedisActorSessionStore`], using the `redis-actor-session` feature flag. - - ```toml - [dependencies] - # ... - actix-session = { version = "...", features = ["redis-actor-session"] } - ``` - - a Redis-based backend via [`redis-rs`](https://docs.rs/redis-rs), [`RedisSessionStore`], using the `redis-rs-session` feature flag. diff --git a/actix-session/src/middleware.rs b/actix-session/src/middleware.rs index 5016f6fc7..536e4c7cc 100644 --- a/actix-session/src/middleware.rs +++ b/actix-session/src/middleware.rs @@ -47,7 +47,7 @@ use crate::{ /// # Examples /// ```no_run /// use actix_web::{web, App, HttpServer, HttpResponse, Error}; -/// use actix_session::{Session, SessionMiddleware, storage::RedisActorSessionStore}; +/// use actix_session::{Session, SessionMiddleware, storage::RedisSessionStore}; /// use actix_web::cookie::Key; /// /// // The secret key would usually be read from a configuration file/environment variables. @@ -59,20 +59,20 @@ use crate::{ /// #[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() -/// // Add session management to your application using Redis for session state storage -/// .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 +/// let storage = RedisSessionStore::new("127.0.0.1:6379").await.unwrap(); +/// +/// HttpServer::new(move || { +/// App::new() +/// // Add session management to your application using Redis as storage +/// .wrap(SessionMiddleware::new( +/// storage.clone(), +/// secret_key.clone(), +/// )) +/// .default_service(web::to(|| HttpResponse::Ok())) +/// }) +/// .bind(("127.0.0.1", 8080))? +/// .run() +/// .await /// } /// ``` /// @@ -80,7 +80,7 @@ use crate::{ /// /// ```no_run /// use actix_web::{App, cookie::{Key, time}, Error, HttpResponse, HttpServer, web}; -/// use actix_session::{Session, SessionMiddleware, storage::RedisActorSessionStore}; +/// use actix_session::{Session, SessionMiddleware, storage::RedisSessionStore}; /// use actix_session::config::PersistentSession; /// /// // The secret key would usually be read from a configuration file/environment variables. @@ -92,25 +92,23 @@ use crate::{ /// #[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() +/// let storage = RedisSessionStore::new("127.0.0.1:6379").await.unwrap(); +/// +/// HttpServer::new(move || { +/// App::new() /// // Customise session length! /// .wrap( -/// SessionMiddleware::builder( -/// RedisActorSessionStore::new(redis_connection_string), -/// secret_key.clone() -/// ) -/// .session_lifecycle( -/// PersistentSession::default() -/// .session_ttl(time::Duration::days(5)) -/// ) -/// .build(), +/// SessionMiddleware::builder(storage.clone(), secret_key.clone()) +/// .session_lifecycle( +/// PersistentSession::default().session_ttl(time::Duration::days(5)), +/// ) +/// .build(), /// ) -/// .default_service(web::to(|| HttpResponse::Ok()))) -/// .bind(("127.0.0.1", 8080))? -/// .run() -/// .await +/// .default_service(web::to(|| HttpResponse::Ok())) +/// }) +/// .bind(("127.0.0.1", 8080))? +/// .run() +/// .await /// } /// ``` #[derive(Clone)] diff --git a/actix-session/src/storage/mod.rs b/actix-session/src/storage/mod.rs index 17508850f..5f6552097 100644 --- a/actix-session/src/storage/mod.rs +++ b/actix-session/src/storage/mod.rs @@ -11,18 +11,13 @@ pub use self::{ #[cfg(feature = "cookie-session")] mod cookie; -#[cfg(feature = "redis-actor-session")] -mod redis_actor; - #[cfg(feature = "redis-rs-session")] mod redis_rs; -#[cfg(any(feature = "redis-actor-session", feature = "redis-rs-session"))] +#[cfg(feature = "redis-rs-session")] mod utils; #[cfg(feature = "cookie-session")] pub use cookie::CookieSessionStore; -#[cfg(feature = "redis-actor-session")] -pub use redis_actor::{RedisActorSessionStore, RedisActorSessionStoreBuilder}; #[cfg(feature = "redis-rs-session")] pub use redis_rs::{RedisSessionStore, RedisSessionStoreBuilder}; diff --git a/actix-session/src/storage/redis_rs.rs b/actix-session/src/storage/redis_rs.rs index e27ba2a23..cd0803f3a 100644 --- a/actix-session/src/storage/redis_rs.rs +++ b/actix-session/src/storage/redis_rs.rs @@ -120,9 +120,7 @@ impl RedisSessionStoreBuilder { self } - /// Finalise the builder and return a [`RedisActorSessionStore`] instance. - /// - /// [`RedisActorSessionStore`]: crate::storage::RedisActorSessionStore + /// Finalise the builder and return a [`RedisSessionStore`] instance. pub async fn build(self) -> Result { let client = ConnectionManager::new(redis::Client::open(self.connection_string)?).await?; Ok(RedisSessionStore {