redis

package
v0.0.0-...-d8850a5 Latest Latest
Warning

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

Go to latest
Published: May 1, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

reids

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetRedisInstance

func SetRedisInstance(dbName string, instance []RedisInstance)

SetRedisInstance 设置实例

Types

type RedisInstance

type RedisInstance struct {
	Client *redis.Client
}

RedisInstance reids客户端对象

func GetRedisInstance

func GetRedisInstance(dbName string) (*RedisInstance, error)

GetRedisInstance 获取redis实例

func (*RedisInstance) Decr

func (r *RedisInstance) Decr(ctx context.Context, key string) (int64, error)

Decr 减少

func (*RedisInstance) DecrBy

func (r *RedisInstance) DecrBy(ctx context.Context, key string, decrAmount int64) (int64, error)

Decr 减少N

func (*RedisInstance) Del

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

Del 删除

func (*RedisInstance) Expire

func (r *RedisInstance) Expire(ctx context.Context, key string, expire int) error

Expire 设置键过期时间,expire的单位为秒

func (*RedisInstance) Get

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

Get 获取值:Set("key")

func (*RedisInstance) GetString

func (r *RedisInstance) GetString(ctx context.Context, key string) (string, error)

GetString 获取值的字符串

func (*RedisInstance) Hdel

func (r *RedisInstance) Hdel(ctx context.Context, key, field string) (int64, error)

Hdel 删除

func (*RedisInstance) Hget

func (r *RedisInstance) Hget(ctx context.Context, key, field string) (string, error)

Hget 获取hash键的值

func (*RedisInstance) Hgetall

func (r *RedisInstance) Hgetall(ctx context.Context, key string) (map[string]string, error)

Hgetall 获取所有的hash值

func (*RedisInstance) Hincrby

func (r *RedisInstance) Hincrby(ctx context.Context, key, field string, incrAmount int64) (int64, error)

Hincrby 为哈希表 key 中的指定字段的整数值加上增量 increment

func (*RedisInstance) Hkeys

func (r *RedisInstance) Hkeys(ctx context.Context, key string) ([]string, error)

Hkeys 获取哈希表中的所有字段

func (*RedisInstance) Hset

func (r *RedisInstance) Hset(ctx context.Context, key, field string, val interface{}) (int64, error)

Hset 设置hash值

func (*RedisInstance) Incr

func (r *RedisInstance) Incr(ctx context.Context, key string) (int64, error)

Incr 增加

func (*RedisInstance) IncrBy

func (r *RedisInstance) IncrBy(ctx context.Context, key string, value int64) (int64, error)

IncrBy 增加N

func (*RedisInstance) Llen

func (r *RedisInstance) Llen(ctx context.Context, key string) (int64, error)

Llen 列表长度

func (*RedisInstance) Lpop

func (r *RedisInstance) Lpop(ctx context.Context, key string) (string, error)

Lpop 移出并获取列表的第一个元素,用法:Lpop("key")

func (*RedisInstance) Lpush

func (r *RedisInstance) Lpush(ctx context.Context, key string, val interface{}) (int64, error)

Lpush 将一个或多个值插入到列表头部,用法:Lpush("key", val)

func (*RedisInstance) Lrem

func (r *RedisInstance) Lrem(ctx context.Context, key string, val interface{}, count int64) (int64, error)

Lrem 移除列表中与参数 VALUE 相等的元素

func (*RedisInstance) Pub

func (r *RedisInstance) Pub(ctx context.Context, channel string, msg string) (int64, error)

Pub 发布

func (*RedisInstance) Rpop

func (r *RedisInstance) Rpop(ctx context.Context, key string) (string, error)

Rpop 移除列表的最后一个元素,返回值为移除的元素,用法:Rpop("key")

func (*RedisInstance) SAdd

func (r *RedisInstance) SAdd(ctx context.Context, key string, value string) (int64, error)

SAdd 向集合添加一个或多个成员

func (*RedisInstance) SMembers

func (r *RedisInstance) SMembers(ctx context.Context, key string) ([]string, error)

SMembers 返回集合中的所有成员

func (*RedisInstance) SRANDMEMBER

func (r *RedisInstance) SRANDMEMBER(ctx context.Context, key string) (string, error)

SRANDMEMBER 返回集合中一个或多个随机数

func (*RedisInstance) Set

func (r *RedisInstance) Set(ctx context.Context, key string, val interface{}, expire int) (string, error)

Set 设置值:Set("key", val, 60),其中 expire 的单位为秒

func (*RedisInstance) SetNx

func (r *RedisInstance) SetNx(ctx context.Context, key string, val interface{}, expire int) (bool, error)

SetNx SetNx("key", val, 60),其中 expire 的单位为秒

func (*RedisInstance) SetNxEx

func (r *RedisInstance) SetNxEx(ctx context.Context, key string, val interface{}, expire int) (string, error)

SetNxEx exist set value + expires otherwise not do cmd: set key value ex 3600 nx

func (*RedisInstance) SetString

func (r *RedisInstance) SetString(ctx context.Context, key string, value string) (string, error)

SetString 设置字符串

func (*RedisInstance) Sub

func (r *RedisInstance) Sub(ctx context.Context, consumeFunc func(data *redis.Message) error, channel string) error

Sub 订阅

func (*RedisInstance) Ttl

func (r *RedisInstance) Ttl(ctx context.Context, key string) (int64, error)

Ttl 设置

func (*RedisInstance) Zadd

func (r *RedisInstance) Zadd(ctx context.Context, key string, score float64, member interface{}) (int64, error)

Zadd 添加有序集合操作

func (*RedisInstance) Zrangebyscore

func (r *RedisInstance) Zrangebyscore(ctx context.Context, key, min, max string) ([]string, error)

Zrangebyscore 获取有序集合

func (*RedisInstance) Zrevrange

func (r *RedisInstance) Zrevrange(ctx context.Context, key string, start, stop int64) ([]string, error)

Zrevrange 返回有序集中指定区间内的成员,通过索引,分数从高到低

Jump to

Keyboard shortcuts

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