mirror of
https://gitee.com/johng/gf
synced 2026-07-03 11:51:04 +08:00
@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user