redisDB

package
v1.6.22 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LuaString = `` /* 430-byte string literal not displayed */

)

Variables

This section is empty.

Functions

func GetRediClient

func GetRediClient(config map[string]string) (redis.Cmdable, error)

GetRediClient 获取客户端

Types

type IRedisRepository

type IRedisRepository interface {

	//Set 插入单个
	// entity  结构体
	// ttl     单位秒 ,0为永不到期
	Set(key string, entity interface{}, ttl int64) (int64, error)

	//SetMany 插入多个【单次20000个以下】
	// entityMap 结构体字典
	SetMany(entityMap map[string]interface{}) (int64, error)

	//Incr 递增字段值
	//key hashid
	//fieid 字段名称
	Incr(key, field string, num int64) (int64, error)

	//GetIncr 获取递增字段值
	//key hashid
	//res 要获取的字段值
	GetIncr(key string, res map[string]int64) (err error)

	//RemoveIncr 移除递增
	//key hashid
	RemoveIncr(key string) error

	//Remove 删除单个
	// key key值
	Remove(key ...string) (int64, error)

	//Get 查询单个
	// key         key值
	// result      查询的结果
	Get(key string, result interface{}) error

	//GetMany 查询多个[只支持string类型]
	// keys        key值切片
	// result      查询的结果切片
	GetMany(keys []string, result interface{}) error

	// CreateKey 创建内部key(配合直接使用数据库连接(GetClient)使用,其它方法不需要使用内部已调用)
	// prefix 前缀
	// key
	CreateKey(prefix, key string) string

	//Do 直接执行
	Do(f func(redis.Cmdable))
}

IRedisRepository 仓储接口(只支持string类型)

type RedisContent

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

RedisContent 集合上下文

func DataBaseMapping

func DataBaseMapping(mappingName string, configFn func(mappingName string) map[string]string, prefixNamesFn func() map[string]int) (*RedisContent, error)

DataBaseMapping 添加映射 @client 连接对象

func (*RedisContent) GetRedisLimit added in v1.6.16

func (r *RedisContent) GetRedisLimit() *RedisLimit

GetRedisLimit 获取限速器

func (*RedisContent) GetRedisLock added in v1.6.16

func (r *RedisContent) GetRedisLock(lockKey string) *RedisLock

GetRedisLock 获取分布式锁

func (*RedisContent) GetRedisRepository

func (r *RedisContent) GetRedisRepository(prefixName string) (IRedisRepository, bool)

GetRedisRepository 获取集合仓储 entity 结构体

type RedisLimit added in v1.6.16

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

RedisLimit redis限速器

func NewRedisLimit added in v1.6.16

func NewRedisLimit(store redis.Cmdable) *RedisLimit

NewRedisLimit 实例化限速器

func (*RedisLimit) DelLimit added in v1.6.16

func (rl *RedisLimit) DelLimit(key string) (bool, error)

DelLimit 删除限速器 key 需要清理的限制标识

func (*RedisLimit) IsLimit added in v1.6.16

func (rl *RedisLimit) IsLimit(key string, maxLimit int, timeout time.Duration) (bool, error)

IsLimit 是否触发限速器 , true 触发的限速,false 没有触发限速 key 需要限制的标识 maxLimit 单位时间内最大访问次数 timeout 时间范围

type RedisLock added in v1.6.16

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

A RedisLock is a redis lock.

func NewRedisLock added in v1.6.16

func NewRedisLock(store redis.Cmdable, key string) *RedisLock

NewRedisLock returns a RedisLock.

func (*RedisLock) GetId added in v1.6.16

func (rl *RedisLock) GetId() string

GetId 获取锁编号,锁value值

func (*RedisLock) Lock added in v1.6.16

func (rl *RedisLock) Lock(ttl time.Duration) (bool, error)

Lock acquires the lock. ttl 锁过期时间,防止死锁 加锁 [可重入锁]

func (*RedisLock) TryLock added in v1.6.16

func (rl *RedisLock) TryLock(ttl time.Duration, wait time.Duration) (bool, error)

TryLock acquires the lock. ttl 锁过期时间,防止死锁, wait 等待获取到锁时间,防止死锁 有阻塞加锁,直到超时或加锁成功

func (*RedisLock) ULock added in v1.6.16

func (rl *RedisLock) ULock() (bool, error)

ULock releases the lock. 释放锁

type ReidsRepository

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

ReidsRepository 仓储(string)

func (*ReidsRepository) CreateKey added in v1.5.1

func (r *ReidsRepository) CreateKey(prefix, key string) string

CreateKey 创建内部key

func (*ReidsRepository) Do added in v1.6.13

func (r *ReidsRepository) Do(h func(redis.Cmdable))

Do 直接执行

func (*ReidsRepository) Get

func (r *ReidsRepository) Get(key string, result interface{}) error

Get 查询单个 key key值 result 查询的结果

func (*ReidsRepository) GetIncr added in v1.5.1

func (r *ReidsRepository) GetIncr(key string, res map[string]int64) (err error)

GetIncr 获取递增值

func (*ReidsRepository) GetMany

func (r *ReidsRepository) GetMany(keys []string, result interface{}) error

GetMany 查询多个 keys key值切片 result 查询的结果切片

func (*ReidsRepository) Incr added in v1.5.1

func (r *ReidsRepository) Incr(key, field string, num int64) (int64, error)

Incr 递增

func (*ReidsRepository) Remove

func (r *ReidsRepository) Remove(keys ...string) (int64, error)

Remove 移除 keys key值切片

func (*ReidsRepository) RemoveIncr added in v1.5.1

func (r *ReidsRepository) RemoveIncr(key string) error

RemoveIncr 清理递增字段

func (*ReidsRepository) Set

func (r *ReidsRepository) Set(key string, entity interface{}, ttl int64) (int64, error)

Set 插入单个[key数据存在会更新] entity 结构体 ttl 单位秒 ,0为永不到期

func (*ReidsRepository) SetMany

func (r *ReidsRepository) SetMany(entityMap map[string]interface{}) (int64, error)

SetMany 插入多个 [key数据存在会更新] entityMap 结构体字典

Jump to

Keyboard shortcuts

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