redis

package
v0.0.0-...-0e6d7d3 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2022 License: BSD-2-Clause Imports: 10 Imported by: 0

Documentation

Overview

redis 实现分布式互斥锁

Index

Constants

View Source
const (
	Minite = 60
	Hour   = 60 * Minite
	Day    = 24 * Hour
	Month  = 30 * Day
)

Variables

View Source
var Decoders map[string]func(data []byte, v interface{}) error
View Source
var Encoders map[string]func(v interface{}) ([]byte, error)
View Source
var ErrNil = errors.New("cache: nil returned")
View Source
var ErrNilDecoder = errors.New("cache: nil decoder")
View Source
var ErrNilEncoder = errors.New("cache: nil encoder")

Functions

func Decode

func Decode(encoding string, b []byte, v interface{}) error

func Encode

func Encode(encoding string, v interface{}) (interface{}, error)

func GetPool

func GetPool(redisName string) *redis.Pool

func GetRedisPoolClient

func GetRedisPoolClient(redisName string) (conn redis.Conn)

func Install

func Install(configs []*Config)

func MustGetPool

func MustGetPool(redisName string) *redis.Pool

func NewMutex

func NewMutex(redisName, key string) *redsync.Mutex

func NewRedisPool

func NewRedisPool(c *Config) *redis.Pool

func Warn

func Warn(err error)

Types

type Config

type Config struct {
	Name         string `json:"name"`
	Addr         string `json:"addr"`
	Active       int    `json:"active"`
	Idle         int    `json:"idle"`
	DialTimeout  int    `json:"dial_timeout"`  // millisecond
	ReadTimeout  int    `json:"read_timeout"`  // millisecond
	WriteTimeout int    `json:"write_timeout"` // millisecond
	IdleTimeout  int    `json:"idle_timeout"`  // second

	DBNum    int    `json:"dbnum"`
	Password string `json:"password"`
}

type Key

type Key struct {
	DBName       string      // redis连接池名
	Key          interface{} // 主键名
	SecondaryKey interface{} // (可选)次级键名, 用于哈希或集合操作, 比如hget <key> <field>
	Encoding     string      // 序列化方式, msgpack/json/自定义
	Timeout      int         // 过期时间(秒)
	Critical     bool        // 是否关键key. true=只要读写报错就panic
}

func (*Key) BitCount

func (this *Key) BitCount() int

func (*Key) Del

func (this *Key) Del() *Result

func (*Key) Do

func (this *Key) Do(command string, args ...interface{}) *Result

func (*Key) Exists

func (this *Key) Exists() bool

func (*Key) Expire

func (this *Key) Expire(ttl int) bool

func (*Key) GeoAdd

func (this *Key) GeoAdd(member interface{}, lat, lng float64) bool

func (*Key) GeoDist

func (this *Key) GeoDist(m1, m2 interface{}) int

func (*Key) GeoMPos

func (this *Key) GeoMPos(members ...interface{}) [][2]float64

批量返回坐标 [[纬度,经度], [纬度,经度], ...]

func (*Key) GeoPos

func (this *Key) GeoPos(member interface{}) (float64, float64)

返回(纬度, 经度)

func (*Key) Get

func (this *Key) Get() *Result

func (*Key) HDel

func (this *Key) HDel(fields ...interface{}) *Result

func (*Key) HExists

func (this *Key) HExists(key ...interface{}) bool

func (*Key) HGet

func (this *Key) HGet(fields ...interface{}) *Result

func (*Key) HGetAll

func (this *Key) HGetAll() *Result

func (*Key) HIncrBy

func (this *Key) HIncrBy(d int) *Result

func (*Key) HIncrBy2

func (this *Key) HIncrBy2(field interface{}, d int) *Result

func (*Key) HKeys

func (this *Key) HKeys(fields ...interface{}) *Result

func (*Key) HLen

func (this *Key) HLen() int

func (*Key) HMGet

func (this *Key) HMGet(fields ...interface{}) *Result

func (*Key) HMSet

func (this *Key) HMSet(fields ...interface{}) *Result

func (*Key) HScanEx

func (this *Key) HScanEx() *Result

func (*Key) HSet

func (this *Key) HSet(value interface{}) *Result

func (*Key) HSet2

func (this *Key) HSet2(key, value interface{}) *Result

func (*Key) HSetNX

func (this *Key) HSetNX(value interface{}) *Result

