redis

package
v0.0.0-...-1ec2636 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2019 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNil = redis.ErrNil

Functions

func Bool

func Bool(reply interface{}, err error) (bool, error)

func Bytes

func Bytes(reply interface{}, err error) ([]byte, error)

func Float64

func Float64(reply interface{}, err error) (float64, error)

func Int

func Int(reply interface{}, err error) (int, error)

func Int64

func Int64(reply interface{}, err error) (int64, error)

func Int64Map

func Int64Map(reply interface{}, err error) (map[string]int64, error)

func Scan

func Scan(src []interface{}, dest ...interface{}) ([]interface{}, error)

func ScanSlice

func ScanSlice(src []interface{}, dest interface{}, fieldNames ...string) error

func ScanStruct

func ScanStruct(src []interface{}, dest interface{}) error

func String

func String(reply interface{}, err error) (string, error)

func Strings

func Strings(reply interface{}, err error) ([]string, error)

func Uint32

func Uint32(reply interface{}, err error) (uint32, error)

func Uint64

func Uint64(reply interface{}, err error) (uint64, error)

func Values

func Values(reply interface{}, err error) ([]interface{}, error)

Types

type BasePool

type BasePool struct {
	BDPool  map[int]*redis.Pool
	Address string
}

type ItemScore

type ItemScore struct {
	Key   string
	Score float64
}

type RedisPool

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

func New

func New(wAddress string, rAddresses []string, maxActiveConn int) (rp *RedisPool)

func (*RedisPool) Del

func (rp *RedisPool) Del(db int, key interface{}) error

func (*RedisPool) Exists

func (rp *RedisPool) Exists(db int, key interface{}) (bool, error)

func (*RedisPool) Expire

func (rp *RedisPool) Expire(db, expire int, key interface{}) (e error)

设置key的有效时间

func (*RedisPool) ExpireAt

func (rp *RedisPool) ExpireAt(db int, expire int64, key interface{}) (e error)

设置key的到期时间

func (*RedisPool) Get

func (rp *RedisPool) Get(db int, key interface{}) (value interface{}, e error)

func (*RedisPool) GetReadConnection

func (rp *RedisPool) GetReadConnection(db int) redis.Conn

func (*RedisPool) GetWriteConnection

func (rp *RedisPool) GetWriteConnection(db int) redis.Conn

func (*RedisPool) HDel

func (rp *RedisPool) HDel(db int, args ...interface{}) (e error)

HDel批量删除某个Key中的元素

args: 第一个必须是key,后面的都是id

func (*RedisPool) HGet

func (rp *RedisPool) HGet(db int, key interface{}, name interface{}) (value interface{}, e error)

func (*RedisPool) HGetAll

func (rp *RedisPool) HGetAll(db int, key interface{}) (reply interface{}, e error)

HGetAll针对同一个key获取hashset中的所有元素的值

func (*RedisPool) HMGet

func (rp *RedisPool) HMGet(db int, values interface{}, key interface{}, ids ...interface{}) (e error)

HMGet针对同一个key获取hashset中的部分元素的值

参数:

args: 第一个值必须是key,后续的值都是id
values: 必须是数组的引用,如果某个id不存在,会把对应数据类型的零值放在数组对应位置上

func (*RedisPool) HMSet

func (rp *RedisPool) HMSet(db int, args ...interface{}) (e error)

HMSET 批量设置key下的多个字段值

db:数据库
args: 必须是 key,filed,value,filed2,value2

func (*RedisPool) HMultiGet

func (rp *RedisPool) HMultiGet(db int, args ...interface{}) (values map[interface{}]map[interface{}]interface{}, e error)

HMultiGet批量获取HashSet中多个key中ID的值

参数:

db: 数据库表ID
args: 必须是<key,id>的列表

返回值:

values: 一个两层的map,第一层的key是参数中的key,第二层的key是参数中的id

func (*RedisPool) HMultiSet

func (rp *RedisPool) HMultiSet(db int, args ...interface{}) (e error)

HSet批量设置HashSet中的值

db: 数据库表ID
args: 必须是<key,id,value>的列表

func (*RedisPool) HSet

func (rp *RedisPool) HSet(db int, key interface{}, id interface{}, value interface{}) (e error)

func (*RedisPool) Incr

func (rp *RedisPool) Incr(db int, key interface{}) (uint64, error)

func (*RedisPool) IncrBy

