Skip to content

Dependencies, tokio #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "async-redis-session"
version = "0.2.2"
version = "0.2.3"
authors = ["Jacob Rothstein <[email protected]>"]
edition = "2018"
description = "redis session store for async-session"
Expand All @@ -12,11 +12,11 @@ keywords = ["sessions", "tide", "async-session", "redis"]
categories = ["web-programming::http-server", "web-programming", "database"]

[dependencies.redis]
version = "0.21.0"
features = ["aio", "async-std-comp"]
version = "0.23.3"
features = ["aio", "tokio-comp", "connection-manager"]

[dependencies]
async-session = "3.0.0"

[dev-dependencies]
async-std = { version = "1.9.0", features = ["attributes"] }
tokio = { version = "1.21", features = ["full", "tracing"] }
23 changes: 12 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl RedisSessionStore {
}

async fn connection(&self) -> RedisResult<Connection> {
self.client.get_async_std_connection().await
self.client.get_async_connection().await
}
}

Expand Down Expand Up @@ -155,6 +155,7 @@ impl SessionStore for RedisSessionStore {
let mut connection = self.connection().await?;

if self.prefix.is_none() {
// TODO Oops, we're clearing the whole database, this should not happen
let _: () = redis::cmd("FLUSHDB").query_async(&mut connection).await?;
} else {
let ids = self.ids().await?;
Expand All @@ -169,16 +170,16 @@ impl SessionStore for RedisSessionStore {
#[cfg(test)]
mod tests {
use super::*;
use async_std::task;
use std::time::Duration;
use tokio::time;

async fn test_store() -> RedisSessionStore {
let store = RedisSessionStore::new("redis://127.0.0.1").unwrap();
store.clear_store().await.unwrap();
store
}

#[async_std::test]
#[tokio::test]
async fn creating_a_new_session_with_no_expiry() -> Result {
let store = test_store().await;
let mut session = Session::new();
Expand All @@ -194,7 +195,7 @@ mod tests {
Ok(())
}

#[async_std::test]
#[tokio::test]
async fn updating_a_session() -> Result {
let store = test_store().await;
let mut session = Session::new();
Expand All @@ -213,7 +214,7 @@ mod tests {
Ok(())
}

#[async_std::test]
#[tokio::test]
async fn updating_a_session_extending_expiry() -> Result {
let store = test_store().await;
let mut session = Session::new();
Expand All @@ -237,13 +238,13 @@ mod tests {

assert_eq!(1, store.count().await.unwrap());

task::sleep(Duration::from_secs(10)).await;
time::sleep(Duration::from_secs(10)).await;
assert_eq!(0, store.count().await.unwrap());

Ok(())
}

#[async_std::test]
#[tokio::test]
async fn creating_a_new_session_with_expiry() -> Result {
let store = test_store().await;
let mut session = Session::new();
Expand All @@ -261,13 +262,13 @@ mod tests {

assert!(!loaded_session.is_expired());

task::sleep(Duration::from_secs(2)).await;
time::sleep(Duration::from_secs(2)).await;
assert_eq!(None, store.load_session(cookie_value).await?);

Ok(())
}

#[async_std::test]
#[tokio::test]
async fn destroying_a_single_session() -> Result {
let store = test_store().await;
for _ in 0..3i8 {
Expand All @@ -286,7 +287,7 @@ mod tests {
Ok(())
}

#[async_std::test]
#[tokio::test]
async fn clearing_the_whole_store() -> Result {
let store = test_store().await;
for _ in 0..3i8 {
Expand All @@ -300,7 +301,7 @@ mod tests {
Ok(())
}

#[async_std::test]
#[tokio::test]
async fn prefixes() -> Result {
test_store().await; // clear the db

Expand Down