feat(redis): add local expiration modes
This commit is contained in:
1 parent
3a2dc4225a
commit
51fa058edb
35 files changed
+2918
-98
No files matched your search
@@ -435,6 +435,8 @@ async fn main() {
|
||||
.route("/redis/stream-add", post(routes::redis::stream_add))
|
||||
.route("/redis/json-set", post(routes::redis::json_set))
|
||||
.route("/redis/check-json-module", post(routes::redis::check_json_module))
|
||||
.route("/redis/set-ttl", post(routes::redis::set_ttl))
|
||||
.route("/redis/set-expire-at", post(routes::redis::set_expire_at))
|
||||
.route("/redis/delete-keys", post(routes::redis::delete_keys))
|
||||
.route("/redis/flush-db", post(routes::redis::flush_db))
|
||||
.route("/redis/execute-command", post(routes::redis::execute_command))
|
||||
|
||||
@@ -162,6 +162,24 @@ pub struct RedisJsonSetRequest {
|
||||
pub ttl: Option<i64>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RedisSetTtlRequest {
|
||||
pub connection_id: String,
|
||||
pub db: u32,
|
||||
pub key_raw: String,
|
||||
pub ttl: i64,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RedisSetExpireAtRequest {
|
||||
pub connection_id: String,
|
||||
pub db: u32,
|
||||
pub key_raw: String,
|
||||
pub expire_at: i64,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RedisKeysRequest {
|
||||
@@ -437,6 +455,7 @@ pub async fn set_remove(
|
||||
}
|
||||
|
||||
pub async fn zadd(State(state): State<Arc<WebState>>, Json(req): Json<RedisZaddRequest>) -> Result<Json<()>, AppError> {
|
||||
ensure_writable(&state.app, &req.connection_id, "ZADD").await?;
|
||||
dbx_core::redis_ops::redis_zadd_in_db_core(
|
||||
&state.app,
|
||||
&req.connection_id,
|
||||
@@ -455,6 +474,7 @@ pub async fn stream_add(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<RedisStreamAddRequest>,
|
||||
) -> Result<Json<()>, AppError> {
|
||||
ensure_writable(&state.app, &req.connection_id, "XADD").await?;
|
||||
dbx_core::redis_ops::redis_stream_add_in_db_core(
|
||||
&state.app,
|
||||
&req.connection_id,
|
||||
@@ -473,6 +493,7 @@ pub async fn json_set(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<RedisJsonSetRequest>,
|
||||
) -> Result<Json<()>, AppError> {
|
||||
ensure_writable(&state.app, &req.connection_id, "JSON.SET").await?;
|
||||
dbx_core::redis_ops::redis_json_set_in_db_core(
|
||||
&state.app,
|
||||
&req.connection_id,
|
||||
@@ -496,6 +517,34 @@ pub async fn check_json_module(
|
||||
Ok(Json(result))
|
||||
}
|
||||
|
||||
pub async fn set_ttl(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<RedisSetTtlRequest>,
|
||||
) -> Result<Json<()>, AppError> {
|
||||
ensure_writable(&state.app, &req.connection_id, "EXPIRE").await?;
|
||||
dbx_core::redis_ops::redis_set_ttl_in_db_core(&state.app, &req.connection_id, req.db, &req.key_raw, req.ttl)
|
||||
.await
|
||||
.map_err(AppError::from)?;
|
||||
Ok(Json(()))
|
||||
}
|
||||
|
||||
pub async fn set_expire_at(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<RedisSetExpireAtRequest>,
|
||||
) -> Result<Json<()>, AppError> {
|
||||
ensure_writable(&state.app, &req.connection_id, "EXPIREAT").await?;
|
||||
dbx_core::redis_ops::redis_set_expire_at_in_db_core(
|
||||
&state.app,
|
||||
&req.connection_id,
|
||||
req.db,
|
||||
&req.key_raw,
|
||||
req.expire_at,
|
||||
)
|
||||
.await
|
||||
.map_err(AppError::from)?;
|
||||
Ok(Json(()))
|
||||
}
|
||||
|
||||
pub async fn delete_keys(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<RedisKeysRequest>,
|
||||
|
||||
Reference in new issue
Block a user