feat(redis): view and edit Hash field expiry (HEXPIRE/HTTL/HPERSIST)

This commit is contained in:
二丫讲梵 authored and GitHub committed 2026-08-07 02:41:04 +08:00
1 parent f8b2924f42
commit 59187f2e41
12 files changed
+583 -16

No files matched your search

+2
View File
@@ -507,6 +507,8 @@ async fn main() {
.route("/redis/delete-key", post(routes::redis::delete_key))
.route("/redis/hash-set", post(routes::redis::hash_set))
.route("/redis/hash-del", post(routes::redis::hash_del))
.route("/redis/hash-field-set-ttl", post(routes::redis::hash_field_set_ttl))
.route("/redis/hash-field-set-expire-at", post(routes::redis::hash_field_set_expire_at))
.route("/redis/list-push", post(routes::redis::list_push))
.route("/redis/list-set", post(routes::redis::list_set))
.route("/redis/list-remove", post(routes::redis::list_remove))
+56
View File
@@ -139,6 +139,26 @@ pub struct RedisHashRequest {
pub ttl: Option<i64>,
}
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RedisHashFieldTtlRequest {
pub connection_id: String,
pub db: u32,
pub key_raw: String,
pub field: String,
pub ttl: i64,
}
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RedisHashFieldExpireAtRequest {
pub connection_id: String,
pub db: u32,
pub key_raw: String,
pub field: String,
pub expire_at: i64,
}
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RedisZaddRequest {
@@ -495,6 +515,42 @@ pub async fn hash_del(
Ok(Json(()))
}
pub async fn hash_field_set_ttl(
State(state): State<Arc<WebState>>,
Json(req): Json<RedisHashFieldTtlRequest>,
) -> Result<Json<()>, AppError> {
ensure_writable(&state.app, &req.connection_id, "HEXPIRE").await?;
dbx_core::redis_ops::redis_hash_field_set_ttl_in_db_core(
&state.app,
&req.connection_id,
req.db,
&req.key_raw,
&req.field,
req.ttl,
)
.await
.map_err(AppError::from)?;
Ok(Json(()))
}
pub async fn hash_field_set_expire_at(
State(state): State<Arc<WebState>>,
Json(req): Json<RedisHashFieldExpireAtRequest>,
) -> Result<Json<()>, AppError> {
ensure_writable(&state.app, &req.connection_id, "HEXPIREAT").await?;
dbx_core::redis_ops::redis_hash_field_set_expire_at_in_db_core(
&state.app,
&req.connection_id,
req.db,
&req.key_raw,
&req.field,
req.expire_at,
)
.await
.map_err(AppError::from)?;
Ok(Json(()))
}
pub async fn list_push(
State(state): State<Arc<WebState>>,
Json(req): Json<RedisListRequest>,