wtredis

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package cache 缓存工具类,可以缓存各种类型包括 struct 对象

Package wtredis 工具包

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectRedis

func ConnectRedis()

ConnectRedis 连接 redis 数据库,设置全局的 Redis 对象

func ConnectRedisCache added in v1.0.1

func ConnectRedisCache()

func Decrement

func Decrement(parameters ...interface{})

func Delete

func Delete(key string) bool

func Exist

func Exist(key ...string) bool

func Flush

func Flush()

func Forever

func Forever(key string, value string)

func Forget

func Forget(key string)

func Get

func Get(key string) interface{}

func GetToBool

func GetToBool(key string) bool

func GetToDuration

func GetToDuration(key string) time.Duration

func GetToFloat64

func GetToFloat64(key string) float64

func GetToInt

func GetToInt(key string) int

func GetToInt32

func GetToInt32(key string) int32

func GetToInt64

func GetToInt64(key string) int64

func GetToIntSlice

func GetToIntSlice(key string) []int

func GetToObject

func GetToObject(key string, wanted interface{})

GetToObject 应该传地址,用法如下:

model := user.User{}
cache.GetObject("key", &model)

func GetToString

func GetToString(key string) string

func GetToStringMap

func GetToStringMap(key string) map[string]interface{}

func GetToStringMapString

func GetToStringMapString(key string) map[string]string

func GetToStringMapStringSlice

func GetToStringMapStringSlice(key string) map[string][]string

func GetToStringSlice

func GetToStringSlice(key string) []string

func GetToTime

func GetToTime(key string) time.Time

func GetToUint

func GetToUint(key string) uint

func GetToUint32

func GetToUint32(key string) uint32

func GetToUint64

func GetToUint64(key string) uint64

func Has

func Has(key string) bool

func Increment

func Increment(parameters ...interface{})

func IsAlive

func IsAlive() error

func IsRedisNilErr

func IsRedisNilErr(err error) bool

func PreDelAll

func PreDelAll(pre string) error

func Set

func Set(key string, obj interface{}, expireTime time.Duration)

func SetString

func SetString(key string, val string, expireTime time.Duration)

Types

type CacheService

type CacheService struct {
	Store Store
}
var Cache *CacheService

type RedisClient

type RedisClient struct {
	Client  *redis.Client
	Context context.Context
}

RedisClient Redis 服务

var Redis *RedisClient

Redis 全局 Redis,使用 db 1

func NewCacheClient added in v1.0.1

func NewCacheClient() *RedisClient

NewCacheClient 创建一个新的 redis 连接

func NewClient

func NewClient() *RedisClient

NewClient 创建一个新的 redis 连接

func (RedisClient) Decrement

func (rds RedisClient) Decrement(parameters ...interface{}) bool

Decrement 当参数只有 1 个时,为 key,其值减去 1。 当参数有 2 个时,第一个参数为 key ,第二个参数为要减去的值 int64 类型。

func (RedisClient) Del

func (rds RedisClient) Del(keys ...string) bool

Del 删除存储在 redis 里的数据,支持多个 key 传参

func (RedisClient) Exist

func (rds RedisClient) Exist(key ...string) bool

func (RedisClient) FlushDB

func (rds RedisClient) FlushDB() bool

FlushDB 清空当前 redis db 里的所有数据

func (RedisClient) Get

func (rds RedisClient) Get(key string) string

Get 获取 key 对应的 value

func (RedisClient) GetInBy

func (rds RedisClient) GetInBy(key string) string

func (RedisClient) GetToObject

func (rds RedisClient) GetToObject(key string, wanted interface{})

func (RedisClient) Has

func (rds RedisClient) Has(key string) bool

Has 判断一个 key 是否存在,内部错误和 redis.Nil 都返回 false

func (RedisClient) Increment

func (rds RedisClient) Increment(parameters ...interface{}) bool

Increment 当参数只有 1 个时,为 key,其值增加 1。 当参数有 2 个时,第一个参数为 key ,第二个参数为要增加的值 int64 类型。

func (RedisClient) LockLucky

func (rds RedisClient) LockLucky(key string) bool

func (RedisClient) MGet

func (rds RedisClient) MGet(keys ...string) (result []interface{})

MGet 获取 key 对应的 value

func (RedisClient) MSet

func (rds RedisClient) MSet(keyValue map[string]interface{}) bool

func (RedisClient) MSetObj

func (rds RedisClient) MSetObj(keyValue map[string]interface{}) bool

func (RedisClient) Ping

func (rds RedisClient) Ping() error

Ping 用以测试 redis 连接是否正常

func (RedisClient) Set

func (rds RedisClient) Set(key string, value interface{}, expiration time.Duration) bool

Set 存储 key 对应的 value,且设置 expiration 过期时间

func (RedisClient) SetExpiration

func (rds RedisClient) SetExpiration(key string, expiration time.Duration) bool

SetExpiration 设置 key 对应的 过期时间,且设置 expiration 过期时间

func (RedisClient) SetObj

func (rds RedisClient) SetObj(key string, obj interface{}, expireTime time.Duration)

func (RedisClient) UnLockLucky

func (rds RedisClient) UnLockLucky(key string) bool

type RedisStore

type RedisStore struct {
	RedisClient *RedisClient
	KeyPrefix   string
}

RedisStore 实现 cache.Store interface

func (*RedisStore) Decrement

func (s *RedisStore) Decrement(parameters ...interface{})

func (*RedisStore) Delete

func (s *RedisStore) Delete(key string) bool

func (*RedisStore) Exist

func (s *RedisStore) Exist(key ...string) bool

func (*RedisStore) Flush

func (s *RedisStore) Flush()

func (*RedisStore) Forever

func (s *RedisStore) Forever(key string, value string)

func (*RedisStore) Forget

func (s *RedisStore) Forget(key string)

func (*RedisStore) Get

func (s *RedisStore) Get(key string) string

func (*RedisStore) Has

func (s *RedisStore) Has(key string) bool

func (*RedisStore) Increment

func (s *RedisStore) Increment(parameters ...interface{})

func (*RedisStore) IsAlive

func (s *RedisStore) IsAlive() error

func (*RedisStore) PreDelAll

func (s *RedisStore) PreDelAll(pre string) error

func (*RedisStore) Set

func (s *RedisStore) Set(key string, value string, expireTime time.Duration)

type Store

type Store interface {
	Set(key string, value string, expireTime time.Duration)
	Get(key string) string
	Has(key string) bool
	Delete(key string) bool
	Forget(key string)
	Forever(key string, value string)
	Flush()
	PreDelAll(pre string) error

	IsAlive() error

	// Increment 当参数只有 1 个时,为 key,增加 1。
	// 当参数有 2 个时,第一个参数为 key ,第二个参数为要增加的值 int64 类型。
	Increment(parameters ...interface{})

	// Decrement 当参数只有 1 个时,为 key,减去 1。
	// 当参数有 2 个时,第一个参数为 key ,第二个参数为要减去的值 int64 类型。
	Decrement(parameters ...interface{})

	Exist(key ...string) bool
}

Jump to

Keyboard shortcuts

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