gredis

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2025 License: MIT Imports: 16 Imported by: 0

README

gredis

SetLog
package main

import (
	"fmt"

	"github.com/grpc-boot/gredis"
)

func init() {
	gredis.SetErrorLog(func(err error, cmd string, opt *gredis.Option) {
		fmt.Printf("exec [%s] failed at[%s]\n", cmd, opt.Addr())
	})
}
Lock
package main

import (
	"context"
	"fmt"
	"os"
	"time"

	"github.com/grpc-boot/gredis"
)

const (
	redKey = `redis`
)

func init() {
	gredis.SetErrorLog(func(err error, cmd string, opt *gredis.Option) {
		fmt.Printf("exec [%s] failed at[%s]\n", cmd, opt.Addr())
	})

	opt, err := gredis.JsonOption([]byte(`{}`))
	if err != nil {
		fmt.Printf("init redis option failed, err:%v\n", err)
		os.Exit(1)
	}

	gredis.Put(redKey, opt)
}

func main() {
	var (
		red = gredis.Get(redKey)
		key = `lockT`
	)

	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
	defer cancel()

	token, err := red.Acquire(ctx, key, 8)
	if err != nil {
		fmt.Printf("acquire redis failed, err:%v\n", err)
		return
	}

	fmt.Printf("got lock token:%v\n", token)

	// todo somethings
	time.Sleep(time.Second)

	// release lock
	_, _ = red.Release(context.Background(), key, token)
}
Traffic
package main

import (
	"context"
	"fmt"
	"os"
	"strconv"
	"time"

	"github.com/grpc-boot/gredis"
)

const (
	redKey = `redis`
)

func init() {
	gredis.SetErrorLog(func(err error, cmd string, opt *gredis.Option) {
		fmt.Printf("exec [%s] failed at[%s]\n", cmd, opt.Addr())
	})

	opt, err := gredis.JsonOption([]byte(`{}`))
	if err != nil {
		fmt.Printf("init redis option failed, err:%v\n", err)
		os.Exit(1)
	}

	gredis.Put(redKey, opt)
}

func main() {
	var (
		red = gredis.Get(redKey)
	)

	limitByIncr(red)
	time.Sleep(time.Second * 3)
	limitByDay(red)
	time.Sleep(time.Second * 3)
	limitByMinute(red)
	time.Sleep(time.Second * 3)
	limitBySecond(red)
}

func limitByIncr(red *gredis.Pool) {
	fmt.Println("limit by incr start")

	var (
		key     = fmt.Sprintf(`trafficIncr:%s`, time.Now().Format("2006-01-02"))
		num     = 128
		okCount = 0
		start   = time.Now()
	)

	for i := 0; i < num; i++ {
		var (
			ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
			ok, err     = red.AcquireByIncr(ctx, key, 1, 100, 3600)
		)

		cancel()
		if err != nil {
			fmt.Printf("acquire redis failed, err:%v\n", err)
			return
		}

		if !ok {
			fmt.Println("limited by incr")
		} else {
			okCount++
			fmt.Printf("acquire redis success: %d cost: %s\n", okCount, time.Since(start))
		}
		time.Sleep(time.Millisecond * 5)
	}

	fmt.Println("limit by incr end")
}

// 每秒100个请求,突发可以突破到128个
func limitBySecond(red *gredis.Pool) {
	fmt.Println("limit by second start")

	var (
		key     = `trafficSecondsT`
		num     = 1000
		okCount = 0
		start   = time.Now()
	)

	for i := 0; i < num; i++ {
		var (
			current     = time.Now().Unix()
			ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
			ok, err     = red.AcquireByLeakyBucket(ctx, key, current, 128, 100, 1, 3600)
		)

		cancel()
		if err != nil {
			fmt.Printf("acquire redis failed, err:%v\n", err)
			return
		}

		if !ok {
			fmt.Println("limited by seconds")
		} else {
			okCount++
			fmt.Printf("acquire redis success: %d cost: %s\n", okCount, time.Since(start))
		}
		time.Sleep(time.Millisecond * 5)
	}

	fmt.Println("limit by second end")
}

