mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-31 16:24:33 +00:00
feat(redis): 修复全库键浏览与二进制展示
This commit is contained in:
+45
-17
@@ -27,14 +27,16 @@ pub struct RedisScanRequest {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RedisKeyRequest {
|
||||
pub connection_id: String,
|
||||
pub key: String,
|
||||
pub db: u32,
|
||||
pub key_raw: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RedisSetStringRequest {
|
||||
pub connection_id: String,
|
||||
pub key: String,
|
||||
pub db: u32,
|
||||
pub key_raw: String,
|
||||
pub value: String,
|
||||
pub ttl: Option<i64>,
|
||||
}
|
||||
@@ -43,7 +45,8 @@ pub struct RedisSetStringRequest {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RedisHashRequest {
|
||||
pub connection_id: String,
|
||||
pub key: String,
|
||||
pub db: u32,
|
||||
pub key_raw: String,
|
||||
pub field: String,
|
||||
pub value: Option<String>,
|
||||
}
|
||||
@@ -52,7 +55,8 @@ pub struct RedisHashRequest {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RedisListRequest {
|
||||
pub connection_id: String,
|
||||
pub key: String,
|
||||
pub db: u32,
|
||||
pub key_raw: String,
|
||||
pub value: Option<String>,
|
||||
pub index: Option<i64>,
|
||||
}
|
||||
@@ -61,7 +65,8 @@ pub struct RedisListRequest {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RedisSetRequest {
|
||||
pub connection_id: String,
|
||||
pub key: String,
|
||||
pub db: u32,
|
||||
pub key_raw: String,
|
||||
pub member: String,
|
||||
}
|
||||
|
||||
@@ -95,8 +100,9 @@ pub async fn get_value(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<RedisKeyRequest>,
|
||||
) -> Result<Json<serde_json::Value>, AppError> {
|
||||
let result =
|
||||
dbx_core::redis_ops::redis_get_value_core(&state.app, &req.connection_id, &req.key).await.map_err(AppError)?;
|
||||
let result = dbx_core::redis_ops::redis_get_value_in_db_core(&state.app, &req.connection_id, req.db, &req.key_raw)
|
||||
.await
|
||||
.map_err(AppError)?;
|
||||
Ok(Json(serde_json::to_value(result).map_err(|e| AppError(e.to_string()))?))
|
||||
}
|
||||
|
||||
@@ -104,9 +110,16 @@ pub async fn set_string(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<RedisSetStringRequest>,
|
||||
) -> Result<Json<()>, AppError> {
|
||||
dbx_core::redis_ops::redis_set_string_core(&state.app, &req.connection_id, &req.key, &req.value, req.ttl)
|
||||
.await
|
||||
.map_err(AppError)?;
|
||||
dbx_core::redis_ops::redis_set_string_in_db_core(
|
||||
&state.app,
|
||||
&req.connection_id,
|
||||
req.db,
|
||||
&req.key_raw,
|
||||
&req.value,
|
||||
req.ttl,
|
||||
)
|
||||
.await
|
||||
.map_err(AppError)?;
|
||||
Ok(Json(()))
|
||||
}
|
||||
|
||||
@@ -114,7 +127,9 @@ pub async fn delete_key(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<RedisKeyRequest>,
|
||||
) -> Result<Json<()>, AppError> {
|
||||
dbx_core::redis_ops::redis_delete_key_core(&state.app, &req.connection_id, &req.key).await.map_err(AppError)?;
|
||||
dbx_core::redis_ops::redis_delete_key_in_db_core(&state.app, &req.connection_id, req.db, &req.key_raw)
|
||||
.await
|
||||
.map_err(AppError)?;
|
||||
Ok(Json(()))
|
||||
}
|
||||
|
||||
@@ -123,7 +138,14 @@ pub async fn hash_set(
|
||||
Json(req): Json<RedisHashRequest>,
|
||||
) -> Result<Json<()>, AppError> {
|
||||
let value = req.value.as_deref().unwrap_or("");
|
||||
dbx_core::redis_ops::redis_hash_set_core(&state.app, &req.connection_id, &req.key, &req.field, value)
|
||||
dbx_core::redis_ops::redis_hash_set_in_db_core(
|
||||
&state.app,
|
||||
&req.connection_id,
|
||||
req.db,
|
||||
&req.key_raw,
|
||||
&req.field,
|
||||
value,
|
||||
)
|
||||
.await
|
||||
.map_err(AppError)?;
|
||||
Ok(Json(()))
|
||||
@@ -133,7 +155,7 @@ pub async fn hash_del(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<RedisHashRequest>,
|
||||
) -> Result<Json<()>, AppError> {
|
||||
dbx_core::redis_ops::redis_hash_del_core(&state.app, &req.connection_id, &req.key, &req.field)
|
||||
dbx_core::redis_ops::redis_hash_del_in_db_core(&state.app, &req.connection_id, req.db, &req.key_raw, &req.field)
|
||||
.await
|
||||
.map_err(AppError)?;
|
||||
Ok(Json(()))
|
||||
@@ -144,7 +166,7 @@ pub async fn list_push(
|
||||
Json(req): Json<RedisListRequest>,
|
||||
) -> Result<Json<()>, AppError> {
|
||||
let value = req.value.as_deref().unwrap_or("");
|
||||
dbx_core::redis_ops::redis_list_push_core(&state.app, &req.connection_id, &req.key, value)
|
||||
dbx_core::redis_ops::redis_list_push_in_db_core(&state.app, &req.connection_id, req.db, &req.key_raw, value)
|
||||
.await
|
||||
.map_err(AppError)?;
|
||||
Ok(Json(()))
|
||||
@@ -155,7 +177,7 @@ pub async fn list_remove(
|
||||
Json(req): Json<RedisListRequest>,
|
||||
) -> Result<Json<()>, AppError> {
|
||||
let index = req.index.unwrap_or(0);
|
||||
dbx_core::redis_ops::redis_list_remove_core(&state.app, &req.connection_id, &req.key, index)
|
||||
dbx_core::redis_ops::redis_list_remove_in_db_core(&state.app, &req.connection_id, req.db, &req.key_raw, index)
|
||||
.await
|
||||
.map_err(AppError)?;
|
||||
Ok(Json(()))
|
||||
@@ -165,7 +187,7 @@ pub async fn set_add(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<RedisSetRequest>,
|
||||
) -> Result<Json<()>, AppError> {
|
||||
dbx_core::redis_ops::redis_set_add_core(&state.app, &req.connection_id, &req.key, &req.member)
|
||||
dbx_core::redis_ops::redis_set_add_in_db_core(&state.app, &req.connection_id, req.db, &req.key_raw, &req.member)
|
||||
.await
|
||||
.map_err(AppError)?;
|
||||
Ok(Json(()))
|
||||
@@ -175,7 +197,13 @@ pub async fn set_remove(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<RedisSetRequest>,
|
||||
) -> Result<Json<()>, AppError> {
|
||||
dbx_core::redis_ops::redis_set_remove_core(&state.app, &req.connection_id, &req.key, &req.member)
|
||||
dbx_core::redis_ops::redis_set_remove_in_db_core(
|
||||
&state.app,
|
||||
&req.connection_id,
|
||||
req.db,
|
||||
&req.key_raw,
|
||||
&req.member,
|
||||
)
|
||||
.await
|
||||
.map_err(AppError)?;
|
||||
Ok(Json(()))
|
||||
|
||||
Reference in New Issue
Block a user