- update redis
continuous-integration/drone/push Build is failing Details
continuous-integration/drone/tag Build is failing Details

master v1.0.26
李光春 2 years ago
parent e8c2b726bf
commit 38bdd453c7

@ -1,3 +1,3 @@
package dorm
const Version = "1.0.25"
const Version = "1.0.26"

@ -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")
)

@ -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 {

Loading…
Cancel
Save