I was wondering if anyone already made a Lua script to make a list 'uniq', by removing all duplicates.
redis.call('del', KEYS[2])
local list = redis.call('lrange', KEYS[1] , 0, -1)
redis.log(redis.LOG_NOTICE, KEYS[1], redis.call('llen', KEYS[1]))
local function table_count(tt, item)
local count
count = 0
for ii,xx in pairs(tt) do
if item == xx then count = count + 1 end
end
return count
end
local function table_unique(tt)
local newtable
newtable = {}
for ii,xx in ipairs(tt) do
if(table_count(newtable, xx) == 0) then
newtable[#newtable+1] = xx
redis.call('lpush', KEYS[2], xx)
end
end
return newtable
end
table_unique(list)
redis.log(redis.LOG_NOTICE, KEYS[2], redis.call('llen', KEYS[2]))
return redis.call('llen', KEYS[2])
But it's extremely slow. Anyone has a better idea?