cache

package
v0.4.8 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromExpiration added in v0.3.7

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

FromExpiration returns the expiration time from the context

func FromKey added in v0.3.7

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

FromKey returns the key from the context

func FromTag added in v0.3.7

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

FromTag returns the tag from the context

func NewExpiration added in v0.3.7

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

NewExpiration creates a new context with the given expiration time

func NewKey added in v0.3.7

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

NewKey creates a new context with the given key

func NewTag added in v0.3.7

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

NewTag creates a new context with the given tag

func QueryDB added in v0.3.7

func QueryDB(tx *gorm.DB)

Types

type Memory

type Memory struct {
	// contains filtered or unexported fields
}

func NewMemory

func NewMemory(options ...Option) *Memory

NewMemory memory模式

func (*Memory) Decrease

func (m *Memory) Decrease(_ context.Context, key string) error

func (*Memory) Del

func (m *Memory) Del(_ context.Context, key string) error

func (*Memory) Expire

func (m *Memory) Expire(_ context.Context, key string, dur time.Duration) error

func (*Memory) Get

func (m *Memory) Get(_ context.Context, key string) (string, error)

func (*Memory) HashDel

func (m *Memory) HashDel(_ context.Context, hk, key string) error

func (*Memory) HashGet

func (m *Memory) HashGet(_ context.Context, hk, key string) (string, error)

func (*Memory) Increase

func (m *Memory) Increase(_ context.Context, key string) error

func (*Memory) Initialize added in v0.3.7

func (m *Memory) Initialize(tx *gorm.DB) error

func (*Memory) Name added in v0.3.7

func (*Memory) Name() string

func (*Memory) Query added in v0.3.7

func (m *Memory) Query(tx *gorm.DB)

func (*Memory) QueryCache added in v0.3.7

func (m *Memory) QueryCache(ctx context.Context, key string, dest any) error

func (*Memory) RemoveFromTag added in v0.3.7

func (m *Memory) RemoveFromTag(ctx context.Context, tag string) error

func (*Memory) SaveCache added in v0.3.7

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

func (*Memory) SaveTagKey added in v0.3.7

func (m *Memory) SaveTagKey(ctx context.Context, tag, key string) error

func (*Memory) Set

func (m *Memory) Set(_ context.Context, key string, val any, expire time.Duration) error

func (*Memory) String

func (*Memory) String() string

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]interface{}

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]interface{})

type Option added in v0.3.7

type Option func(*Options)

func WithQueryCacheDuration added in v0.3.7

func WithQueryCacheDuration(d time.Duration) Option

WithQueryCacheDuration 设置缓存时间

func WithQueryCacheKeys added in v0.3.7

func WithQueryCacheKeys(keys ...string) Option

WithQueryCacheKeys 设置缓存key

func WithQueryCachePrefix added in v0.3.7

func WithQueryCachePrefix(prefix string) Option

WithQueryCachePrefix 设置缓存前缀

type Options added in v0.3.7

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

func DefaultOptions added in v0.3.7

func DefaultOptions() Options

func (*Options) HasKey added in v0.3.7

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

type Redis

type Redis struct {
	// contains filtered or unexported fields
}

Redis cache implement

func NewRedis

func NewRedis(client *redis.Client, options *redis.Options, opts ...Option) (*Redis, error)

NewRedis redis模式

func (*Redis) Decrease

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

func (*Redis) Del

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

Del delete key in redis

func (*Redis) Expire

func (r *Redis) Expire(ctx context.Context, key string, dur time.Duration) error

Expire Set ttl

func (*Redis) Get

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

Get from key

func (*Redis) GetClient

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

GetClient 暴露原生client

func (*Redis) HashDel

func (r *Redis) HashDel(ctx context.Context, hk, key string) error

HashDel delete key in specify redis's hashtable

func (*Redis) HashGet

func (r *Redis) HashGet(ctx context.Context, hk, key string) (string, error)

HashGet from key

func (*Redis) Increase

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

Increase key's value

func (*Redis) Initialize added in v0.3.7

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

func (*Redis) Name added in v0.3.7

func (*Redis) Name() string

func (*Redis) Query added in v0.3.7

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

func (*Redis) QueryCache added in v0.3.7

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

func (*Redis) RemoveFromTag added in v0.3.7

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

func (*Redis) SaveCache added in v0.3.7

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

func (*Redis) SaveTagKey added in v0.3.7

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

func (*Redis) Set

func (r *Redis) Set(ctx context.Context, key string, val interface{}, expire time.Duration) error

Set value with key and expire time

func (*Redis) String

func (*Redis) String() string

type VerifyCode added in v0.4.6

type VerifyCode struct {
	Cache storage.AdapterCache
}

func NewVerifyCode added in v0.4.6

func NewVerifyCode(cache storage.AdapterCache) *VerifyCode

NewVerifyCode create a new verify code

func (*VerifyCode) GenerateCode added in v0.4.6

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

func (*VerifyCode) VerifyCode added in v0.4.6

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