Documentation
¶
Index ¶
- Constants
- Variables
- func FormatMs(ctx context.Context, dur time.Duration) int64
- func FormatSec(ctx context.Context, dur time.Duration) int64
- func RedisScriptSHA(src string) string
- func UsePrecise(dur time.Duration) bool
- type RedisCacheService
- func (svc *RedisCacheService) Finish()
- func (svc *RedisCacheService) GetDBLink(dbType string, dbName string) redis.UniversalClient
- func (svc *RedisCacheService) Init(s app.Stoper) (err error)
- func (svc *RedisCacheService) Name() string
- func (svc *RedisCacheService) RegisterDBName(dbType string, dbName string)
- func (svc *RedisCacheService) Start(s app.Stoper) (err error)
- func (svc *RedisCacheService) Stop()
- type Script
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 RedisScriptSHA ¶
func UsePrecise ¶
Types ¶
type RedisCacheService ¶
type RedisCacheService struct {
// contains filtered or unexported fields
}
func (*RedisCacheService) Finish ¶
func (svc *RedisCacheService) Finish()
func (*RedisCacheService) GetDBLink ¶
func (svc *RedisCacheService) GetDBLink(dbType string, dbName string) redis.UniversalClient
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) Stop ¶
func (svc *RedisCacheService) Stop()
Click to show internal directories.
Click to hide internal directories.