local prefix = ARGV[1]
redis.call('SELECT', ARGV[2])
local keys = redis.call('KEYS', '*')
local lastKey = ''
for i, key in ipairs(keys) do
if not string.find(key, prefix, 1, true) then
local newKey = prefix .. key
lastKey = newKey
-- 检查 newKey 是否已经存在
if 0 == redis.call('EXISTS', newKey) then
redis.call('RENAME', key, newKey)
end
end
end
return lastKey
redis-cli -h <host> -p <port> -a <password> eval "$(cat rename.lua)" 0 <prefix> <database>