1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-12-18 01:33:59 +01:00
actix-extras/actix-redis/README.md

48 lines
1.7 KiB
Markdown
Raw Normal View History

2020-01-30 01:31:25 +01:00
# actix-redis
2018-01-23 08:16:24 +01:00
> Redis integration for Actix and session store for Actix Web.
2020-01-30 01:31:25 +01:00
[![crates.io](https://img.shields.io/crates/v/actix-redis?label=latest)](https://crates.io/crates/actix-redis)
2021-04-02 12:38:27 +02:00
[![Documentation](https://docs.rs/actix-redis/badge.svg?version=0.10.0-beta.1)](https://docs.rs/actix-redis/0.10.0-beta.1)
![Apache 2.0 or MIT licensed](https://img.shields.io/crates/l/actix-redis)
2021-04-02 12:38:27 +02:00
[![Dependency Status](https://deps.rs/crate/actix-redis/0.10.0-beta.1/status.svg)](https://deps.rs/crate/actix-redis/0.10.0-beta.1)
2018-01-23 08:13:18 +01:00
## Documentation & Resources
2018-01-23 08:13:18 +01:00
2021-04-09 15:39:50 +02:00
- [API Documentation](https://docs.rs/actix-redis)
- [Example Project](https://github.com/actix/examples/tree/HEAD/session/redis-session)
2021-04-02 12:31:30 +02:00
- Minimum Supported Rust Version (MSRV): 1.46
2018-01-23 08:13:18 +01:00
## Redis Session Backend
2017-12-29 10:10:27 +01:00
Use redis as session storage.
You need to pass an address of the redis server and random value to the
constructor of `RedisSession`. This is private key for cookie session,
2017-12-29 10:10:27 +01:00
When this value is changed, all session data is lost.
Note that whatever you write into your session is visible by the user (but not modifiable).
Constructor panics if key length is less than 32 bytes.
2018-05-08 19:12:57 +02:00
```rust
2021-04-09 15:39:50 +02:00
use actix_web::{App, HttpServer, middleware::Logger};
use actix_web::web::{resource, get}
use actix_redis::RedisSession;
2017-12-29 10:10:27 +01:00
2021-04-09 15:39:50 +02:00
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(move || App::new()
2019-12-20 17:11:38 +01:00
// cookie session middleware
2021-04-09 15:39:50 +02:00
.wrap(RedisSession::new("127.0.0.1:6379", &[0; 32]))
// enable logger
.wrap(Logger::default())
2019-12-20 17:11:38 +01:00
// register simple route, handle all methods
2021-04-09 15:39:50 +02:00
.service(resource("/").route(get().to(index)))
2019-12-20 17:11:38 +01:00
)
2021-04-09 15:39:50 +02:00
.bind("127.0.0.1:8080")?
.run()
2019-12-20 17:11:38 +01:00
.await
2017-12-29 10:10:27 +01:00
}
```