redis

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CodisPool

type CodisPool struct {
	ZkServers []string
	ZkTimeout time.Duration
	ZkDir     string
	// contains filtered or unexported fields
}

type Pool

type Pool struct {
	Name string

	Type string
	// contains filtered or unexported fields
}

func InitCodis

func InitCodis(setting Setting) *Pool

func InitRedis

func InitRedis(setting Setting) *Pool

InitRedis 初始化单点redis

func InitRedisCluster

func InitRedisCluster(setting Setting) *Pool

func InitRedisPool

func InitRedisPool(setting Setting) *Pool

InitRedisPool 通过此方法初始化,不需要关注底层是redis cluster还是codis等

func InitRedisSentinel

func InitRedisSentinel(setting Setting) *Pool

func (*Pool) BLPop

func (p *Pool) BLPop(timeoutMS int, keys ...interface{}) ([]string, error)

func (*Pool) BRPop

func (p *Pool) BRPop(timeoutSeconds int, keys ...interface{}) ([]string, error)

func (*Pool) BRPopLPush

func (p *Pool) BRPopLPush(source, dest string, timeoutSeconds int) (string, error)

func (*Pool) BitCount

func (p *Pool) BitCount(key string, queryOpt ...interface{}) (int, error)

BitCount 统计value中被置为1的数量,可以通过指定start、end让计数只在特定的位上进行

func (*Pool) BitOp

func (p *Pool) BitOp(op, dest string, keys ...string) (int, error)

BitOp 对一个或多个bitmap,进行与、或、非、异或运算,并将结果保存在dest中。op可以为and、or、not、xor

func (*Pool) BitPos

func (p *Pool) BitPos(key string, bit int, pos ...int) (int, error)

BitPos 返回Bitmap中第一个值为bit的位置,可以通过传start、end位置控制查询范围

func (*Pool) Close

func (p *Pool) Close()

Close 关闭redis

func (*Pool) Decr

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

func (*Pool) DecrBy

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

func (*Pool) Del

func (p *Pool) Del(keys ...string) (int, error)

func (*Pool) Do

func (p *Pool) Do(command string, args ...interface{}) (interface{}, error)

Do 扩展方法

func (*Pool) Exists

func (p *Pool) Exists(keys ...string) (int, error)

func (*Pool) Expire

func (p *Pool) Expire(key string, seconds int) (bool, error)

func (*Pool) GeoAdd

func (p *Pool) GeoAdd(key string, geoLocationAndKey ...interface{}) (int, error)

GeoAdd 示例:GEOADD Sicily 13.361389 38.115556 "Palermo" 15.087269 37.502669 "Catania"

func (*Pool) GeoDist

func (p *Pool) GeoDist(key string, member1, member2, unit string) (float64, error)

GeoDist 返回两个给定位置的成员之间的距离 示例:GEODIST Sicily Palermo Catania km

func (*Pool) GeoHash

func (p *Pool) GeoHash(key string, members ...string) ([]string, error)

GeoHash 返回一个或多个成员的geohash表示

func (*Pool) GeoPos

func (p *Pool) GeoPos(key string, members ...string) ([]string, error)

GeoPos 获取指定成员的经纬度

func (*Pool) GeoRadius

func (p *Pool) GeoRadius(key string, longitude, latitude float64, radius int, unit string) ([]string, error)

GeoRadius 以给定的经纬度为中心, 返回键包含的位置成员当中, 与中心的距离不超过给定最大距离的所有位置元素 示例:GEORADIUS Sicily 15 37 200 km WITHDIST

func (*Pool) GeoRadiusByMember

func (p *Pool) GeoRadiusByMember(key, member string, queryOpt ...interface{}) ([]string, error)

GeoRadiusByMember 以给定的成员为中心, 返回键包含的位置元素当中,与中心的距离不超过给定最大距离的所有位置元素 示例:GEORADIUSBYMEMBER Sicily Agrigento 100 km

func (*Pool) GeoRadiusWithCoord

func (p *Pool) GeoRadiusWithCoord(key string, longitude float64, latitude float64, radius int, unit string, orderType string) ([][]string, error)

func (*Pool) GeoRadiusWithDist

func (p *Pool) GeoRadiusWithDist(key string, longitude float64, latitude float64, radius int, unit string, orderType string) ([][]string, error)

func (*Pool) Get

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

Get 注意:获取不到key时,会返回ERROR(redigo, nil returned)

func (*Pool) GetBit

func (p *Pool) GetBit(key string, offset int) (int, error)

