import { defineAuctionRedisScript } from './auction-redis.scripts'; // Compare the lifecycle and remove the payload and its indexes atomically. export const AUCTION_CLEANUP_DURABILITY_SCRIPT = defineAuctionRedisScript( 'auction.cleanupDurability', ` local deleted = 0 for i = 3, #KEYS do local key = KEYS[i] local keyType = redis.call('TYPE', key).ok local matches = ARGV[1] == '' if not matches and keyType == 'hash' then matches = redis.call('HGET', key, 'auctionLifecycleId') == ARGV[1] elseif not matches and keyType == 'string' then -- Retain compatibility with payloads written before the Hash format. local ok, payload = pcall(cjson.decode, redis.call('GET', key)) matches = ok and type(payload) == 'table' and payload.auctionLifecycleId == ARGV[1] end if matches then redis.call('ZREM', KEYS[1], key) redis.call('ZREM', KEYS[2], key) deleted = deleted + redis.call('UNLINK', key) end end return deleted `, );