Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-common
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujiebin
hilo-common
Commits
5815efc1
Commit
5815efc1
authored
Mar 05, 2024
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update clear_redis.go
parent
8601ecaa
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
9 deletions
+37
-9
clear_redis.go
script/clear_redis.go
+37
-9
No files found.
script/clear_redis.go
View file @
5815efc1
...
@@ -4,7 +4,9 @@ import (
...
@@ -4,7 +4,9 @@ import (
"context"
"context"
"fmt"
"fmt"
"github.com/go-redis/redis/v8"
"github.com/go-redis/redis/v8"
"github.com/spf13/cast"
"log"
"log"
"strings"
)
)
const
redisAddr
=
"172.28.16.31:6379"
// 替换为你的Redis地址
const
redisAddr
=
"172.28.16.31:6379"
// 替换为你的Redis地址
...
@@ -32,10 +34,10 @@ func main() {
...
@@ -32,10 +34,10 @@ func main() {
println
(
len
(
keys
))
println
(
len
(
keys
))
// 删除所有匹配的键
// 删除所有匹配的键
//
err = deleteKeys(client, keys)
err
=
deleteKeys
(
client
,
keys
)
//
if err != nil {
if
err
!=
nil
{
//
log.Fatalf("Failed to delete keys: %v", err)
log
.
Fatalf
(
"Failed to delete keys: %v"
,
err
)
//
}
}
fmt
.
Println
(
"Cleanup completed."
)
fmt
.
Println
(
"Cleanup completed."
)
}
}
...
@@ -65,14 +67,40 @@ func getKeysWithPrefix(client *redis.Client, prefix string) ([]string, error) {
...
@@ -65,14 +67,40 @@ func getKeysWithPrefix(client *redis.Client, prefix string) ([]string, error) {
}
}
// 删除指定的键
// 删除指定的键
// 谨慎打开删除动作
func
deleteKeys
(
client
*
redis
.
Client
,
keys
[]
string
)
error
{
func
deleteKeys
(
client
*
redis
.
Client
,
keys
[]
string
)
error
{
ctx
:=
context
.
Background
()
//
ctx := context.Background()
for
_
,
key
:=
range
keys
{
for
index
,
key
:=
range
keys
{
err
:=
client
.
Del
(
ctx
,
key
)
.
Err
()
if
strings
.
Contains
(
key
,
"autochooses"
)
{
if
err
!=
nil
{
arr
:=
strings
.
Split
(
key
,
"-"
)
return
err
if
len
(
arr
)
<
3
{
log
.
Fatalf
(
"illgal"
)
}
if
cast
.
ToInt
(
arr
[
2
])
>=
837395
{
log
.
Printf
(
"skip skip skip key:%v,index:%v
\n
"
,
key
,
index
)
continue
}
}
}
else
if
strings
.
Contains
(
key
,
"choose_user"
)
{
arr
:=
strings
.
Split
(
key
,
":"
)
if
len
(
arr
)
<
3
{
log
.
Fatalf
(
"illgal"
)
}
arr2
:=
strings
.
Split
(
arr
[
1
],
"-"
)
if
len
(
arr2
)
<
3
{
log
.
Fatalf
(
"illgal"
)
}
if
cast
.
ToInt
(
arr2
[
2
])
>=
837395
{
log
.
Printf
(
"skip skip skip key:%v,index:%v
\n
"
,
key
,
index
)
continue
}
}
// 打开del操作
//err := client.Del(ctx, key).Err()
//if err != nil {
// return err
//}
log
.
Printf
(
"key:%v,index:%v
\n
"
,
key
,
index
)
}
}
return
nil
return
nil
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment