51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
// Package cache -----------------------------
|
|
// @file : redis_test.go
|
|
// @author : JJXu
|
|
// @contact : wavingbear@163.com
|
|
// @time : 2023/11/28 10:27
|
|
// -------------------------------------------
|
|
package cache
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"github.com/go-redis/redis"
|
|
"testing"
|
|
)
|
|
|
|
// RedisDB = 2
|
|
// RedisAddr = svc-fontree-redis-service:6379
|
|
// RedisPW = "fonchain_opv:kP6tW4tS3qB2dW4aE6uI5cX2"
|
|
func Test_connRedis(t *testing.T) {
|
|
RedisClient = redis.NewClient(&redis.Options{
|
|
Addr: "https://svc-fontree-redis-service:6379",
|
|
Password: "fonchain_opv:kP6tW4tS3qB2dW4aE6uI5cX2",
|
|
DB: 2,
|
|
})
|
|
_, err := RedisClient.Ping().Result()
|
|
if err != nil {
|
|
t.Error(err)
|
|
return
|
|
}
|
|
var cacheBytes []byte
|
|
var cacheData = make(map[string]map[string]*artistInfoArtwork.TempSaveReviewStatusData)
|
|
val := RedisClient.Get("artistinfo:review_artwok_base")
|
|
if val.Err() == nil {
|
|
err2 := val.Scan(&cacheBytes)
|
|
if err2 != nil {
|
|
fmt.Println("redis scan error", err2.Error())
|
|
return
|
|
}
|
|
err2 = json.Unmarshal(cacheBytes, &cacheData)
|
|
if err2 != nil {
|
|
fmt.Println("cache bytes unmarshall error", err2)
|
|
return
|
|
}
|
|
}
|
|
if _, ok := cacheData["30e7e34e-88ce-43ab-812f-f12095336888"]; ok {
|
|
fmt.Println("have cache:true")
|
|
} else {
|
|
fmt.Println("have cache:false")
|
|
}
|
|
}
|