// 每分钟60个请求
func limitByMinute(red *gredis.Pool) {
	fmt.Println("limit by minute start")
	var (
		key     = `trafficMinuteT`
		num     = 1000
		okCount = 0
		start   = time.Now()
	)

	for i := 0; i < num; i++ {
		var (
			current, _  = strconv.ParseInt(time.Now().Format("200601021504"), 10, 64)
			ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
			ok, err     = red.AcquireByLeakyBucket(ctx, key, current, 60, 60, 1, 3600)
		)

		cancel()
		if err != nil {
			fmt.Printf("acquire redis failed, err:%v\n", err)
			return
		}

		if !ok {
			fmt.Println("limited by minute")
		} else {
			okCount++
			fmt.Printf("acquire redis success: %d cost: %s\n", okCount, time.Since(start))
		}
		time.Sleep(time.Millisecond * 500)
	}

	fmt.Println("limit by minute end")
}

func limitByDay(red *gredis.Pool) {
	fmt.Println("limit by day start")
	var (
		key     = `trafficDayT`
		num     = 100
		okCount = 0
		start   = time.Now()
	)

	for i := 0; i < num; i++ {
		var (
			current, _  = strconv.ParseInt(time.Now().Format("20060102"), 10, 64)
			ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
			ok, err     = red.AcquireByLeakyBucket(ctx, key, current, 60, 60, 1, 3600*24*2)
		)

		cancel()
		if err != nil {
			fmt.Printf("acquire redis failed, err:%v\n", err)
			return
		}

		if !ok {
			fmt.Println("limited by day")
		} else {
			okCount++
			fmt.Printf("acquire redis success: %d cost: %s\n", okCount, time.Since(start))
		}
		time.Sleep(time.Millisecond * 50)
	}

	fmt.Println("limit by day end")
}
Cache
package main

import (
	"context"
	"fmt"
	"os"
	"time"

	"github.com/grpc-boot/gredis"

	"google.golang.org/protobuf/proto"
	"google.golang.org/protobuf/types/known/structpb"
)

const (
	redKey = `redis`
)

func init() {
	gredis.SetErrorLog(func(err error, cmd string, opt *gredis.Option) {
		fmt.Printf("exec [%s] failed at[%s]\n", cmd, opt.Addr())
	})

	opt, err := gredis.JsonOption([]byte(`{}`))
	if err != nil {
		fmt.Printf("init redis option failed, err:%v\n", err)
		os.Exit(1)
	}

	gredis.Put(redKey, opt)
}

func main() {
	var (
		red = gredis.Get(redKey)
		key = `cacheT`
	)

	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
	defer cancel()

	ci, err := red.ComCache(ctx, key, 15, func() (value []byte, err error) {
		// todo
		time.Sleep(time.Second * 3)

		// 仅支持基本的数据类型,不支持嵌套切片和map等结构
		data, err := structpb.NewStruct(map[string]any{
			"id":      123,
			"age":     uint8(35),
			"name":    "Masco",
			"male":    true,
			"height":  1.73,
			"current": time.Now().Format("2006-01-02 15:04:05"),
		})

		if err != nil {
			return
		}

		return proto.Marshal(data)
	})

	if err != nil {
		fmt.Printf("get cache from redis failed, err:%v\n", err)
		return
	}

	data, err := ci.MapData()
	if err != nil {
		fmt.Printf("get map data failed, err:%v\n", err)
	}

	for k, v := range data {
		fmt.Printf("key:%s, type: %T value:%v\n", k, v, v)
	}
}
Geo
package main

import (
	"context"
	"fmt"
	"os"
	"time"

	"github.com/grpc-boot/gredis"

	"github.com/redis/go-redis/v9"
)

const (
	redKey = `redis`
)

func init() {
	gredis.SetErrorLog(func(err error, cmd string, opt *gredis.Option) {
		fmt.Printf("exec [%s] failed at[%s]\n", cmd, opt.Addr())
	})

	opt, err := gredis.JsonOption([]byte(`{}`))
	if err != nil {
		fmt.Printf("init redis option failed, err:%v\n", err)
		os.Exit(1)
	}

	gredis.Put(redKey, opt)
}

