Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrTypeNil = errors.New("数据为nil")
View Source
var ErrUnknownType = errors.New("未知数据类型")
View Source
var HIncrMinZeroScript = redis.NewScript(`if (redis.call('exists', KEYS[1]) == 1) then
local stock = tonumber(redis.call('hget', KEYS[1], KEYS[2]));
local num = tonumber(ARGV[1]);
if (stock == -1) then
return -1;
end;
if (stock + num >= 0) then
return redis.call('HINCRBY', KEYS[1], KEYS[2], num);
elseif (stock + num < 0) then
return redis.call('HSET', KEYS[1], KEYS[2], 0)
end;
return -2;
end;
return -3;`)
View Source
var HIncrTopLimitScript = redis.NewScript(`
local key = KEYS[1]
local field = ARGV[1]
local increment = tonumber(ARGV[2])
local maxValue = tonumber(ARGV[3])
local currentValue = tonumber(redis.call('HGET', key, field))
if currentValue == nil then
currentValue = 0
end
if currentValue == maxValue then
return maxValue
end
local newValue = currentValue + increment
if newValue > maxValue then
newValue = maxValue
end
redis.call('HSET', key, field, newValue)
return newValue
`)
View Source
var HIncrUnMinusScript = redis.NewScript(`if (redis.call('exists', KEYS[1]) == 1) then
local stock = tonumber(redis.call('hget', KEYS[1], KEYS[2]));
local num = tonumber(ARGV[1]);
if (stock == -1) then
return -1;
end;
if (stock + num >= 0) then
return redis.call('HINCRBY', KEYS[1], KEYS[2], num);
end;
return -2;
end;
return -3;`)
View Source
var IncrScript = redis.NewScript(`if (redis.call('exists', KEYS[1]) == 1) then
local stock = tonumber(redis.call('get', KEYS[1]));
local num = tonumber(ARGV[1]);
if (stock == -1) then
return -1;
end;
if (stock + num >= 0) then
return redis.call('incrby', KEYS[1], num);
end;
return -2;
end;
return -3;`)
View Source
var IncrTopLimitScript = redis.NewScript(`
local stock = tonumber(redis.call('get', KEYS[1]));
if type(stock) == "nil" then
stock = 0
end;
local num = tonumber(ARGV[1]);
local top = tonumber(ARGV[2]);
if ( stock + num > top) then
return 0;
else
return redis.call('incrby', KEYS[1], num);
end;
`)
Functions ¶
Types ¶
type DelayedQueue ¶
type DelayedQueue interface { // 添加队列消息 Put(ctx context.Context, z []*redis.Z) error // 处理单条队列消息 DealWithOnce(ctx context.Context, min, max float64) (*redis.Z, error) // 处理多条队列消息 DealWithMultiple(ctx context.Context, min, max float64, count int64) ([]redis.Z, error) // 队列消息加速 Expedite(ctx context.Context, member string, score float64) error }
func NewDelayedQueue ¶
func NewDelayedQueue(rd *Client, fun QueueDealWith, keyName, lockKey, lockVal string, lockTtl time.Duration) DelayedQueue
type QueueDealWith ¶
type RedisLock ¶
type RedisLock struct {
// contains filtered or unexported fields
}
func NewRedisLock ¶
func (*RedisLock) GetLockKey ¶
func (*RedisLock) GetLockVal ¶
type RedisSubscribe ¶
type RedisSubscribe struct {
// contains filtered or unexported fields
}
func NewRedisSubscribe ¶
func NewRedisSubscribe(conn *redis.Client) *RedisSubscribe
func (*RedisSubscribe) PubMessage ¶
func (r *RedisSubscribe) PubMessage(ctx context.Context, channel, msg string)
func (*RedisSubscribe) SubMessage ¶
func (r *RedisSubscribe) SubMessage(ctx context.Context, channel, msg string)
Click to show internal directories.
Click to hide internal directories.