CodisLabs / CodisLabs/codis

A lua script causes master-slave data to be out of sync(redis version 3.2.8)

Open
#1,691 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
13.2k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

`eval "local flag = 0 local targetScore = redis.call('get', KEYS[1]) local currentCount = 0 if (not targetScore) then redis.call('set', KEYS[1], 0) if (ARGV[2] ~= nil and ARGV[2] ~= '') then redis.call('expire', KEYS[1], tonumber(ARGV[2])) end else currentCount = tonumber(targetScore) end local limitCount = tonumber(ARGV[1]) if (currentCount < limitCount or limitCount == 0) then currentCount = tonumber(redis.call('incr', KEYS[1])) flag = 1 end local ret = {} ret[1] = flag ret[2] = currentCount return ret" 1 lua_expire_test 1 -1`
1)When we executed the above lua script on version 3.2.8, we found the master-slave data inconsistent

**master : ttl lua_expire_test result: -1
slave : ttl lua_expire_test result: -2**

2)Then we try again and execute the `monitor `command on the slave
`1575463540.730292 [0 xx.xx.xx.xx:6380] "eval" "local flag = 0 local targetScore = redis.call('get', KEYS[1]) local currentCount = 0 if (not targetScore) then redis.call('set', KEYS[1], 0) if (ARGV[2] ~= nil and ARGV[2] ~= '') then redis.call('expire', KEYS[1], tonumber(ARGV[2])) end else currentCount = tonumber(targetScore) end local limitCount = tonumber(ARGV[1]) if (currentCount < limitCount or limitCount == 0) then currentCount = tonumber(redis.call('incr', KEYS[1])) flag = 1 end local ret = {} ret[1] = flag ret[2] = currentCount ret[3]=tonumber(ARGV[2]) return ret" "1" "lua_expire_test" "1" "-1"
1575463540.730380 [0 lua] "get" "lua_expire_test"
1575463540.730391 [0 lua] "set" "lua_expire_test" "0"
1575463540.730411 [0 lua] "expire" "lua_expire_test" "-1"
1575463540.730419 [0 lua] "incr" "lua_expire_test"`

There seems to be nothing wrong with the sync script.

Could you check whether this is expected behavior or an issue ? Thanks.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.