redis

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2024 License: MIT Imports: 5 Imported by: 1

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 RdsClient

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

RdsClient Redis服务

var (
	Rds  *RdsClient
	Once sync.Once
)

rds 全局 Redis,使用 db 1

func NewClient

func NewClient(address string, username string, password string, db int) *RdsClient

NewClient 创建一个新的 redis 连接

func (*RdsClient) Decrement

func (rds *RdsClient) Decrement(params ...interface{}) bool

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

func (*RdsClient) Del

func (rds *RdsClient) Del(keys ...string) bool

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

func (*RdsClient) FlushDB

func (rds *RdsClient) FlushDB() bool

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

func (*RdsClient) Get

func (rds *RdsClient) Get(key string) string

Get 获取 key 对应的 value

func (*RdsClient) HGet

func (rds *RdsClient) HGet(key string, field string) string

HGet 获取hash元素

func (*RdsClient) Has

func (rds *RdsClient) Has(key string) bool

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

func (*RdsClient) Increment

func (rds *RdsClient) Increment(params ...interface{}) bool

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

func (*RdsClient) IsExists

func (rds *RdsClient) IsExists(key string) bool

IsExists 判断一个 key 是否存在

func (*RdsClient) LLen

func (rds *RdsClient) LLen(key string) int64

LLen 返回列表 key 的长度

func (*RdsClient) LPush

func (rds *RdsClient) LPush(key string, values ...interface{}) bool

LPush 将一个或多个值 value 插入到列表 key 的表头

func (*RdsClient) Ping

func (rds *RdsClient) Ping() error

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

func (*RdsClient) RPeek

func (rds *RdsClient) RPeek(key string) string

RPeek 返回队列 key 最后一个尾元素

func (*RdsClient) RPop

func (rds *RdsClient) RPop(key string) string

RPop 移除并返回列表 key 的尾元素

func (*RdsClient) SAdd

func (rds *RdsClient) SAdd(key string, values ...interface{}) bool

SAdd 存储无序集合

func (*RdsClient) SMembers

func (rds *RdsClient) SMembers(key string) []string

SMembers 获取一个无序集合的所有成员

func (*RdsClient) SRandMember

func (rds *RdsClient) SRandMember(key string) string

SRandMember 随机获取集合的元素

func (*RdsClient) Set

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

Set 存储 key 对应的 value,并设置 expiration 过期时间(单位:秒)

func (*RdsClient) ZAdd

func (rds *RdsClient) ZAdd(key string, values ...*redis.Z) bool

ZAdd 存储一个有序集合

func (*RdsClient) ZRange

func (rds *RdsClient) ZRange(key string) []string

ZRange 获取一个有序集合的所有成员

Jump to

Keyboard shortcuts

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