cache

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2025 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromExpiration

func FromExpiration(ctx context.Context) (time.Duration, bool)

FromExpiration returns the expiration time from the context

func FromKey

func FromKey(ctx context.Context) (string, bool)

FromKey returns the key from the context

func FromTag

func FromTag(ctx context.Context) (string, bool)

FromTag returns the tag from the context

func NewExpiration

func NewExpiration(ctx context.Context, ttl time.Duration) context.Context

NewExpiration creates a new context with the given expiration time

func NewKey

func NewKey(ctx context.Context, key string) context.Context

NewKey creates a new context with the given key

func NewTag

func NewTag(ctx context.Context, key string) context.Context

NewTag creates a new context with the given tag

func QueryDB

func QueryDB(tx *gorm.DB)

Types

type Message

type Message struct {
	redisqueue.Message
}

func (*Message) GetID

func (m *Message) GetID() string

func (*Message) GetPrefix

func (m *Message) GetPrefix() (prefix string)

func (*Message) GetStream

func (m *Message) GetStream() string

func (*Message) GetValues

func (m *Message) GetValues() map[string]any

func (*Message) SetID

func (m *Message) SetID(id string)

func (*Message) SetPrefix

func (m *Message) SetPrefix(prefix string)

func (*Message) SetStream

func (m *Message) SetStream(stream string)

func (*Message) SetValues

func (m *Message) SetValues(values map[string]any)

type Option

type Option func(*Options)

func WithQueryCacheDuration

func WithQueryCacheDuration(d time.Duration) Option

WithQueryCacheDuration 设置缓存时间

func WithQueryCacheKeys

func WithQueryCacheKeys(keys ...string) Option

WithQueryCacheKeys 设置缓存key

func WithQueryCachePrefix

func WithQueryCachePrefix(prefix string) Option

WithQueryCachePrefix 设置缓存前缀

type Options

type Options struct {
	QueryCacheDuration time.Duration
	QueryCacheKeys     []string
	QueryCachePrefix   string
}

func DefaultOptions

func DefaultOptions() Options

func (*Options) HasKey

func (o *Options) HasKey(key string) bool

type Redis

type Redis struct {
	redis.UniversalClient
	// contains filtered or unexported fields
}

Redis cache implement

func NewRedis

func NewRedis(client redis.UniversalClient, options *redis.UniversalOptions, opts ...Option) (*Redis, error)

NewRedis redis模式

func (*Redis) GetClient

func (r *Redis) GetClient() redis.UniversalClient

GetClient 暴露原生client

func (*Redis) Initialize

func (r *Redis) Initialize(tx *gorm.DB) error

func (*Redis) Name

func (*Redis) Name() string

func (*Redis) Query

func (r *Redis) Query(tx *gorm.DB)

func (*Redis) QueryCache

func (r *Redis) QueryCache(ctx context.Context, key string, dest any) error

func (*Redis) RemoveFromTag

func (r *Redis) RemoveFromTag(ctx context.Context, tag string) error

func (*Redis) SaveCache

func (r *Redis) SaveCache(ctx context.Context, key string, dest any, ttl time.Duration) error

func (*Redis) SaveTagKey

func (r *Redis) SaveTagKey(ctx context.Context, tag, key string) error

func (*Redis) String

func (*Redis) String() string

type VerifyCode

type VerifyCode struct {
	Cache storage.AdapterCache
}

func NewVerifyCode

func NewVerifyCode(cache storage.AdapterCache) *VerifyCode

NewVerifyCode create a new verify code

func (*VerifyCode) GenerateCode

func (v *VerifyCode) GenerateCode(ctx context.Context, key string, expire time.Duration) (string, error)

func (*VerifyCode) VerifyCode

func (v *VerifyCode) VerifyCode(ctx context.Context, key, code string) (bool, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL