Skip to content

Commit 6f84cfe

Browse files
committed
refactor(playmatch): use typed scan_match for suggestion store list_all
1 parent fdf9252 commit 6f84cfe

1 file changed

Lines changed: 8 additions & 16 deletions

File tree

src/abstraction/suggestion_store.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,15 @@ impl SuggestionStore {
4646
pub async fn list_all(&self) -> Result<HashMap<Uuid, MessageId>, Error> {
4747
let mut conn = self.conn.clone();
4848
let pattern = format!("{KEY_PREFIX}*");
49-
let mut cursor = 0u64;
50-
let mut keys: Vec<String> = Vec::new();
51-
loop {
52-
let (next_cursor, batch): (u64, Vec<String>) = redis::cmd("SCAN")
53-
.arg(cursor)
54-
.arg("MATCH")
55-
.arg(&pattern)
56-
.arg("COUNT")
57-
.arg(100)
58-
.query_async(&mut conn)
59-
.await?;
60-
keys.extend(batch);
61-
if next_cursor == 0 {
62-
break;
49+
50+
let keys: Vec<String> = {
51+
let mut iter: redis::AsyncIter<'_, String> = conn.scan_match(&pattern).await?;
52+
let mut collected = Vec::new();
53+
while let Some(item) = iter.next_item().await {
54+
collected.push(item?);
6355
}
64-
cursor = next_cursor;
65-
}
56+
collected
57+
};
6658

6759
if keys.is_empty() {
6860
return Ok(HashMap::new());

0 commit comments

Comments
 (0)