func main() {
	var (
		red = gredis.Get(redKey)
		key = `geoT`
	)

	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
	defer cancel()

	newCount, err := red.GeoAdd(ctx,
		key,
		&redis.GeoLocation{
			Name:      "王府井金街店",
			Longitude: 116.410256,
			Latitude:  39.909594,
		},
		&redis.GeoLocation{
			Name:      "西单明珠店",
			Longitude: 116.376018,
			Latitude:  39.909956,
		},
		&redis.GeoLocation{
			Name:      "密云鼓楼大街店",
			Longitude: 116.846254,
			Latitude:  40.375323,
		},
	)

	if err != nil {
		fmt.Printf("redis add failed, err:%v\n", err)
	}

	fmt.Printf("redis add success, count:%d\n", newCount)

	locs, err := red.GeoRadius(ctx, key, 116.376018, 39.909956, &redis.GeoRadiusQuery{
		Radius:      1000, // 搜索半径
		Unit:        "km", // 单位
		WithCoord:   true, // 返回坐标
		WithDist:    true, // 返回距离
		WithGeoHash: true, // 返回geo hash
		Count:       100,
		Sort:        "ASC",
	})

	if err != nil {
		fmt.Printf("redis query failed, err:%v\n", err)
	}
	fmt.Printf("geo radius: %+v\n", locs)

	dist, err := red.GeoDist(ctx, key, "西单明珠店", "密云鼓楼大街店", "km")
	if err != nil {
		fmt.Printf("redis query failed, err:%v\n", err)
	}
	fmt.Printf("geo dist: %+v\n", dist)

	pos, err := red.GeoPos(ctx, key, "西单明珠店", "密云鼓楼大街店")
	if err != nil {
		fmt.Printf("redis query failed, err:%v\n", err)
	}
	fmt.Printf("geo pos[0] lat:%v long:%v\n", pos[0].Latitude, pos[0].Longitude)
	fmt.Printf("geo pos[1] lat:%v long:%v\n", pos[1].Latitude, pos[1].Longitude)
}

Documentation

Index

Constants

View Source
const (
	OK      = `OK`
	Success = 1
	ErrNil  = redis.Nil
)

Variables

View Source
var (
	DefaultOption = func() Option {
		return Option{
			Network:               "tcp",
			Host:                  "127.0.0.1",
			Port:                  6379,
			MaxRetries:            3,
			ContextTimeoutEnabled: true,
			PoolSize:              16,
			MinIdleConns:          2,
			MaxIdleConns:          8,
			MaxActiveConns:        16,
		}
	}

	JsonOption = func(data []byte) (opt Option, err error) {
		opt = DefaultOption()
		err = json.Unmarshal(data, &opt)
		return
	}

	YamlOption = func(data []byte) (opt Option, err error) {
		opt = DefaultOption()
		err = yaml.Unmarshal(data, &opt)
		return
	}
)
View Source
var (
	DefaultCacheTimeout = time.Hour * 24
)
View Source
var (
	Uint32Hash = crc32.ChecksumIEEE
)

Functions

func Bytes2String

func Bytes2String(b []byte) string

Bytes2String converts byte slice to string.

func IsNil

func IsNil(err error) bool

func KeyHash

func KeyHash(key interface{}) uint32

func Put

func Put(key string, opts ...Option)

func SetErrorLog

func SetErrorLog(l ErrLog)

func String2Bytes

func String2Bytes(s string) []byte

String2Bytes converts string to byte slice.

func WriteLog

func WriteLog(err error, cmd string, opt *Option)

Types

type CacheHandler

type CacheHandler func() (value []byte, err error)

type ConfigParam

type ConfigParam map[string]string

func (ConfigParam) Clone

func (p ConfigParam) Clone() ConfigParam

func (ConfigParam) Exists

func (p ConfigParam) Exists(key string) bool

Exists 是否存在

func (ConfigParam) Get

func (p ConfigParam) Get(key string) string

Get 获取字符串

func (ConfigParam) ToBool

func (p ConfigParam) ToBool(key string) bool

