http-rs / async-mongodb-session Goto Github PK
View Code? Open in Web Editor NEWAn async-session implementation for MongoDB
License: Apache License 2.0
An async-session implementation for MongoDB
License: Apache License 2.0
Each request we make creates a new session id entry in the database. It seems we're probably doing something wrong. The result is that the counter isn't updated and we keep opening new sessions.
Related issues: #1, http-rs/async-session#10, http-rs/tide#664
cc/ @lrlna
cargo run --example session
As mongodb
now supports async-std
runtime besides tokio
and the whole async-*
ecosystem of crates usually use async-std
as its default runtime, shouldn't this crate provide support for that runtime as well?
Hey Folks
As mentioned in the code https://github.com/yoshuawuyts/async-mongodb-session/blob/master/src/lib.rs#L49
Sessions do not expire at the moment.
Looking at the mongo docs it seems expiry can be enforced using an index
https://docs.mongodb.com/manual/tutorial/expire-data/#expire-documents-after-a-specified-number-of-seconds
It should be simple enough to code (famous last words when talking about cache expiry :) ), but wanted to clarify a some points before i started.
The approach I am considering is to add an additional parameter called expireAfterSeconds
to connect and from_client
Is that ok?
Currently the session object in async-session only has an expiry
field https://github.com/http-rs/async-session/blob/main/src/session.rs#L59 .
Using the inbuilt TTL in mongo means that the property in this scenario is not an expiry time but the creation time that will be offset with the expireAfterSeconds value to calculate the expiry time.
I can proceed using the expiry field but would suggest that we change the name of the of the session object to expiry-marker.
If that makes sense I can PR that as part of this.
As the TTL is an index it will have to be redefined on restart in the case where the user changes the value following restarts.
This will be done using collMod
https://docs.mongodb.com/manual/reference/command/collMod/#dbcmd.collMod
It would be great if we can finalise #7 as expiry will will need tests and I wouldn't want to do too much using an approach that hasn't landed.
Thanks for your time.
We either need to make it so Tide can work with older versions of async-std, or update mongodb to async-std 1.6+.
cc/ @saghm; most of the issues on async-std 1.6 have been fixed; are there any blockers on upgrading to a newer version? Is there anything I can do to help?
error[E0428]: the name `RUNTIME_NAME` is defined multiple times
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mongodb-2.3.1/src/cmap/establish/handshake/mod.rs:25:1
|
22 | const RUNTIME_NAME: &str = "tokio";
| ----------------------------------- previous definition of the value `RUNTIME_NAME` here
...
25 | const RUNTIME_NAME: &str = "async-std";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `RUNTIME_NAME` redefined here
|
= note: `RUNTIME_NAME` must be defined only once in the value namespace of this module
error[E0252]: the name `Interval` is defined multiple times
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mongodb-2.3.1/src/runtime/mod.rs:34:5
|
28 | use interval::Interval;
| ------------------ previous import of the type `Interval` here
...
34 | use tokio::time::Interval;
| ^^^^^^^^^^^^^^^^^^^^^ `Interval` reimported here
|
= note: `Interval` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
|
34 | use tokio::time::Interval as OtherInterval;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: `tokio-runtime` and `async-std-runtime` can't both be enabled; either disable `async-std-runtime` or set `default-features = false` in your Cargo.toml
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mongodb-2.3.1/src/lib.rs:357:1
|
357 | / compile_error!(
358 | | "`tokio-runtime` and `async-std-runtime` can't both be enabled; either disable \
359 | | `async-std-runtime` or set `default-features = false` in your Cargo.toml"
360 | | );
| |_^
error[E0124]: field `resolver` is already declared
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/mongodb-2.3.1/src/runtime/resolver.rs:16:5
|
13 | resolver: trust_dns_resolver::TokioAsyncResolver,
| ------------------------------------------------ `resolver` first declared here
...
16 | resolver: async_std_resolver::AsyncStdResolver,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ field already declared
[dependencies]
axum = "0.5.16"
axum-extra = { version = "0.3.7", features = ["cookie-private", "cookie-signed"] }
axum-sessions = "0.3.1"
async-session = "3.0.0"
# async-redis-session = "0.2.2"
mongodb = { version = "2.3.1", features = ["tokio-runtime"] }
async-mongodb-session = { version = "3.0.0", features = ["tokio-runtime"] }
tokio = { version = "1.21.2", features = ["full"] }
For some reason this app crashes when trying to use MongodbSessionStore::from_client
I tried deleting the .cargo cache, but the problem still persists. Any ideas?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.