func (*Key) HSetNX2

func (this *Key) HSetNX2(key, value interface{}) *Result

func (*Key) Incr

func (this *Key) Incr() *Result

func (*Key) IncrBy

func (this *Key) IncrBy(amount int) *Result

func (*Key) LPop

func (this *Key) LPop() *Result

左出队, 返回弹出值

func (*Key) LuaIncrBy

func (this *Key) LuaIncrBy(amount int) *Result

安全增减键值, Result.Reply==nil表示失败, Result.Int()是最新值

func (*Key) RPush

func (this *Key) RPush(args ...interface{}) int

右进队, 返回最新队列长度

func (*Key) SAdd

func (this *Key) SAdd(members ...interface{}) bool

返回 false 表示重复添加

func (*Key) SCard

func (this *Key) SCard() *Result

func (*Key) SIsMember

func (this *Key) SIsMember(member interface{}) bool

func (*Key) SMembers

func (this *Key) SMembers() *Result

func (*Key) SPop

func (this *Key) SPop(count int) *Result

func (*Key) SRandMember

func (this *Key) SRandMember(count int) *Result

func (*Key) SRem

func (this *Key) SRem(members ...interface{}) bool

返回 false 表示重复删除

func (*Key) Set

func (this *Key) Set(value interface{}) *Result

func (*Key) SetBit

func (this *Key) SetBit(offset int, value int) bool

func (*Key) SetEX

func (this *Key) SetEX(value interface{}, timeout int) *Result

func (*Key) SetNX

func (this *Key) SetNX(value interface{}) *Result

func (*Key) TTL

func (this *Key) TTL() int

func (*Key) ZAdd

func (this *Key) ZAdd(member, score interface{}) bool

有序集合添加成员, 重复添加返回false

func (*Key) ZAddNX

func (this *Key) ZAddNX(member, score interface{}) bool

Only update elements that not exist.

func (*Key) ZAddXX

func (this *Key) ZAddXX(member, score interface{}) bool

Only update elements that already exist.

func (*Key) ZCard

func (this *Key) ZCard() int

func (*Key) ZExists

func (this *Key) ZExists(member interface{}) bool

func (*Key) ZIncrBy

func (this *Key) ZIncrBy(member interface{}, d interface{}) *Result

d: int/float

func (*Key) ZPopMin

func (this *Key) ZPopMin(count int) []string

Removes and returns up to count members with the lowest scores in the sorted set stored at key. Returns: list of popped elements and scores.

func (*Key) ZRank

func (this *Key) ZRank(member interface{}) int

func (*Key) ZRem

func (this *Key) ZRem(member interface{}) bool

有序集合删除成员, 重复删除返回false

func (*Key) ZRemRangeByScore

func (this *Key) ZRemRangeByScore(min interface{}, max interface{}) int

Redis Zremrangebyscore 命令用于移除有序集中,指定分数(score)区间内的所有成员。

func (*Key) ZRevRank

func (this *Key) ZRevRank(member interface{}) int

func (*Key) ZScore

func (this *Key) ZScore(member interface{}) *Result

type Result

type Result struct {
	Reply    interface{}
	Err      error
	Encoding string
}

func Do

func Do(dbname, command string, args ...interface{}) *Result

func (*Result) Bool

func (this *Result) Bool() bool

func (*Result) Bytes

func (this *Result) Bytes() []byte

func (*Result) Float64

func (this *Result) Float64() float64

func (*Result) Float64s

func (this *Result) Float64s() []float64

func (*Result) Int

func (this *Result) Int() int

func (*Result) Int32

func (this *Result) Int32() int32

func (*Result) Int32s

func (this *Result) Int32s() []int32

func (*Result) Int64

func (this *Result) Int64() int64

func (*Result) Int64Map

func (this *Result) Int64Map() map[string]int64

func (*Result) Int64s

func (this *Result) Int64s() []int64

func (*Result) IntMap

func (this *Result) IntMap() map[string]int

func (*Result) Ints

func (this *Result) Ints() []int

func (*Result) String

func (this *Result) String() string

func (*Result) StringMap

func (this *Result) StringMap() map[string]string

func (*Result) Strings

func (this *Result) Strings() []string

func (*Result) Unmarshal

func (this *Result) Unmarshal(v interface{}) error

func (*Result) Values

func (this *Result) Values() []interface{}

Jump to

Keyboard shortcuts

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