func (*Pool) HDel

func (p *Pool) HDel(key string, fields ...string) (int, error)

func (*Pool) HExists

func (p *Pool) HExists(key, field string) (bool, error)

func (*Pool) HGet

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

func (*Pool) HGetAll

func (p *Pool) HGetAll(key string) (map[string]string, error)

func (*Pool) HIncrBy

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

func (*Pool) HIncrByFloat

func (p *Pool) HIncrByFloat(key, field string, incr float64) (float64, error)

func (*Pool) HKeys

func (p *Pool) HKeys(key string) ([]string, error)

func (*Pool) HLen

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

func (*Pool) HMGet

func (p *Pool) HMGet(key string, fields ...string) ([]string, error)

func (*Pool) HMSet

func (p *Pool) HMSet(key string, fields map[string]interface{}) (string, error)

func (*Pool) HSet

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

func (*Pool) HSetNX

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

func (*Pool) HVals

func (p *Pool) HVals(key string) ([]string, error)

func (*Pool) Incr

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

func (*Pool) IncrBy

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

func (*Pool) LIndex

func (p *Pool) LIndex(key string, index int) (string, error)

LIndex 根据下标获取列表中的元素,从0开始,-1代表最后一个元素 interface{}为[]uint8

func (*Pool) LInsert

func (p *Pool) LInsert(key, op string, pivot, value interface{}) (int, error)

func (*Pool) LInsertAfter

func (p *Pool) LInsertAfter(key string, pivot, value interface{}) (int, error)

func (*Pool) LInsertBefore

func (p *Pool) LInsertBefore(key string, pivot, value interface{}) (int, error)

func (*Pool) LLen

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

func (*Pool) LPop

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

func (*Pool) LPush

func (p *Pool) LPush(key string, values ...interface{}) (int, error)

func (*Pool) LPushX

func (p *Pool) LPushX(key string, value interface{}) (int, error)

LPushX 只有列表存在时才会插入

func (*Pool) LRange

func (p *Pool) LRange(key string, start, stop int) ([]string, error)

func (*Pool) LRem

func (p *Pool) LRem(key string, count int, value interface{}) (int, error)

func (*Pool) LSet

func (p *Pool) LSet(key string, index int, value interface{}) (string, error)

func (*Pool) LTrim

func (p *Pool) LTrim(key string, start, stop int64) (string, error)

func (*Pool) MGet

func (p *Pool) MGet(keys ...interface{}) ([]string, error)

MGet 返回的数据,其中interface{}为[]uint8

func (*Pool) MSet

func (p *Pool) MSet(pairs map[string]interface{}) (status string, err error)

MSet client.MSet([]interface{}{"test_1", "value1", "test_2", "value2"}...) return "OK", nil

func (*Pool) RPop

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

func (*Pool) RPopLPush

func (p *Pool) RPopLPush(source, dest string) (string, error)

func (*Pool) RPush

func (p *Pool) RPush(key string, values ...interface{}) (int, error)

func (*Pool) RPushX

func (p *Pool) RPushX(key string, value interface{}) (int, error)

func (*Pool) SAdd

func (p *Pool) SAdd(key string, members ...interface{}) (int, error)

func (*Pool) SCard

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

func (*Pool) SDiff

func (p *Pool) SDiff(keys ...interface{}) ([]string, error)

func (*Pool) SDiffStore

func (p *Pool) SDiffStore(dest string, keys ...string) (int, error)

func (*Pool) SInter

func (p *Pool) SInter(keys ...interface{}) ([]string, error)

func (*Pool) SInterStore

func (p *Pool) SInterStore(dest string, keys ...string) (int, error)

func (*Pool) SIsMember

func (p *Pool) SIsMember(key string, member interface{}) (bool, error)

func (*Pool) SMembers

func (p *Pool) SMembers(key string) ([]string, error)

func (*Pool) SMove

func (p *Pool) SMove(source, dest string, member interface{}) (bool, error)

func (*Pool) SPop

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

func (*Pool) SPopN

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

func (*Pool) SRandMember

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

func (*Pool) SRandMemberN

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

func (*Pool) SRem

func (p *Pool) SRem(key string, members ...interface{}) (int, error)

func (*Pool) SUnion

func (p *Pool) SUnion(keys ...interface{}) ([]string, error)

func (*Pool) SUnionStore

func (p *Pool) SUnionStore(dest string, keys ...string) (int, error)

func (*Pool) Set

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

func (*Pool) SetBit

