| 1 |
-- Lua script to invalidate ANNs by rank |
| 2 |
-- Uses the following keys |
| 3 |
-- key1 - prefix for keys |
| 4 |
-- key2 - number of elements to leave |
| 5 |
|
| 6 |
local card = redis.call('ZCARD', KEYS[1]) |
| 7 |
local lim = tonumber(KEYS[2]) |
| 8 |
if card > lim then |
| 9 |
local to_delete = redis.call('ZRANGE', KEYS[1], 0, card - lim - 1) |
| 10 |
if to_delete then |
| 11 |
for _, k in ipairs(to_delete) do |
| 12 |
local tb = cjson.decode(k) |
| 13 |
if type(tb) == 'table' and type(tb.redis_key) == 'string' then |
| 14 |
redis.call('DEL', tb.redis_key) |
| 15 |
-- Also train vectors |
| 16 |
redis.call('DEL', tb.redis_key .. '_spam_set') |
| 17 |
redis.call('DEL', tb.redis_key .. '_ham_set') |
| 18 |
end |
| 19 |
end |
| 20 |
end |
| 21 |
redis.call('ZREMRANGEBYRANK', KEYS[1], 0, card - lim - 1) |
| 22 |
return to_delete |
| 23 |
else |
| 24 |
return {} |
| 25 |
end |