feat(redis): support renaming keys
This commit is contained in:
21 files changed
+297
-2
No files matched your search
@@ -564,6 +564,7 @@ async fn main() {
|
||||
.route("/redis/load-more", post(routes::redis::load_more))
|
||||
.route("/redis/set-string", post(routes::redis::set_string))
|
||||
.route("/redis/delete-key", post(routes::redis::delete_key))
|
||||
.route("/redis/rename-key", post(routes::redis::rename_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))
|
||||
|
||||
@@ -76,6 +76,15 @@ pub struct RedisKeyRequest {
|
||||
pub key_raw: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RedisRenameKeyRequest {
|
||||
pub connection_id: String,
|
||||
pub db: u32,
|
||||
pub key_raw: String,
|
||||
pub new_key_raw: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RedisStreamEntriesRequest {
|
||||
@@ -484,6 +493,23 @@ pub async fn delete_key(
|
||||
Ok(Json(()))
|
||||
}
|
||||
|
||||
pub async fn rename_key(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<RedisRenameKeyRequest>,
|
||||
) -> Result<Json<()>, AppError> {
|
||||
ensure_writable(&state.app, &req.connection_id, "RENAMENX").await?;
|
||||
dbx_core::redis_ops::redis_rename_key_in_db_core(
|
||||
&state.app,
|
||||
&req.connection_id,
|
||||
req.db,
|
||||
&req.key_raw,
|
||||
&req.new_key_raw,
|
||||
)
|
||||
.await
|
||||
.map_err(AppError::from)?;
|
||||
Ok(Json(()))
|
||||
}
|
||||
|
||||
pub async fn hash_set(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<RedisHashRequest>,
|
||||
|
||||
Reference in new issue
Block a user