Giter Club home page Giter Club logo

Comments (8)

maxcountryman avatar maxcountryman commented on May 30, 2024

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.

AppyCat avatar AppyCat commented on May 30, 2024

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.

Ptrskay3 avatar Ptrskay3 commented on May 30, 2024

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.

maxcountryman avatar maxcountryman commented on May 30, 2024

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.

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.

AppyCat avatar AppyCat commented on May 30, 2024

That would be ideal if async-redis-session enables Tokio as a feature flag. Thanks for all your input and help.

from axum-sessions.

Ptrskay3 avatar Ptrskay3 commented on May 30, 2024

@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.

maxcountryman avatar maxcountryman commented on May 30, 2024

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.

maxcountryman avatar maxcountryman commented on May 30, 2024

@AppyCat we've released tower-sessions 0.1.0 which includes Redis support.

from axum-sessions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.