Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
yedf2 committed May 5, 2022
1 parent 6f9b936 commit 6518364
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (c *Client) DelayDelete(key string) error {
}
debugf("deleting: key=%s", key)
luaFn := func(con redisConn) error {
_, err := callLua(con, c.rdb.Context(), ` -- delete
_, err := callLua(c.rdb.Context(), con, ` -- delete
local v = redis.call('HGET', KEYS[1], 'value')
if v == false then
return
Expand All @@ -98,7 +98,9 @@ func (c *Client) DelayDelete(key string) error {
}
if c.Options.WaitReplicas > 0 {
rconn := c.rdb.Conn(c.rdb.Context())
defer rconn.Close()
defer func() {
_ = rconn.Close()
}()
err := luaFn(rconn)
cmd := redis.NewCmd(c.rdb.Context(), "WAIT", c.Options.WaitReplicas, c.Options.WaitReplicasTimeout)
if err == nil && c.Options.WaitReplicas > 0 {
Expand Down Expand Up @@ -132,7 +134,7 @@ func (c *Client) Fetch(key string, expire time.Duration, fn func() (string, erro
}

func (c *Client) luaGet(key string, owner string) ([]interface{}, error) {
res, err := callLua(c.rdb, c.rdb.Context(), ` -- luaGet
res, err := callLua(c.rdb.Context(), c.rdb, ` -- luaGet
local v = redis.call('HGET', KEYS[1], 'value')
local lu = redis.call('HGET', KEYS[1], 'lockUtil')
if lu ~= false and tonumber(lu) < tonumber(ARGV[1]) or lu == false and v == false then
Expand All @@ -150,7 +152,7 @@ func (c *Client) luaGet(key string, owner string) ([]interface{}, error) {
}

func (c *Client) luaSet(key string, value string, expire int, owner string) error {
_, err := callLua(c.rdb, c.rdb.Context(), `-- luaSet
_, err := callLua(c.rdb.Context(), c.rdb, `-- luaSet
local o = redis.call('HGET', KEYS[1], 'lockOwner')
if o ~= ARGV[2] then
return
Expand Down Expand Up @@ -238,7 +240,7 @@ func (c *Client) RawSet(key string, value string, expire time.Duration) error {
// LockForUpdate locks the key, used in very strict strong consistency mode
func (c *Client) LockForUpdate(key string, owner string) error {
lockUtil := math.Pow10(10)
res, err := callLua(c.rdb, c.rdb.Context(), ` -- luaLock
res, err := callLua(c.rdb.Context(), c.rdb, ` -- luaLock
local lu = redis.call('HGET', KEYS[1], 'lockUtil')
local lo = redis.call('HGET', KEYS[1], 'lockOwner')
if lu == false or tonumber(lu) < tonumber(ARGV[2]) or lo == ARGV[1] then
Expand All @@ -256,7 +258,7 @@ func (c *Client) LockForUpdate(key string, owner string) error {

// UnlockForUpdate unlocks the key, used in very strict strong consistency mode
func (c *Client) UnlockForUpdate(key string, owner string) error {
_, err := callLua(c.rdb, c.rdb.Context(), ` -- luaUnlock
_, err := callLua(c.rdb.Context(), c.rdb, ` -- luaUnlock
local lo = redis.call('HGET', KEYS[1], 'lockOwner')
if lo == ARGV[1] then
redis.call('DEL', KEYS[1])
Expand Down
2 changes: 1 addition & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type redisConn interface {
Eval(ctx context.Context, script string, keys []string, args ...interface{}) *redis.Cmd
}

func callLua(rdb redisConn, ctx context.Context, script string, keys []string, args []interface{}) (interface{}, error) {
func callLua(ctx context.Context, rdb redisConn, script string, keys []string, args []interface{}) (interface{}, error) {
debugf("callLua: script=%s, keys=%v, args=%v", script, keys, args)
v, err := rdb.Eval(ctx, script, keys, args).Result()
if err == redis.Nil {
Expand Down

0 comments on commit 6518364

Please sign in to comment.