.cosid-spring-redis.1.19.0.source-code.machine_id_revert_stable.lua Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cosid-spring-redis Show documentation
Show all versions of cosid-spring-redis Show documentation
Universal, flexible, high-performance distributed ID generator.
local stateDelimiter = "|";
local namespace = KEYS[1];
local instanceId = ARGV[1];
local currentStamp = ARGV[2];
local instanceIdxKey = 'cosid' .. ':' .. namespace .. ':itc_idx';
local function convertStingToState(machineState)
local splitIdx = string.find(machineState, stateDelimiter, 1);
local machineId = string.sub(machineState, 1, splitIdx - 1);
local timestamp = string.sub(machineState, splitIdx + 1, -1);
return { tonumber(machineId), tonumber(timestamp) }
end
local function convertStateToString(machineId, timestamp)
return tostring(machineId) .. stateDelimiter .. tostring(timestamp);
end
local function setState(machineId, lastStamp)
local machineState = convertStateToString(machineId, lastStamp);
redis.call('hset', instanceIdxKey, instanceId, machineState);
end
local machineState = redis.call('hget', instanceIdxKey, instanceId)
if machineState then
local states = convertStingToState(machineState)
local machineId = states[1];
setState(machineId,currentStamp);
return 1;
end
return 0;
© 2015 - 2025 Weber Informatics LLC | Privacy Policy