diff --git a/const.go b/const.go index 0f0cc16..0df2d43 100644 --- a/const.go +++ b/const.go @@ -1,3 +1,3 @@ package dorm -const Version = "1.0.25" +const Version = "1.0.26" diff --git a/redis_error.go b/redis_error.go index 548aed9..62e1b77 100644 --- a/redis_error.go +++ b/redis_error.go @@ -1,8 +1,8 @@ package dorm +import "errors" + var ( - // RedisNotFound 没有数据 - RedisNotFound = "redis: nil" // RedisKeysNotFound keys没有数据 - RedisKeysNotFound = "ERR wrong number of arguments for 'mget' command" + RedisKeysNotFound = errors.New("ERR wrong number of arguments for 'mget' command") ) diff --git a/redis_lock.go b/redis_lock.go index 352ddff..0d34c8b 100644 --- a/redis_lock.go +++ b/redis_lock.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "github.com/go-redis/redis/v9" "time" ) @@ -27,7 +28,7 @@ func (rl *RedisClientLock) Lock(ctx context.Context, key string, val string, ttl } // 获取 get, err := rl.operation.Get(ctx, key).Result() - if err.Error() == RedisNotFound { + if errors.Is(err, redis.Nil) { // 设置 err = rl.operation.Set(ctx, key, val, ttl).Err() if err != nil { @@ -57,7 +58,7 @@ func (rl *RedisClientLock) Unlock(ctx context.Context, key string) error { func (rl *RedisClientLock) LockForever(ctx context.Context, key string, val string) (resp string, err error) { // 获取 get, err := rl.operation.Get(ctx, key).Result() - if err.Error() == RedisNotFound { + if errors.Is(err, redis.Nil) { // 设置 err = rl.operation.Set(ctx, key, val, 0).Err() if err != nil {