fix(lua): 改进 dictReplace key 存在性检查逻辑
修复 shared_dict.replace() 方法对过期 key 的判断: - 区分 key 不存在和 key 存在但已过期的情况 - Get() 返回 val="" 且 expired=false 表示 key 不存在 - 先检查不存在情况,再检查过期情况 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
5a5f733cb4
commit
d856e3c570
@ -278,9 +278,20 @@ func dictReplace(L *glua.LState) int {
|
|||||||
ttl = time.Duration(L.CheckNumber(4)) * time.Second
|
ttl = time.Duration(L.CheckNumber(4)) * time.Second
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否存在
|
// 检查是否存在(Get 返回: value, expired, error)
|
||||||
_, expired, _ := dict.Get(key)
|
// expired=true 表示存在但已过期,expired=false 表示不存在或存在且未过期
|
||||||
|
// 需要区分不存在和存在的情况
|
||||||
|
val, expired, _ := dict.Get(key)
|
||||||
|
// 如果 val 为空且 expired 为 false,表示 key 不存在
|
||||||
|
// 如果 expired 为 true,表示 key 存在但已过期(也算不存在)
|
||||||
|
if val == "" && !expired {
|
||||||
|
// key 不存在
|
||||||
|
L.Push(glua.LFalse)
|
||||||
|
L.Push(glua.LString("not found"))
|
||||||
|
return 2
|
||||||
|
}
|
||||||
if expired {
|
if expired {
|
||||||
|
// key 存在但已过期,也算不存在
|
||||||
L.Push(glua.LFalse)
|
L.Push(glua.LFalse)
|
||||||
L.Push(glua.LString("not found"))
|
L.Push(glua.LString("not found"))
|
||||||
return 2
|
return 2
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user