mirror of
https://github.com/modrinth/code.git
synced 2026-08-25 00:55:25 +00:00
* chore(labrinth): bump to redis 1.4.1 * feat(labrinth): redis cluster * chore: cleanup * feat(labrinth): cache locking * fix(labrinth): clippy * chore(labrinth): cleanup env, remove postcard support * chore(ci): fix test env for labrinth * chore(labrinth): bump all key versions * chore(labrinth): improve redis key identities handling * chore(labrinth): simplify deadline handling * chore(labrinth): remove unused lease tracking * chore(labrinth): remove distributed cache locking for now * chore(labrinth): improve redis backend init error * feat(labrinth): expose redis read replica strategy * chore(ci): remove other connection mode tests * chore: split xredis crate * feat(xredis): primaries routing * chore: tombi fmt * chore: clippy * chore: update query cache
30 lines
996 B
Rust
30 lines
996 B
Rust
use std::collections::HashMap;
|
|
|
|
use redis::cluster_routing::{
|
|
MultiSlotArgPattern, MultipleNodeRoutingInfo, ResponsePolicy, Route,
|
|
RoutingInfo, SlotAddr,
|
|
};
|
|
|
|
/// Returns a routing specification to split an MGET by hash slots and
|
|
/// route to **primaries only**.
|
|
///
|
|
/// Use this if you need a command to be routed to primaries only.
|
|
///
|
|
/// It's not needed just to split an MGET; redis-rs already does that by default.
|
|
pub(crate) fn primary_mget_routing<K: AsRef<[u8]>>(keys: &[K]) -> RoutingInfo {
|
|
let mut keys_by_slot: HashMap<Route, Vec<usize>> = HashMap::new();
|
|
|
|
for (index, key) in keys.iter().enumerate() {
|
|
let route = Route::with_key(key.as_ref(), SlotAddr::Master);
|
|
keys_by_slot.entry(route).or_default().push(index);
|
|
}
|
|
|
|
RoutingInfo::MultiNode((
|
|
MultipleNodeRoutingInfo::MultiSlot((
|
|
keys_by_slot.into_iter().collect(),
|
|
MultiSlotArgPattern::KeysOnly,
|
|
)),
|
|
Some(ResponsePolicy::CombineArrays),
|
|
))
|
|
}
|