redis

package
v0.4.8 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SET_IF_NOT_EXIST      = "NX" // 不存在则执行
	SET_WITH_EXPIRE_TIME  = "EX" // 过期时间(秒)  PX 毫秒
	SET_LOCK_SUCCESS      = "OK" // 操作成功
	DEL_LOCK_SUCCESS      = 1    // lock 删除成功
	DEL_LOCK_NON_EXISTENT = 0    // 删除lock key时,并不存在
)
View Source
const (
	INCR = "INCR"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v0.4.4

type Config struct {
	Host      string
	Password  string
	Db        string
	Port      int
	MaxIdle   int
	MaxActive int
	Timeout   time.Duration
}

type Pool added in v0.4.5

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

func New added in v0.4.3

func New(c Config) *Pool

func (*Pool) HashGet added in v0.4.5

func (p *Pool) HashGet(key, field string) (b []byte, err error)

"test","a"

func (*Pool) HashGetString added in v0.4.5

func (p *Pool) HashGetString(key, field string) (string, error)

"test","a"

func (*Pool) HashHdel added in v0.4.5

func (p *Pool) HashHdel(key, field string) (err error)

删除field 删除不存在的field不会报错 输入 "test", "e"

func (*Pool) HashHexists added in v0.4.5

func (p *Pool) HashHexists(key, field string) (ok bool)

判断field是否存在 输入 "test", "a" 输出 true or false

func (*Pool) HashHgetallMapStringInt added in v0.4.5

func (p *Pool) HashHgetallMapStringInt(key string) (res map[string]int, err error)

获取key的全部数据 输入 "test"

func (*Pool) HashHgetallMapStringString added in v0.4.5

func (p *Pool) HashHgetallMapStringString(key string) (res map[string]string, err error)

获取key的全部数据 输入 "test"

func (*Pool) HashHincrby added in v0.4.5

func (p *Pool) HashHincrby(key, field string, incr int) (err error)

value 增加incr e原来是1,incr=2,完成后e=3 要求 field的值必须是int 若field不存在,则新增field,value=incr 输入 "test", "e",2 输出 true or false

func (*Pool) HashHkeys added in v0.4.5

func (p *Pool) HashHkeys(key string) (l []string, err error)

获取key的所有field 输入 "test"

func (*Pool) HashHlen added in v0.4.5

func (p *Pool) HashHlen(key string) (l int64, err error)

获取key的field长度 输入 "test"

func (*Pool) HashHvals added in v0.4.5

func (p *Pool) HashHvals(key string) (l []string, err error)

获取key的所有field的value 输入 "test"

func (*Pool) HashMget added in v0.4.5

func (p *Pool) HashMget(values ...interface{}) (b []interface{}, err error)

values 是由 key, k,k,k组成 输入 "test", "a", "b","c" 输出

func (*Pool) HashMgetMapString added in v0.4.5

func (p *Pool) HashMgetMapString(values ...interface{}) (b map[string]string, err error)

values 是由 key, k,k,k组成 输入 "test", "a", "b","c","cc","e" 输出 map[string]string{ "a": "aa", "b": "bb", "c": "cc", "cc": "cc", "e": "3" }

func (*Pool) HashMgetString added in v0.4.5

func (p *Pool) HashMgetString(values ...interface{}) (b []string, err error)

values 是由 key, k,k,k组成 输入 "test", "a", "b","c" 输出 ["aa","bb","cc"]

func (*Pool) HashMset added in v0.4.5

func (p *Pool) HashMset(values ...interface{}) error

values 是由 key, k,v,k,v组成 "test", "a", "aa"

func (*Pool) HashSet added in v0.4.5

func (p *Pool) HashSet(key, field string, value interface{}) error

"test","e",1

func (*Pool) KeyDelete added in v0.4.5

func (p *Pool) KeyDelete(key string) (bool, error)

func (*Pool) KeyExists added in v0.4.5

func (p *Pool) KeyExists(key string) bool

func (*Pool) KeyExpire added in v0.4.7

func (p *Pool) KeyExpire(key string, time int) (bool, error)

func (*Pool) KeyLikeDeletes added in v0.4.5

func (p *Pool) KeyLikeDeletes(key string) error

func (*Pool) LockAdd added in v0.4.5

func (p *Pool) LockAdd(key, requestId string, ex int) bool

redis 类型 字符串设置一个分布式锁 (哈希内部字段不支持过期判断,redis只支持顶级key过期)

@param key: 锁名,格式为 用户id_操作_方法 @param requestId: 客户端唯一id 用来指定锁不被其他线程(协程)删除 @param ex: 过期时间

func (*Pool) LockDel added in v0.4.5

func (p *Pool) LockDel(key, requestId string) bool

删除redis分布式锁

@param key:redis类型字符串的key值 @param requestId: 唯一值id,与value值对比,避免在分布式下其他实例删除该锁

func (*Pool) LockGet added in v0.4.5

func (p *Pool) LockGet(key string) string

获得redis分布式锁的值

@param key:redis类型字符串的key值 @param return: redis类型字符串的value

func (*Pool) SetDel added in v0.4.5

func (p *Pool) SetDel(key, value string) error

删除

func (*Pool) SetExist added in v0.4.5

func (p *Pool) SetExist(key, value string) bool

判断是否存在

func (*Pool) SetGetAll added in v0.4.5

func (p *Pool) SetGetAll(key string) []string

获取全部数据

func (*Pool) SetPop added in v0.4.6

func (p *Pool) SetPop(key string, count int) []string

随机删除

func (*Pool) SetSet added in v0.4.5

func (p *Pool) SetSet(key, value string) error

设置

func (*Pool) SetSetAndExpire added in v0.4.6

func (p *Pool) SetSetAndExpire(key, value string) error

设置

func (*Pool) StringGet added in v0.4.5

func (p *Pool) StringGet(key string) (string, error)

func (*Pool) StringGetInt added in v0.4.5

func (p *Pool) StringGetInt(key string) (int, error)

func (*Pool) StringSet added in v0.4.5

func (p *Pool) StringSet(key string, data interface{}, time int) (bool, error)

func (*Pool) ZsetSet added in v0.4.5

func (p *Pool) ZsetSet(key, value string, score int) error

设置

func (*Pool) ZsetSetGetASC added in v0.4.5

func (p *Pool) ZsetSetGetASC(key string, start, end int) (list ZsetList, err error)

获取 从低到高

func (*Pool) ZsetSetGetDESC added in v0.4.5

func (p *Pool) ZsetSetGetDESC(key string, start, end int) (list ZsetList, err error)

获取 从高到低

func (*Pool) ZsetSetInccr1 added in v0.4.5

func (p *Pool) ZsetSetInccr1(key, value string, score int) error

设置 同时自增1

type Zset

type Zset struct {
	Key   string
	Score int
}

type ZsetList

type ZsetList []Zset

func (ZsetList) Len

func (z ZsetList) Len() int

func (ZsetList) Less

func (z ZsetList) Less(i, j int) bool

func (ZsetList) Swap

func (z ZsetList) Swap(i, j int)

Jump to

Keyboard shortcuts

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