ToBool 获取Bool

func (ConfigParam) ToFloat64

func (p ConfigParam) ToFloat64(key string) float64

ToFloat64 获取Float64

func (ConfigParam) ToInt

func (p ConfigParam) ToInt(key string) int

ToInt 获取Int

func (ConfigParam) ToInt64

func (p ConfigParam) ToInt64(key string) int64

ToInt64 获取Int64

func (ConfigParam) ToUint8

func (p ConfigParam) ToUint8(key string) uint8

ToUint8 获取Uint8

type ErrLog

type ErrLog func(err error, cmd string, opt *Option)

type Key

type Key interface {
	~string | ~uint8 | ~int8 | ~uint16 | ~int16 | ~uint32 | ~int32 | ~uint | ~int | ~uint64 | ~int64
}

type Option

type Option struct {
	Network               string `json:"network" yaml:"network"`
	Host                  string `json:"host" yaml:"host"`
	Port                  uint32 `json:"port" yaml:"port"`
	Username              string `json:"username" yaml:"username"`
	Password              string `json:"password" yaml:"password"`
	DB                    uint32 `json:"DB" yaml:"DB"`
	MaxRetries            uint32 `json:"maxRetries" yaml:"maxRetries"`
	DialTimeoutSecond     uint32 `json:"dialTimeoutSecond" yaml:"dialTimeoutSecond"`
	ReadTimeoutSecond     uint32 `json:"readTimeoutSecond" yaml:"readTimeoutSecond"`
	WriteTimeoutSecond    uint32 `json:"writeTimeoutSecond" yaml:"writeTimeoutSecond"`
	ContextTimeoutEnabled bool   `json:"contextTimeoutEnabled" yaml:"contextTimeoutEnabled"`
	PoolSize              uint32 `json:"poolSize" yaml:"poolSize"`
	PoolWaitTimeoutSecond uint32 `json:"poolWaitTimeoutSecond" yaml:"poolWaitTimeoutSecond"`
	MinIdleConns          uint32 `json:"minIdleConns" yaml:"minIdleConns"`
	MaxIdleConns          uint32 `json:"maxIdleConns" yaml:"maxIdleConns"`
	MaxActiveConns        uint32 `json:"maxActiveConns" yaml:"maxActiveConns"`
	ConnMaxIdleTimeSecond uint32 `json:"connMaxIdleTimeSecond" yaml:"connMaxIdleTimeSecond"`
	ConnMaxLifetimeSecond uint32 `json:"connMaxLifetimeSecond" yaml:"connMaxLifetimeSecond"`
	TLSConfig             *tls.Config
	// contains filtered or unexported fields
}

func (*Option) Addr

func (o *Option) Addr() string

func (*Option) ConnMaxIdleTime

func (o *Option) ConnMaxIdleTime() time.Duration

func (*Option) ConnMaxLifetime

func (o *Option) ConnMaxLifetime() time.Duration

func (*Option) DialTimeout

func (o *Option) DialTimeout() time.Duration

func (*Option) Id

func (o *Option) Id() string

func (*Option) NewClient

func (o *Option) NewClient() *redis.Client

func (*Option) PoolWaitTimeout

func (o *Option) PoolWaitTimeout() time.Duration

func (*Option) ReadTimeout

func (o *Option) ReadTimeout() time.Duration

func (*Option) ToOptions

func (o *Option) ToOptions() *redis.Options

func (*Option) WriteTimeout

func (o *Option) WriteTimeout() time.Duration

type Pool

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

func Get

func Get(key string) (p *Pool)

func GetWithIndex

func GetWithIndex(key string, index int) (p *Pool)

func GetWithShard

func GetWithShard[K Key](containerKey string, shardKey K) (p *Pool)

func NewPool

func NewPool(opt *Option) *Pool

func (*Pool) Acquire

func (p *Pool) Acquire(ctx context.Context, key string, lockSeconds int64) (token int64, err error)

func (*Pool) AcquireByIncr

func (p *Pool) AcquireByIncr(ctx context.Context, key string, acqNum, limitNum int64, keyTimeoutSecond int) (ok bool, err error)

