redis

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2023 License: MIT Imports: 5 Imported by: 3

Documentation

Overview

Package redis 工具包

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectRedis

func ConnectRedis(address string, username string, password string, db int)

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

Types

type RedisClient

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

RedisClient Redis 服务

var Redis *RedisClient

Redis 全局 Redis,使用 db 1

func NewClient

func NewClient(address string, username string, password string, db int) *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) FlushDB

func (rds RedisClient) FlushDB() bool

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

func (RedisClient) Get

func (rds RedisClient) Get(key string) string

Get 获取 key 对应的 value

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) 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 过期时间

Jump to

Keyboard shortcuts

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