func (p *Pool) SetBit(key string, offset int, bit int) (int, error)

func (*Pool) SetEx

func (p *Pool) SetEx(key string, expire int, value string) (string, error)

func (*Pool) SetNX

func (p *Pool) SetNX(key string, value interface{}, seconds int) (string, error)

SetNX 当seconds为0时,代表不需要指定过期时间

func (*Pool) TTL

func (p *Pool) TTL(key string) (seconds int, err error)

func (*Pool) ZAdd

func (p *Pool) ZAdd(key string, members ...interface{}) (int, error)

ZAdd 示例:zadd test_c score1 value1 score2 value2 [score value...]

func (*Pool) ZCard

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

func (*Pool) ZCount

func (p *Pool) ZCount(key, min, max string) (int, error)

func (*Pool) ZIncr

func (p *Pool) ZIncr(key string, members ...interface{}) (int, error)

func (*Pool) ZIncrBy

func (p *Pool) ZIncrBy(key string, increment float64, members ...interface{}) (float64, error)

func (*Pool) ZInterStore

func (p *Pool) ZInterStore(dest string, keys ...string) (int, error)

func (*Pool) ZLexCount

func (p *Pool) ZLexCount(key, min, max string) (int, error)

func (*Pool) ZRange

func (p *Pool) ZRange(key string, start, stop int) ([]string, error)

func (*Pool) ZRangeByScore

func (p *Pool) ZRangeByScore(key string, start, stop interface{}) ([]string, error)

ZRangeByScore 正常是双闭区间,可以传start = (1, stop= (5 控制为开区间,即 1< score < 5

func (*Pool) ZRangeByScoreWithScores

func (p *Pool) ZRangeByScoreWithScores(key string, start, stop interface{}) ([]string, error)

func (*Pool) ZRangeWithScores

func (p *Pool) ZRangeWithScores(key string, start, stop int) ([]string, error)

func (*Pool) ZRank

func (p *Pool) ZRank(key, member string) (int, error)

ZRank 返回member的索引位置

func (*Pool) ZRem

func (p *Pool) ZRem(key string, members ...string) (int, error)

func (*Pool) ZRemRangeByLex

func (p *Pool) ZRemRangeByLex(key, min, max string) (int, error)

func (*Pool) ZRemRangeByRank

func (p *Pool) ZRemRangeByRank(key string, start, stop int) (int, error)

func (*Pool) ZRemRangeByScore

func (p *Pool) ZRemRangeByScore(key, min, max interface{}) (int, error)

func (*Pool) ZRevRange

func (p *Pool) ZRevRange(key string, start, stop int) ([]string, error)

func (*Pool) ZRevRangeByScore

func (p *Pool) ZRevRangeByScore(key string, limitOpt ...interface{}) ([]string, error)

func (*Pool) ZRevRangeWithScores

func (p *Pool) ZRevRangeWithScores(key string, start, stop int) ([]string, error)

func (*Pool) ZRevRank

func (p *Pool) ZRevRank(key, member string) (int, error)

func (*Pool) ZScore

func (p *Pool) ZScore(key, member string) (float64, error)

func (*Pool) ZUnionStore

func (p *Pool) ZUnionStore(dest string, keys ...string) (int, error)

type PoolInterface

type PoolInterface interface {
	Get() redis.Conn
	Close() error
}

type Setting

type Setting struct {
	Name string `mapstructure:"name"`
	// redis类型,包括redis,sentinel,cluster,codis四种
	Type string   `mapstructure:"type"`
	Addr []string `mapstructure:"addr"`
	// 密码
	Password string `mapstructure:"passwd"`
	// 数据库,默认0
	Db int `mapstructure:"db"`
	// 用于codis连接
	ZkHost []string `mapstructure:"zk_host"`
	// 用于codis连接
	ZkPath string `mapstructure:"zk_path"`
	// 最大连接数量
	MaxPoolSize int `mapstructure:"max_pool_size"`
	// 最大空闲连接数量,超过这个数值的空闲连接将会被关闭
	MaxIdle int `mapstructure:"max_idle"`
	// 空闲时间,超过这个时间的空闲连接将会被关闭
	IdleTimeout time.Duration `mapstructure:"idle_timeout"`
	// 连接等待时间
	ConnectTimeout time.Duration `mapstructure:"connect_timeout"`
	// 读写等待时间
	DoWithTimeout time.Duration `mapstructure:"do_with_timeout"`
}

Jump to

Keyboard shortcuts

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