-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
some fixing to the draft, still a draft
- Loading branch information
Showing
17 changed files
with
420 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 | ||
*/ | ||
use logger_core::log_info; | ||
use once_cell::sync::Lazy; | ||
use redis::{RedisResult, ScanStateRC}; | ||
use sha1_smol::Sha1; | ||
use std::{collections::HashMap, sync::Mutex}; | ||
|
||
static CONTAINER: Lazy<Mutex<HashMap<String, ScanStateRC>>> = | ||
Lazy::new(|| Mutex::new(HashMap::new())); | ||
|
||
pub fn insert_cluster_scan_cursor(scan_state: ScanStateRC) -> String { | ||
let hash = Sha1::new(); | ||
let hash = hash.digest().to_string(); | ||
CONTAINER | ||
.lock() | ||
.unwrap() | ||
.insert(hash.clone(), scan_state.into()); | ||
hash | ||
} | ||
|
||
pub fn get_cluster_scan_cursor(hash: String) -> RedisResult<ScanStateRC> { | ||
let scan_state_rc = CONTAINER.lock().unwrap().get(&hash).cloned(); | ||
match scan_state_rc { | ||
Some(scan_state_rc) => Ok(scan_state_rc.into()), | ||
None => Err(redis::RedisError::from(( | ||
redis::ErrorKind::ResponseError, | ||
"Invalid scan_state_cursor hash", | ||
))), | ||
} | ||
} | ||
|
||
pub fn remove_scan_state_cursor(hash: String) { | ||
log_info( | ||
"scan_state_cursor lifetime", | ||
format!("Removed scan_state_cursor with hash: `{hash}`"), | ||
); | ||
CONTAINER.lock().unwrap().remove(&hash); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.