func (rp *RedisPool) IncrBy(db int, key interface{}, value interface{}) (uint64, error)

func (*RedisPool) Keys

func (rp *RedisPool) Keys(db int) (keys []interface{}, e error)

批量获取所有key

func (*RedisPool) LLen

func (rp *RedisPool) LLen(db int, key interface{}) (length int, e error)

获取队列长度,如果key不存在,length=0,不会报错。

func (*RedisPool) LPop

func (rp *RedisPool) LPop(db int, key interface{}) (value interface{}, e error)

移出并获取列表的第一个元素

func (*RedisPool) LRange

func (rp *RedisPool) LRange(db int, key interface{}, start, stop interface{}) (value interface{}, e error)

获取队列数据

func (*RedisPool) Lock

func (rp *RedisPool) Lock(db int, key_suffix string, expire_sec int64, timeout int64) (getLock bool)

func (*RedisPool) MGet

func (rp *RedisPool) MGet(db int, keys ...interface{}) (value interface{}, e error)

批量获取

func (*RedisPool) MHGetAll

func (rp *RedisPool) MHGetAll(db int, args ...interface{}) (reply map[interface{}][]interface{}, e error)

MHGetAll批量获取多个key所有的字段

func (*RedisPool) MSet

func (rp *RedisPool) MSet(db int, kvs ...interface{}) (value interface{}, e error)

批量设置 < key value > 序列

func (*RedisPool) Multi

func (rp *RedisPool) Multi(db int, cmd func(con redigo.Conn) error) error

func (*RedisPool) MultiExpire

func (rp *RedisPool) MultiExpire(db, expire int, args ...interface{}) (e error)

MultiExpire 批量设置key的有效时间

db: 数据库表ID
expire:缓存失效时间(秒值)
args:key的列表

func (*RedisPool) RPush

func (rp *RedisPool) RPush(db int, key interface{}, values ...interface{}) (value interface{}, e error)

批量插入队尾

func (*RedisPool) SAdd

func (rp *RedisPool) SAdd(db int, key interface{}, values ...interface{}) (e error)

func (*RedisPool) SCard

func (rp *RedisPool) SCard(db int, key interface{}) (num uint64, e error)

SMembers获取某个key下的所有元素

参数:

values: 必须是数组的引用

func (*RedisPool) SIsMember

func (rp *RedisPool) SIsMember(db int, key interface{}, value interface{}) (isMember bool, e error)

func (*RedisPool) SMembers

func (rp *RedisPool) SMembers(db int, values interface{}, key interface{}) (e error)

SMembers获取某个key下的所有元素

参数:

values: 必须是数组的引用

func (*RedisPool) SMultiAdd

func (rp *RedisPool) SMultiAdd(db int, args ...interface{}) error

批量添加到set类型的表中

db: 数据库表ID
args: 必须是<key,id>的列表

func (*RedisPool) SMultiRem

func (rp *RedisPool) SMultiRem(db int, args ...interface{}) error

批量删除set类型表中的元素

db: 数据库表ID
args: 必须是<key,id>的列表

func (*RedisPool) SRem

func (rp *RedisPool) SRem(db int, key interface{}, values ...interface{}) (e error)

func (*RedisPool) Set

func (rp *RedisPool) Set(db int, key interface{}, value interface{}) (e error)

func (*RedisPool) SetEx

func (rp *RedisPool) SetEx(db int, key interface{}, seconds int, value interface{}) (e error)

func (*RedisPool) SetNX

func (rp *RedisPool) SetNX(db int, key interface{}, value interface{}) (int, error)

func (*RedisPool) TTL

func (rp *RedisPool) TTL(db int, key interface{}) (int64, error)

func (*RedisPool) UnLock

func (rp *RedisPool) UnLock(db int, key_suffix string) (e error)

func (*RedisPool) ZAdd

func (rp *RedisPool) ZAdd(db int, args ...interface{}) error

批量添加到sorted set类型的表中

db: 数据库表ID
args: 必须是<key,score,id>的列表

func (*RedisPool) ZAddOpt

func (rp *RedisPool) ZAddOpt(db int, opt string, args ...interface{}) error

批量添加到sorted set类型的表中

db: 数据库表ID
opt: 可选参数,必须是NX|XX|CH|INCR|""中的一个
args: 必须是<key,score,id>的列表

func (*RedisPool) ZCard

