script tried accessing undeclared key

hello. i want some help with my lua scritps

local cursor = '0'
local pattern = ARGV[1] .. ':*'

repeat
    local result = redis.call('SCAN', cursor, 'MATCH', pattern)
    cursor = result[1]
    local batchKeys = result[2]

    for _, key in ipairs(batchKeys) do
        redis.call('DEL', key)
    end
until cursor == '0'

return true

I get “script tried accessing undeclared key” when using key inside for clause. should i use allow-undeclared-keys flag in this case?

Hi! Yes, this is the primary use case.
You can add disable-atomicity if you don’t want to block the full keystore for this operation

thanks!

By the way, we also have an experimental feature :upside_down_face: You can enable it with --lua_auto_async. If you run on multiple threads, it will parallelize the loop over batchkeys :scream: