redisLock 中context 代码错误
Author: hanchao131415Created Apr 25, 2025Updated Aug 21, 2025
源码: func (r Lock) Lock(key string, unixTsToExpireNs int64) error { now := time.Now().UnixNano() expiration := time.Duration(unixTsToExpireNs + 1 - now) ctx := r.rclient.Context()
success, err := r.rclient.SetNX(ctx, key, unixTsToExpireNs, expiration).Result()
if err != nil {
return err
}错误信息:
github.com/RichardKnop/machinery/v2/locks/redis
....\pkg\mod\github.com!richard!knop\machinery\[email protected]\locks\redis\redis.go:67:19: r.rclient.Context undefined (type "github.com/redis/go-redis/v9".UniversalClient has no field or method Context)
ctx := r.rclient.Context() 这行代码错误,我使用的是最新版本,没有context 方法
Source: RichardKnop/machinery