use std::collections::HashMap; use redis::{AsyncCommands, FromRedisValue, ToRedisArgs, ToSingleRedisArg}; use crate::error::{CacheError, CacheResult}; use crate::kv::Cache; impl Cache { pub async fn hget( &self, key: &str, field: &str, ) -> CacheResult> { let mut conn = self.conn().clone(); conn.hget(key, field).await.map_err(CacheError::from) } pub async fn hmget( &self, key: &str, fields: F, ) -> CacheResult>> { let mut conn = self.conn().clone(); conn.hmget(key, fields).await.map_err(CacheError::from) } pub async fn hset( &self, key: &str, field: F, value: V, ) -> CacheResult { let mut conn = self.conn().clone(); conn.hset(key, field, value).await.map_err(CacheError::from) } pub async fn hset_multiple< F: ToSingleRedisArg + Send + Sync, V: ToSingleRedisArg + Send + Sync, >( &self, key: &str, items: &[(F, V)], ) -> CacheResult<()> { let mut conn = self.conn().clone(); conn.hset_multiple(key, items) .await .map_err(CacheError::from) } pub async fn hgetall( &self, key: &str, ) -> CacheResult> { let mut conn = self.conn().clone(); conn.hgetall(key).await.map_err(CacheError::from) } pub async fn hdel( &self, key: &str, fields: F, ) -> CacheResult { let mut conn = self.conn().clone(); conn.hdel(key, fields).await.map_err(CacheError::from) } pub async fn hexists(&self, key: &str, field: &str) -> CacheResult { let mut conn = self.conn().clone(); conn.hexists(key, field).await.map_err(CacheError::from) } pub async fn hlen(&self, key: &str) -> CacheResult { let mut conn = self.conn().clone(); conn.hlen(key).await.map_err(CacheError::from) } pub async fn hkeys(&self, key: &str) -> CacheResult> { let mut conn = self.conn().clone(); conn.hkeys(key).await.map_err(CacheError::from) } pub async fn hvals(&self, key: &str) -> CacheResult> { let mut conn = self.conn().clone(); conn.hvals(key).await.map_err(CacheError::from) } pub async fn hincr(&self, key: &str, field: &str, delta: i64) -> CacheResult { let mut conn = self.conn().clone(); conn.hincr(key, field, delta) .await .map_err(CacheError::from) } }