2022-10-21 18:50:38 +08:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
2022-10-31 17:26:15 +08:00
|
|
|
"time"
|
2022-10-21 18:50:38 +08:00
|
|
|
|
2022-10-31 17:26:15 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
|
|
|
"github.com/go-redis/redis"
|
2022-10-21 18:50:38 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMysql(t *testing.T) {
|
2022-10-31 17:26:15 +08:00
|
|
|
client := redis.NewClient(&redis.Options{
|
|
|
|
Addr: "localhost:6379",
|
|
|
|
Password: "eYVX7EwVmmxKPCDmwMtyKVge8oLd2t81",
|
|
|
|
DB: 0,
|
|
|
|
})
|
|
|
|
// fmt.Println(rdb.Get("dqwas"))
|
2022-10-27 23:09:39 +08:00
|
|
|
|
2022-10-31 17:26:15 +08:00
|
|
|
client.Set("omg", "111", 10*time.Minute)
|
|
|
|
client.Set("omg1", "111", 10*time.Minute)
|
|
|
|
client.Set("omg2", "111", 10*time.Minute)
|
|
|
|
client.Set("omg3", "111", 10*time.Minute)
|
|
|
|
client.Set("omg4", "111", 10*time.Minute)
|
|
|
|
client.Set("omg5", "111", 10*time.Minute)
|
|
|
|
client.Set("omg6", "111", 10*time.Minute)
|
|
|
|
client.Set("omg7", "111", 10*time.Minute)
|
|
|
|
client.Set("omg8", "111", 10*time.Minute)
|
|
|
|
client.Set("omg9", "111", 10*time.Minute)
|
|
|
|
keys, _, err := client.Scan(0, "*", 5).Result()
|
2022-10-21 18:50:38 +08:00
|
|
|
if err != nil {
|
2022-10-31 17:26:15 +08:00
|
|
|
panic(err)
|
2022-10-21 18:50:38 +08:00
|
|
|
}
|
2022-10-25 11:41:19 +08:00
|
|
|
|
2022-10-31 17:26:15 +08:00
|
|
|
var data []dto.RedisData
|
|
|
|
for _, key := range keys {
|
|
|
|
var dataItem dto.RedisData
|
|
|
|
dataItem.Key = key
|
|
|
|
value, err := client.Get(key).Result()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
dataItem.Value = value
|
|
|
|
typeVal, err := client.Type(key).Result()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
dataItem.Type = typeVal
|
|
|
|
length, err := client.StrLen(key).Result()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
dataItem.Length = length
|
|
|
|
ttl, err := client.TTL(key).Result()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
dataItem.Expiration = int64(ttl / 1000000000)
|
|
|
|
data = append(data, dataItem)
|
|
|
|
}
|
|
|
|
fmt.Println(data)
|
2022-10-25 11:41:19 +08:00
|
|
|
}
|