Comments (8)
Hi there, have you had a look at the Crate docs already? This example in particular might be helpful.
There isn't an example of Redis specifically, however I'd be happy to accept a PR with an implementation in examples/
. I can also share how I'm using the SQLx variation:
let store = PostgresSessionStore::new(&config.database_url)
.await
.expect("Could not connect to database.");
store.migrate().await.unwrap();
let service = ServiceBuilder::new().layer(
SessionLayer::new(store, config.app_secret.as_bytes())
.with_same_site_policy(SameSite::Lax)
.with_secure(false),
);
from axum-sessions.
Thanks for the links, I did view the docs and use the example.
However with session_layer as the layer, it's not storing a record set in one handler which is retrievable in another handler.
Perhaps it may be an idea to doc an example of an insert in one handler and a get in another handler.
Redis is generally more widely used to store sessions, so if you could doc a Redis example, insert & get in separate handlers, that would be awesome.
from axum-sessions.
I have a relatively complex project with a redis session using this crate. When I'll have a little more free time, I'll submit a PR with a basic working example. The redis part is not that complicated imo, so basically I just followed the docs.
Edit:
There's one little problem with it though; I had to fork async_redis_session
and change it to use tokio
instead of async-std
.
from axum-sessions.
Edit: There's one little problem with it though; I had to fork
async_redis_session
and change it to usetokio
instead ofasync-std
.
Oh that's too bad: async-sqlx-session
allows you to configure the async runtime with feature flags. I wonder if async-redis-session
would be open to a similar approach?
from axum-sessions.
That would be ideal if async-redis-session enables Tokio as a feature flag. Thanks for all your input and help.
from axum-sessions.
@AppyCat I have a redis example here. I'm not going to submit a PR, as the async_redis_session
crate still uses async-std
for the Redis connection, and if you run that example, it'll spin up both tokio and async-std. I personally have my own fork of async_redis_session
where I patched to use get_tokio_connection
instead of get_async_std_connection
.
from axum-sessions.
I also added a sqlx example for reference.
Given that async-sqlx-session
and async-redis-session
share maintainers, I wonder if there's appetite for incorporating upstream changes to support tokio with the redis variant.
from axum-sessions.
@AppyCat we've released tower-sessions 0.1.0 which includes Redis support.
from axum-sessions.
Related Issues (20)
- Idea: Rework session service implementation to use the new axum 0.6 state pattern HOT 3
- Please consider to keep a changelog HOT 4
- How to retrieve a readable session in middleware? HOT 11
- Resist session id name fingerprinting by default HOT 2
- Rustdoc code doesn't compile due to minor import error HOT 2
- Session not saving when returning a redirect response HOT 7
- "Session handle still has owners" HOT 5
- ReadableSession test utils HOT 1
- How to connect to redis or pg ? HOT 1
- Type-safe `Session` handles HOT 1
- Add a listener trait to listen to the creation, update and destruction of sessions HOT 3
- Implementing `MemoryStore` HOT 5
- Memory session is not persisted (on RPi Arm) HOT 3
- Deadlock when using WritableSession in middleware layer HOT 8
- Bug: data present in session, but `.get` returns `None` HOT 2
- WritableSession Load Forever HOT 4
- How to make one-shot session?
- Session expiration has no effect
- How to destroy then insert in the same route?
- How to persist postgres sessions between server restarts or load balanced servers? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from axum-sessions.