David
David

Reputation: 23

Error in Lua script since last Redis update

Since Redis 6.2.7 (and Redis 7) an existing Lua script stopped working with the error message:

"ERR user_script:6: Attempt to modify a readonly table script: 2f405679dab26da46ec86d29bded48f66a99ff64, on @user_script:6."

The script is working fine with Redis 6.2.6. I did not find any breaking changes in the last Redis release notes.

Any clue ? Thanks !!

Here's the script:

-- returns valid task ID if successfull, nil if no tasks

local tenantId = unpack(ARGV)
local activeTenantsSet, activeTenantsList, tenantQueue = unpack(KEYS)

-- next task lua based function - return nil or taskId
function next ()
    local task = redis.call('ZPOPMAX', tenantQueue)
    if table.getn(task) == 0 then
        redis.call('SREM', activeTenantsSet, tenantId)
        redis.call('LREM', activeTenantsList, 0, tenantId)
        return nil
    end
    redis.call('SADD', activeTenantsSet, tenantId)
    redis.call('RPUSH', activeTenantsList, tenantId)
    return task[1]
end

-------------
return next()

Upvotes: 2

Views: 3354

Answers (2)

rescdsk
rescdsk

Reputation: 8905

There's a fix for this in a new version of Sentry (the patch also applies cleanly to the lua scripts going back to some older versions): https://github.com/getsentry/sentry/pull/34416/commits/7c57fe7b17f613fecc47a56c22fff3a20a958496

Upvotes: 1

guest
guest

Reputation: 46

try adding 'local' in front of 'function next'

local function next ()
...

Upvotes: 3

Related Questions