Skip to content

Commit

Permalink
fix kitsune-test
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed May 20, 2024
1 parent 400356a commit bee283e
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions crates/kitsune-test/src/redis.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use fred::{
clients::RedisClient,
interfaces::{ClientLike, RedisResult},
types::{RedisConfig, RedisValue},
interfaces::{ClientLike, KeysInterface, RedisResult, ServerInterface},
types::{RedisConfig, RedisValue, SetOptions},
};
use rand::Rng;
use std::{ops::RangeInclusive, time::Duration};
Expand All @@ -12,16 +12,12 @@ const LOCK_VALUE: &str = "LOCKED";
const SLEEP_DURATION: Duration = Duration::from_millis(100);

async fn switch_and_try_lock(conn: &RedisClient, id: u8) -> bool {
conn.custom::<(), _>(fred::cmd!("SELECT"), vec![id])
.await
.unwrap();

conn.select(id).await.unwrap();
try_lock(conn).await
}

async fn try_lock(conn: &RedisClient) -> bool {
let result: RedisResult<RedisValue> = conn
.custom(fred::cmd!("SELECT"), vec![LOCK_KEY, LOCK_VALUE, "NX"])
conn.set(LOCK_KEY, LOCK_VALUE, None, Some(SetOptions::NX), true)
.await;

if let Ok(val) = result {
Expand Down

0 comments on commit bee283e

Please sign in to comment.