This commit is contained in:
John Guo
2023-02-08 19:07:05 +08:00
committed by GitHub
parent a7467945ca
commit d66af122c7
2 changed files with 6 additions and 6 deletions

View File

@ -246,7 +246,7 @@ func Test_AdapterRedis_SetIfNotExistFunc(t *testing.T) {
return 11, nil
}, 0)
t.AssertNil(err)
t.Assert(exist, false)
t.Assert(exist, true)
})
}
@ -257,7 +257,7 @@ func Test_AdapterRedis_SetIfNotExistFuncLock(t *testing.T) {
return 11, nil
}, 0)
t.AssertNil(err)
t.Assert(exist, false)
t.Assert(exist, true)
})
}

View File

@ -121,17 +121,17 @@ func (c *AdapterRedis) SetIfNotExist(ctx context.Context, key interface{}, value
}
ok, err = c.redis.SetNX(ctx, redisKey, value)
if err != nil {
return false, err
return ok, err
}
if ok && duration > 0 {
// Set the expiration.
_, err = c.redis.Expire(ctx, redisKey, int64(duration.Seconds()))
if err != nil {
return false, err
return ok, err
}
return true, err
return ok, err
}
return false, err
return ok, err
}
// SetIfNotExistFunc sets `key` with result of function `f` and returns true