rediscli

package
v0.0.0-...-c42b9c9 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package rediscli for mgr redis cli

Index

Constants

View Source
const (
	DEFAULT_MAX_CONN      = 3500
	DEFAULT_MAX_IDEL_CONN = 3000
	DEFAULT_IDEL_TIMEOUT  = 300 // use time.Second
)
View Source
const (
	KEY_PREFIX = "redislock::"
)

Variables

View Source
var (
	SecKillErrKeyNotExist = errors.New("key not exist")
	SecKillErrSelledOut   = errors.New("selled out")
	SecKillErrNotEnough   = errors.New("not enough")
)
View Source
var KeyExistError = errors.New("rediskey exist")

Functions

func NanoToMills

func NanoToMills(nanoTime int64) int64

func SecKillRetCodeToError

func SecKillRetCodeToError(retCode int64) error

SecKillRetCodeToError func get code to err

Types

type DLock

type DLock struct {
	RedisCli *RedisCli
}

func CreateDLock

func CreateDLock(cli *RedisCli) *DLock

Create DLock handler

func (*DLock) Lock

func (p *DLock) Lock(key, value string, timeout int) error

func (*DLock) Unlock

func (p *DLock) Unlock(key, value string) (bool, error)

bool 为false表示没有删除,为true表示成功删除

type LockService

type LockService interface {
	TryLock(cli *RedisCli) error
	Unlock(cli *RedisCli) (bool, error)
	SetTimeout(cli *RedisCli) error
}

type RedisCli

type RedisCli struct {
	RedisPool *redis.Pool
}

RedisCli redis cli instance

func (*RedisCli) Decrease

func (p *RedisCli) Decrease(pool, key string) (string, error)

Decrease func Decrease

func (*RedisCli) Delete

func (p *RedisCli) Delete(key string) (bool, error)

Delete delete a kye

func (*RedisCli) DescBy

func (p *RedisCli) DescBy(key string, count int64) (int64, error)

DescBy func DescBy

func (*RedisCli) Exists

func (p *RedisCli) Exists(key string) bool

Exists check a key

func (*RedisCli) Expire

func (p *RedisCli) Expire(key string, second int) error

Expire func Expire

func (*RedisCli) Get

func (p *RedisCli) Get(key string) ([]byte, error)

Get get a key

func (*RedisCli) IncrBy

func (p *RedisCli) IncrBy(key string, count int64) (int64, error)

IncrBy func incrBy

func (*RedisCli) Increase

func (p *RedisCli) Increase(key string) (string, error)

Increase func Increase

func (*RedisCli) LPop

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

LPop pop

func (*RedisCli) LRange

func (p *RedisCli) LRange(key string, begin, end int) ([]string, error)

LRange LRange LRange

func (*RedisCli) LikeDeletes

func (p *RedisCli) LikeDeletes(key string) error

LikeDeletes batch delete

func (*RedisCli) RPush

func (p *RedisCli) RPush(key string, value string) (int64, error)

RPush Push back

func (*RedisCli) RPushAndSetExpire

func (p *RedisCli) RPushAndSetExpire(key string, value string, second int) (int64, error)

RPush Push back

func (*RedisCli) Set

func (p *RedisCli) Set(key, value string, time int) error

Set key,value,time

func (*RedisCli) SetNX

func (p *RedisCli) SetNX(key, value string, time int) error

SetNX a key/value 已存在返回错误信息

func (*RedisCli) TTL

func (p *RedisCli) TTL(key string) (int, error)

TTL get the key remain expire time

type RedisFactory

type RedisFactory struct {
	MaxIdleConn int
	MaxConn     int
	IdleTimeout int
}

RedisFactory struct

var (
	Factory RedisFactory
)

func (*RedisFactory) CreateRedisCli

func (p *RedisFactory) CreateRedisCli(pwd, url string) (*RedisCli, error)

CreateRedisCli func create redis cli

type RedisSetnxLock

type RedisSetnxLock struct {
	Key               string
	Value             string
	TimeoutSecond     int
	MaxWaitMills      int
	MillsBetweenTries int
}

func (RedisSetnxLock) SetTimeout

func (r RedisSetnxLock) SetTimeout(redisCli *RedisCli) error

func (RedisSetnxLock) TryLock

func (r RedisSetnxLock) TryLock(redisCli *RedisCli) error

func (RedisSetnxLock) Unlock

func (r RedisSetnxLock) Unlock(redisCli *RedisCli) (bool, error)

type SecKill

type SecKill struct {
	RedisCli *RedisCli
}

SecKill sec kill struct

func CreateSecKillHandler

func CreateSecKillHandler(cli *RedisCli) *SecKill

CreateSecKillHandler func create sec kill handler

func (*SecKill) Aquire

func (p *SecKill) Aquire(key string, num int64) error

Aquire func aquire

func (*SecKill) BuildData

func (p *SecKill) BuildData(key string, total int64) error

BuildData func mset data

Jump to

Keyboard shortcuts

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