initial commit: fork

This commit is contained in:
2023-10-27 10:31:20 +02:00
commit a52dbbc103
195 changed files with 17484 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
local KEY = KEYS[1]
local FROM = tonumber(ARGV[1])
local TO = tonumber(ARGV[2])
if FROM == nil then return redis.redis_error('origin must be a number') end
if TO == nil then return redis.redis_error('destination must be a number') end
local list = redis.call('lrange', KEY, 0, -1)
if FROM == TO then return 'OK' end
if FROM < 0 then FROM = #list + FROM end
if TO < 0 then TO = #list + TO end
-- provided indexes are 0-based
local val = table.remove(list, FROM + 1)
table.insert(list, TO + 1, val)
redis.call('del', KEY)
redis.call('rpush', KEY, unpack(list))
return 'OK'

View File

@@ -0,0 +1,20 @@
local KEY = KEYS[1]
local INDEX = tonumber(ARGV[1])
if INDEX == nil then return redis.redis_error('origin must be a number') end
local list = redis.call('lrange', KEY, 0, -1)
if INDEX < 0 then INDEX = #list + INDEX end
-- provided indexes are 0-based
table.remove(list, INDEX + 1)
redis.call('del', KEY)
-- If there is at least one element, call rpush
if (next(list) ~= nil) then
redis.call('rpush', KEY, unpack(list))
end
return 'OK'

View File

@@ -0,0 +1,19 @@
math.randomseed(tonumber(ARGV[1]))
local function shuffle(t)
for i = #t, 1, -1 do
local rand = math.random(i)
t[i], t[rand] = t[rand], t[i]
end
return t
end
local KEY = KEYS[1]
local list = redis.call('lrange', KEY, 0, -1)
if #list > 0 then
shuffle(list)
redis.call('del', KEY)
redis.call('lpush', KEY, unpack(list))
end
return 'OK'

View File

@@ -0,0 +1,12 @@
local SOURCE = KEYS[1]
local DESTINATION = KEYS[2]
local value = redis.call('rpop', SOURCE)
if value then
redis.call('set', DESTINATION, value)
return value
end
redis.call('del', DESTINATION)
return nil