svc_redis

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

README

svc_redis

service redis

Documentation

Index

Constants

View Source
const KeepTTL = -1

KeepTTL is a Redis KEEPTTL option to keep existing TTL, it requires your redis-server version >= 6.0, otherwise you will receive an error: (error) ERR syntax error. For example:

rdb.Set(ctx, key, value, redis.KeepTTL)

Variables

View Source
var (
	// ZPopMaxValue pop values of more then score
	ZPopMaxValue = NewScript(`local v = redis.call('ZREVRANGEBYSCORE',KEYS[1],'+inf','-inf','limit',0,ARGV[1]) if #v > 0 then redis.call('ZREM',KEYS[1], unpack(v)) end return v`)
	// ZPopMaxValueWithScore pop values of more then score withscores
	ZPopMaxValueWithScore = NewScript(`local v = redis.call('zrange',KEYS[1],'+inf',ARGV[1],'byscore','rev','limit',0,ARGV[2], 'withscores') for k = 1,#v,2 do redis.call('ZREM',KEYS[1], v[k]) end return v`)
	// LockerScriptUnlock redis locker unlock script
	LockerScriptUnlock = NewScript(`if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end`)
)
View Source
var DBType string = "redis"
View Source
var (
	ErrLockFailed = errors.New("redis locker lock failed")
)
View Source
var GetDBLink func(dbType string, dbName string) redis.UniversalClient = service.GetDBLink

GetDBLink get redis cache link

View Source
var RegisterDBName func(dbType string, dbName string) = service.RegisterDBName

RegisterDBName register redis cache config

Functions

func FormatMs

func FormatMs(ctx context.Context, dur time.Duration) int64

func FormatSec

func FormatSec(ctx context.Context, dur time.Duration) int64

func RedisScriptSHA

func RedisScriptSHA(src string) string

func UsePrecise

func UsePrecise(dur time.Duration) bool

Types

type RedisCacheService

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

func (*RedisCacheService) Finish

func (svc *RedisCacheService) Finish()
func (svc *RedisCacheService) GetDBLink(dbType string, dbName string) redis.UniversalClient

func (*RedisCacheService) Init

func (svc *RedisCacheService) Init(s app.Stoper) (err error)

func (*RedisCacheService) Name

func (svc *RedisCacheService) Name() string

func (*RedisCacheService) RegisterDBName

func (svc *RedisCacheService) RegisterDBName(dbType string, dbName string)

RegisterDBName register redis cache config

func (*RedisCacheService) Start

func (svc *RedisCacheService) Start(s app.Stoper) (err error)

func (*RedisCacheService) Stop

func (svc *RedisCacheService) Stop()

type Script

type Script struct {
	Script string
	Hash   string
}

func NewScript

func NewScript(src string) *Script

Directories

Path Synopsis
example
rds
Code generated by "gogen cfggen"; DO NOT EDIT.
Code generated by "gogen cfggen"; DO NOT EDIT.

Jump to

Keyboard shortcuts

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