Documentation
¶
Index ¶
- Variables
- type Client
- func (c *Client) Close() error
- func (c *Client) HIncrMinZero(ctx context.Context, key, subKey string, num int64) (int64, error)
- func (c *Client) HIncrUnMinus(ctx context.Context, key, subKey string, num int64) (int64, error)
- func (c *Client) IncrUnMinus(ctx context.Context, key string, num int64) (int64, error)
- func (c *Client) Process(cmd redis.Cmder) error
- type Config
- type RedisLock
Constants ¶
This section is empty.
Variables ¶
View Source
var HIncrMinZeroScript = redis2.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 HIncrScript = redis2.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 = redis2.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;`)
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
redis.Cmdable
}
func (*Client) HIncrMinZero ¶
func (*Client) HIncrUnMinus ¶
func (*Client) IncrUnMinus ¶
type RedisLock ¶
type RedisLock struct {
// contains filtered or unexported fields
}
func NewRedisLock ¶
func (*RedisLock) GetLockKey ¶
func (*RedisLock) GetLockVal ¶
Click to show internal directories.
Click to hide internal directories.