缓存key组件
1. 介绍
1.1 获取缓存的key
GetKey(args ...any) string
1.2 Expiration() int
Expiration() int
2. 使用
package cachekey
import (
"github.com/test-go/testify/assert"
"testing"
)
var (
CacheKeyApplyDID = CacheKey{
Pattern: "did_apply_did_%s",
Expiration: 60 * 10,
}
)
func TestCacheKey_Expiration(t *testing.T) {
key := CacheKeyApplyDID.GetKey("did:cnbn:1234567890qwertyuiopasdfghjklzxcvbnm")
expiration := CacheKeyApplyDID.GetExpiration()
t.Log("key: ", key)
t.Log("expiration: ", expiration)
assert.Equal(t, "did_apply_did_did:cnbn:1234567890qwertyuiopasdfghjklzxcvbnm", key, "The strings should be equal")
assert.Equal(t, 60*10, expiration, "The strings should be equal")
}
3. 例子
err := RedisInstance.Setex(key.CacheKeyApplyDID.GetKey(did), docPlantext, key.CacheKeyApplyDID.GetExpiration())
if err != nil {
return nil, err
}