func (*Pool) AcquireByLeakyBucket

func (p *Pool) AcquireByLeakyBucket(ctx context.Context, key string, current int64, capacity, speed, acqNum, keyTimeoutSecond int) (ok bool, err error)

func (*Pool) BitCount

func (p *Pool) BitCount(ctx context.Context, key string, bitCount *redis.BitCount) (num int64, err error)

func (*Pool) BitField

func (p *Pool) BitField(ctx context.Context, key string, values ...any) (res []int64, err error)

BitField is an API after Redis version 3.2 type: 位宽格式:u(无符号)/i(有符号)+ 位数(1-64) u8(8位无符号整数) offset: 位段起始位置(比特偏移量),支持#前缀指定字段序(如#0第1个字段) 0 或 #1 原子增加第2个字段(4位无符号计数器) BITFIELD api_count OVERFLOW SAT INCRBY u4 #1 1 OVERFLOW: WRAP 回绕(默认):溢出时从最小值重新计数 循环计数器(如ID生成) OVERFLOW: SAT 饱和:超出上限取最大值,低于下限取最小值 限制数值范围(如温度值) OVERFLOW: FAIL 失败:溢出时返回 nil,不执行操作 严格数值控制(如余额)

func (*Pool) BitOpAnd

func (p *Pool) BitOpAnd(ctx context.Context, destKey string, keys ...string) (bytesLen int64, err error)

func (*Pool) BitOpNot

func (p *Pool) BitOpNot(ctx context.Context, destKey string, key string) (bytesLen int64, err error)

func (*Pool) BitOpOr

func (p *Pool) BitOpOr(ctx context.Context, destKey string, keys ...string) (bytesLen int64, err error)

func (*Pool) BitOpXor

func (p *Pool) BitOpXor(ctx context.Context, destKey string, keys ...string) (bytesLen int64, err error)

func (*Pool) ComCache

func (p *Pool) ComCache(ctx context.Context, key string, timeoutSeconds int64, handler CacheHandler) (*proto2.CacheItem, error)

func (*Pool) ConfigGet

func (p *Pool) ConfigGet(ctx context.Context, parameter string) (res ConfigParam, err error)

func (*Pool) ConfigSet

func (p *Pool) ConfigSet(ctx context.Context, parameter, value string) (ok bool, err error)

func (*Pool) Del

func (p *Pool) Del(ctx context.Context, keys ...string) (delNum int64, err error)

func (*Pool) Exists

func (p *Pool) Exists(ctx context.Context, keys ...string) (existsNum int64, err error)

func (*Pool) Expire

func (p *Pool) Expire(ctx context.Context, key string, timeout time.Duration) (ok bool, err error)

func (*Pool) ExpireAt

func (p *Pool) ExpireAt(ctx context.Context, key string, tm time.Time) (exists bool, err error)

func (*Pool) GeoAdd

func (p *Pool) GeoAdd(ctx context.Context, key string, geoLocations ...*redis.GeoLocation) (newCount int64, err error)

func (*Pool) GeoDist

func (p *Pool) GeoDist(ctx context.Context, key string, member1, member2, unit string) (float64, error)

func (*Pool) GeoPos

func (p *Pool) GeoPos(ctx context.Context, key string, members ...string) ([]*redis.GeoPos, error)

func (*Pool) GeoRadius

func (p *Pool) GeoRadius(ctx context.Context, key string, longitude, latitude float64, query *redis.GeoRadiusQuery) ([]redis.GeoLocation, error)

func (*Pool) GeoSearch

func (p *Pool) GeoSearch(ctx context.Context, key string, q *redis.GeoSearchQuery) ([]string, error)

func (*Pool) Get

func (p *Pool) Get(ctx context.Context, key string) (value string, err error)

func (*Pool) GetBit

func (p *Pool) GetBit(ctx context.Context, key string, offset int64) (value int64, err error)

func (*Pool) GetBytes

func (p *Pool) GetBytes(ctx context.Context, key string) (value []byte, err error)

func (*Pool) HDel

func (p *Pool) HDel(ctx context.Context, key string, fields ...string) (delNum int64, err error)

