diff --git a/backend/services/connection_service.go b/backend/services/connection_service.go
index f5e2656..7921690 100644
--- a/backend/services/connection_service.go
+++ b/backend/services/connection_service.go
@@ -1330,7 +1330,7 @@ func (c *connectionService) SetKeyTTL(connName string, db int, k any, ttl int64)
}
// DeleteKey remove redis key
-func (c *connectionService) DeleteKey(connName string, db int, k any) (resp types.JSResp) {
+func (c *connectionService) DeleteKey(connName string, db int, k any, async bool) (resp types.JSResp) {
client, ctx, err := c.getRedisClient(connName, db)
if err != nil {
resp.Msg = err.Error()
@@ -1344,10 +1344,15 @@ func (c *connectionService) DeleteKey(connName string, db int, k any) (resp type
var mutex sync.Mutex
del := func(ctx context.Context, cli redis.UniversalClient) error {
iter := cli.Scan(ctx, 0, key, 10000).Iterator()
+ var fn func(c context.Context, ks ...string) *redis.IntCmd
+ if async {
+ fn = cli.Unlink
+ } else {
+ fn = cli.Del
+ }
for iter.Next(ctx) {
subKey := iter.Val()
- if err = cli.Unlink(ctx, subKey).Err(); err != nil {
- log.Println("unlink error", err.Error())
+ if err = fn(ctx, subKey).Err(); err != nil {
return err
} else {
mutex.Lock()
@@ -1373,10 +1378,16 @@ func (c *connectionService) DeleteKey(connName string, db int, k any) (resp type
}
} else {
// delete key only
- _, err = client.Del(ctx, key).Result()
- if err != nil {
- resp.Msg = err.Error()
- return
+ if async {
+ if _, err = client.Unlink(ctx, key).Result(); err != nil {
+ resp.Msg = err.Error()
+ return
+ }
+ } else {
+ if _, err = client.Del(ctx, key).Result(); err != nil {
+ resp.Msg = err.Error()
+ return
+ }
}
deletedKeys = append(deletedKeys, key)
}
diff --git a/frontend/src/components/dialogs/DeleteKeyDialog.vue b/frontend/src/components/dialogs/DeleteKeyDialog.vue
index 67d4022..c445ed4 100644
--- a/frontend/src/components/dialogs/DeleteKeyDialog.vue
+++ b/frontend/src/components/dialogs/DeleteKeyDialog.vue
@@ -12,6 +12,7 @@ const deleteForm = reactive({
showAffected: false,
loadingAffected: false,
affectedKeys: [],
+ async: true,
})
const dialogStore = useDialog()
@@ -27,6 +28,7 @@ watch(
deleteForm.showAffected = false
deleteForm.loadingAffected = false
deleteForm.affectedKeys = []
+ deleteForm.async = true
}
},
)
@@ -50,8 +52,8 @@ const resetAffected = () => {
const i18n = useI18n()
const onConfirmDelete = async () => {
try {
- const { server, db, key } = deleteForm
- const success = await connectionStore.deleteKeyPrefix(server, db, key)
+ const { server, db, key, async } = deleteForm
+ const success = await connectionStore.deleteKeyPrefix(server, db, key, async)
if (success) {
$message.success(i18n.t('dialogue.handle_succ'))
}
@@ -86,6 +88,9 @@ const onClose = () => {
+
+ {{ $t('dialogue.key.async_delete_title') }}
+
}
*/
- async deleteKeyPrefix(connName, db, prefix) {
+ async deleteKeyPrefix(connName, db, prefix, async) {
if (isEmpty(prefix)) {
return false
}
@@ -1492,7 +1493,7 @@ const useConnectionStore = defineStore('connections', {
if (!endsWith(prefix, '*')) {
prefix += '*'
}
- const { data, success, msg } = await DeleteKey(connName, db, prefix)
+ const { data, success, msg } = await DeleteKey(connName, db, prefix, async)
if (success) {
// const { deleted: keys = [] } = data
// for (const key of keys) {