Function fred::util::group_by_hash_slot
source ยท pub fn group_by_hash_slot<T>(
args: impl IntoIterator<Item = T>,
) -> Result<BTreeMap<u16, VecDeque<RedisKey>>, RedisError>Expand description
Group the provided arguments by their cluster hash slot.
This can be useful with commands that require all keys map to the same hash slot, such as SSUBSCRIBE,
MGET, etc.
async fn example(client: impl KeysInterface) -> Result<(), RedisError> {
let keys = vec!["foo", "bar", "baz", "a{1}", "b{1}", "c{1}"];
let groups = fred::util::group_by_hash_slot(keys)?;
for (slot, keys) in groups.into_iter() {
// `MGET` requires that all arguments map to the same hash slot
println!("{:?}", client.mget::<Vec<String>, _>(keys).await?);
}
Ok(())
}