func (*Pool) HExists

func (p *Pool) HExists(ctx context.Context, key string, field string) (exists bool, err error)

func (*Pool) HGet

func (p *Pool) HGet(ctx context.Context, key, field string) (value string, err error)

func (*Pool) HGetAll

func (p *Pool) HGetAll(ctx context.Context, key string) (value map[string]string, err error)

func (*Pool) HGetBytes

func (p *Pool) HGetBytes(ctx context.Context, key, field string) (value []byte, err error)

func (*Pool) HIncrBy

func (p *Pool) HIncrBy(ctx context.Context, key, field string, incr int64) (value int64, err error)

func (*Pool) HIncrByFloat

func (p *Pool) HIncrByFloat(ctx context.Context, key, field string, incr float64) (value float64, err error)

func (*Pool) HMGet

func (p *Pool) HMGet(ctx context.Context, key string, fields ...string) (values []string, err error)

func (*Pool) HMGetMap

func (p *Pool) HMGetMap(ctx context.Context, key string, fields ...string) (valMap map[string]string, err error)

func (*Pool) HMSet

func (p *Pool) HMSet(ctx context.Context, key string, values ...any) (ok bool, err error)

func (*Pool) HScan

func (p *Pool) HScan(ctx context.Context, key string, cursor uint64, match string, count int64) (keys []string, newCursor uint64, err error)

func (*Pool) HSet

func (p *Pool) HSet(ctx context.Context, key, field string, value any) (isNew int64, err error)

func (*Pool) HSetMap

func (p *Pool) HSetMap(ctx context.Context, key string, fv map[string]any) (value bool, err error)

func (*Pool) HSetNX

func (p *Pool) HSetNX(ctx context.Context, key, field string, value any) (ok bool, err error)

func (*Pool) HasLock

func (p *Pool) HasLock(ctx context.Context, key string) (hasLock bool, err error)

func (*Pool) IncrBy

func (p *Pool) IncrBy(ctx context.Context, key string, value int64) (newValue int64, err error)

func (*Pool) IncrByFloat

func (p *Pool) IncrByFloat(ctx context.Context, key string, value float64) (newValue float64, err error)

func (*Pool) Info

func (p *Pool) Info(ctx context.Context, sections ...string) (info string, err error)

func (*Pool) InfoMap

func (p *Pool) InfoMap(ctx context.Context, sections ...string) (info map[string]map[string]string, err error)

func (*Pool) LLen

func (p *Pool) LLen(ctx context.Context, key string) (length int64, err error)

func (*Pool) LPop

func (p *Pool) LPop(ctx context.Context, key string) (value string, err error)

func (*Pool) LPush

func (p *Pool) LPush(ctx context.Context, key string, values ...any) (length int64, err error)

func (*Pool) LRange

func (p *Pool) LRange(ctx context.Context, key string, start, stop int64) (items []string, err error)

func (*Pool) LRem

func (p *Pool) LRem(ctx context.Context, key string, count int64, val any) (items int64, err error)

func (*Pool) MGet

func (p *Pool) MGet(ctx context.Context, keys ...string) (values []string, err error)

func (*Pool) MGetBytes

func (p *Pool) MGetBytes(ctx context.Context, keys ...string) (values [][]byte, err error)

func (*Pool) MSet

func (p *Pool) MSet(ctx context.Context, values ...any) (ok bool, err error)

func (*Pool) Option

func (p *Pool) Option() *Option

func (*Pool) RPop

func (p *Pool) RPop(ctx context.Context, key string) (value string, err error)

func (*Pool) RPopLPush

func (p *Pool) RPopLPush(ctx context.Context, srcKey, dstKey string) (value string, err error)

func (*Pool) RPush

func (p *Pool) RPush(ctx context.Context, key string, values ...any) (length int64, err error)

func (*Pool) Release

func (p *Pool) Release(ctx context.Context, key string, token int64) (delNum int64, err error)

func (*Pool) RunScript

func (p *Pool) RunScript(ctx context.Context, script *redis.Script, keys []string, args ...any) (res any, err error)

func (*Pool) SAdd

