package main
import (
"fmt"
"log"
"github.com/go-redis/redis/v8"
)
func main() {
// 创建Redis客户端
client := redis.NewClient(&redis.Options{
Addr: "localhost:6379", // Redis服务器地址
Password: "", // Redis服务器密码
DB: 0, // 使用默认的数据库
})
//上下文对象
var ctx = context.Background()
// 使用Scan方法遍历所有键
iter := client.Scan(ctx, 0, "*", 0).Iterator()
for iter.Next(ctx) {
key := iter.Val()
fmt.Println(key)
}
}
go-redis获取所有key
最新推荐文章于 2024-01-24 16:47:27 发布