redis

package
v0.0.0-...-fc17aaa Latest Latest
Warning

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

Go to latest
Published: May 23, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

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 NewRedis

func NewRedis(o Config, ctx context.Context) (client *Client, err error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) HIncrMinZero

func (c *Client) HIncrMinZero(ctx context.Context, key, subKey string, num int64) (int64, error)

func (*Client) HIncrUnMinus

func (c *Client) HIncrUnMinus(ctx context.Context, key, subKey string, num int64) (int64, error)

func (*Client) IncrUnMinus

func (c *Client) IncrUnMinus(ctx context.Context, key string, num int64) (int64, error)

func (*Client) Process

func (c *Client) Process(cmd redis.Cmder) error

type Config

type Config struct {
	PoolSize     int
	Addr         []string
	Pwd          string
	DialTimeout  time.Duration
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
}

type RedisLock

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

func NewRedisLock

func NewRedisLock(conn redis.Cmdable, key, val string, timeout time.Duration) *RedisLock

func (*RedisLock) GetLockKey

func (lock *RedisLock) GetLockKey() string

func (*RedisLock) GetLockVal

func (lock *RedisLock) GetLockVal() string

func (*RedisLock) TryLock

func (lock *RedisLock) TryLock(ctx context.Context) error

TryLock return true ===> Get the lock successfully

func (*RedisLock) UnLock

func (lock *RedisLock) UnLock(ctx context.Context) error

Jump to

Keyboard shortcuts

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