func (p *Pool) SAdd(ctx context.Context, key string, members ...any) (newNum int64, err error)

func (*Pool) SCard

func (p *Pool) SCard(ctx context.Context, key string) (length int64, err error)

func (*Pool) SIsMember

func (p *Pool) SIsMember(ctx context.Context, key string, member any) (exists bool, err error)

func (*Pool) SMembers

func (p *Pool) SMembers(ctx context.Context, key string) (list []string, err error)

func (*Pool) SPop

func (p *Pool) SPop(ctx context.Context, key string) (member string, err error)

func (*Pool) SPopN

func (p *Pool) SPopN(ctx context.Context, key string, count int64) (members []string, err error)

func (*Pool) SRem

func (p *Pool) SRem(ctx context.Context, key string, members ...any) (delNum int64, err error)

func (*Pool) SScan

func (p *Pool) SScan(ctx context.Context, key string, cursor uint64, match string, count int64) (keys []string, newCursor uint64, err error)

func (*Pool) Scan

func (p *Pool) Scan(ctx context.Context, cursor uint64, match string, count int64) (keys []string, newCursor uint64, err error)

func (*Pool) Set

func (p *Pool) Set(ctx context.Context, key string, value any, expiration time.Duration) (ok bool, err error)

func (*Pool) SetBit

func (p *Pool) SetBit(ctx context.Context, key string, offset int64, value int64) (oldValue int64, err error)

func (*Pool) SetEx

func (p *Pool) SetEx(ctx context.Context, key string, value any, timeout time.Duration) (ok bool, err error)

func (*Pool) SetNx

func (p *Pool) SetNx(ctx context.Context, key string, value any, timeout time.Duration) (ok bool, err error)

func (*Pool) Ttl

func (p *Pool) Ttl(ctx context.Context, key string) (duration time.Duration, err error)

func (*Pool) Type

func (p *Pool) Type(ctx context.Context, key string) (t string, err error)

func (*Pool) ZAdd

func (p *Pool) ZAdd(ctx context.Context, key string, members ...redis.Z) (newNum int64, err error)

func (*Pool) ZCard

func (p *Pool) ZCard(ctx context.Context, key string) (length int64, err error)

func (*Pool) ZCount

func (p *Pool) ZCount(ctx context.Context, key, min, max string) (count int64, err error)

func (*Pool) ZIncrBy

func (p *Pool) ZIncrBy(ctx context.Context, key string, increment float64, member string) (score float64, err error)

func (*Pool) ZRange

func (p *Pool) ZRange(ctx context.Context, key string, start, stop int64) (list []string, err error)

func (*Pool) ZRangeByScore

func (p *Pool) ZRangeByScore(ctx context.Context, key string, opt *redis.ZRangeBy) (list []string, err error)

func (*Pool) ZRangeByScoreWithScores

func (p *Pool) ZRangeByScoreWithScores(ctx context.Context, key string, opt *redis.ZRangeBy) (list []redis.Z, err error)

func (*Pool) ZRangeWithScores

func (p *Pool) ZRangeWithScores(ctx context.Context, key string, start, stop int64) (list []redis.Z, err error)

func (*Pool) ZRank

func (p *Pool) ZRank(ctx context.Context, key, member string) (rank int64, err error)

func (*Pool) ZRevRange

func (p *Pool) ZRevRange(ctx context.Context, key string, start, stop int64) (list []string, err error)

func (*Pool) ZRevRangeWithScores

func (p *Pool) ZRevRangeWithScores(ctx context.Context, key string, start, stop int64) (list []redis.Z, err error)

func (*Pool) ZRevRank

func (p *Pool) ZRevRank(ctx context.Context, key, member string) (rank int64, err error)

func (*Pool) ZScan

func (p *Pool) ZScan(ctx context.Context, key string, cursor uint64, match string, count int64) (keys []string, newCursor uint64, err error)

func (*Pool) ZScore

func (p *Pool) ZScore(ctx context.Context, key, member string) (score float64, err error)

Directories

Path Synopsis
example
cache command
geo command
lock command
traffic command

Jump to

Keyboard shortcuts

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