func (rp *RedisPool) ZCard(db int, key interface{}) (num uint64, e error)

func (*RedisPool) ZCount

func (rp *RedisPool) ZCount(db int, key interface{}, min, max float64) (count uint32, e error)

func (*RedisPool) ZExists

func (rp *RedisPool) ZExists(db int, key interface{}, id interface{}) (bool, error)

func (*RedisPool) ZIsMember

func (rp *RedisPool) ZIsMember(db int, key interface{}, item interface{}) (isMember bool, e error)

ZIsMember判断是否是有序集合的成员

func (*RedisPool) ZMultiIsMember

func (rp *RedisPool) ZMultiIsMember(db int, key interface{}, items map[interface{}]bool) error

批量判断是否是有序集合中的元素

func (*RedisPool) ZMultiScore

func (rp *RedisPool) ZMultiScore(db int, key interface{}, items ...interface{}) (scores map[interface{}]int64, e error)

批量获取有序集合的元素的得分

func (*RedisPool) ZREVRangeByScoreWithScores

func (rp *RedisPool) ZREVRangeByScoreWithScores(db int, key interface{}, min, max int64, ps int) (items []ItemScore, e error)

根据score 获取有序集 ZREVRANGEBYSCORE min <=score < max 按照score 从大到小排序, ps 获取条数

func (*RedisPool) ZREVRangeWithScores

func (rp *RedisPool) ZREVRangeWithScores(db int, key interface{}, start, end int) (items []ItemScore, total int, e error)

func (*RedisPool) ZREVRangeWithScoresPS

func (rp *RedisPool) ZREVRangeWithScoresPS(db int, key interface{}, cur int, ps int) (items []ItemScore, total int, e error)

func (*RedisPool) ZRange

func (rp *RedisPool) ZRange(db int, key interface{}, start, end int, asc bool, results interface{}) (total int, e error)

获取SortedSet的ID集合

func (*RedisPool) ZRangeByScore

func (rp *RedisPool) ZRangeByScore(db int, key interface{}, min, max interface{}) (items []ItemScore, e error)

func (*RedisPool) ZRangeByScoreWithScores

func (rp *RedisPool) ZRangeByScoreWithScores(db int, key interface{}, min, max int64, ps int) (items []ItemScore, e error)

根据score 获取有序集 ZRANGEBYSCORE min <score <= max 按照score 从小到大排序, ps 获取条数

func (*RedisPool) ZRangePS

func (rp *RedisPool) ZRangePS(db int, key interface{}, cur int, ps int, asc bool, results interface{}) (total int, e error)

分页获取SortedSet的ID集合

func (*RedisPool) ZRangeWithScores

func (rp *RedisPool) ZRangeWithScores(db int, key interface{}, start, end int) (items []ItemScore, total int, e error)

func (*RedisPool) ZRangeWithScoresPS

func (rp *RedisPool) ZRangeWithScoresPS(db int, key interface{}, cur int, ps int) (items []ItemScore, total int, e error)

func (*RedisPool) ZRem

func (rp *RedisPool) ZRem(db int, args ...interface{}) (affected []int, e error)

ZRem批量删除sorted set表中的元素

参数:

db: 数据库表ID
args: 必须是<key,id>的列表

返回值:

affected: 每条命令影响的行数

func (*RedisPool) ZRemRangeByScore

func (rp *RedisPool) ZRemRangeByScore(db int, key interface{}, min, max int64) error

移除有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员

func (*RedisPool) ZScore

func (rp *RedisPool) ZScore(db int, key interface{}, item interface{}) (score int64, e error)

func (*RedisPool) ZUnionSrore

func (rp *RedisPool) ZUnionSrore(db int, dest_key interface{}, expire int, keys []interface{}, weights []interface{}, aggregate string) error

合并多个有序集合,其中权重weights 默认为1 ,AGGREGATE 默认使用sum ZUNIONSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX] dest_key:合并目标key keys: 带合并的keys集合 <key> 的列表 expire: 有效时间 (秒值) aggregate: 聚合方式: SUM | MIN | MAX

Directories

Path Synopsis
用时间和一个16位的标签共同生成sorted set的分值,时间放在高位,这样既不影响按时间排序,还能记录一些额外的信息。
用时间和一个16位的标签共同生成sorted set的分值,时间放在高位,这样既不影响按时间排序,还能记录一些额外的信息。

Jump to

Keyboard shortcuts

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