-- Atomically inserts a batch of messages into the queue.
-- KEYS[1]: namespace:queuename (the sorted set key for the queue)
-- ARGV[1]: realtime flag ("1" or "0") — when "1", returns the new ZCARD so the
-- caller can do a single PUBLISH outside the script.
-- ARGV[2..]: triplets of (id, score, body), one per message. Total length must be
-- 1 + 3*N for N messages.
-- Returns: new ZCARD if realtime, else 0.
local n = / 3
local queue_hash = KEYS .. ":Q"
for i = 0, n - 1
redis.
if ARGV == "1"
return 0