cachekey

package
v1.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

README

缓存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
}

Documentation

Overview

Created by guoxin in 2024/1/15 11:25

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheKey

type CacheKey struct {
	Pattern    string
	Expiration int
}

func New

func New(pattern string, expiration int) *CacheKey

New @Description: 初始化 CacheKey @param pattern @param expiration @return *CacheKey

func (*CacheKey) GetExpiration

func (k *CacheKey) GetExpiration() int

GetExpiration 获取缓存的过期时间

func (*CacheKey) GetKey

func (k *CacheKey) GetKey(args ...any) string

GetKey 获取缓存的key

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