This Redis command is not allowed from script

I am using a golang queue library and it has an inbuilt monitoring UI which just spews errors.

https://github.com/hibiken/asynqmon/issues/210

Via this issue I tried the getMemoryLua script and it does indeed show the following error:

(error) ERR Error running script (call to d1d11371f87d10f5e0fff48dae6916d007a66f3e): @user_script:19: This Redis command is not allowed from script


local sample_size = tonumber(20)
if sample_size <= 0 then
    return redis.error_reply("sample size must be a positive number")
end
local memusg = 0
for i=1,2 do
    local ids = redis.call("LRANGE", "asynq:default:active", 0, sample_size - 1)
    local sample_total = 0
    if (table.getn(ids) > 0) then
        for _, id in ipairs(ids) do
            local bytes = redis.call("MEMORY", "USAGE", "asynq:default:t:" .. id)
            sample_total = sample_total + bytes
        end
        local n = redis.call("LLEN", "asynq:default:active")
        local avg = sample_total / table.getn(ids)
        memusg = memusg + (avg * n)
    end
    local m = redis.call("MEMORY", "USAGE", "asynq:default:active")
    if (m) then
        memusg = memusg + m
    end
end
for i=3,6 do
    local ids = redis.call("ZRANGE", "asynq:default:" .. ({"scheduled", "retry", "archived", "completed"})[i - 2], 0, sample_size - 1)
    local sample_total = 0
    if (table.getn(ids) > 0) then
        for _, id in ipairs(ids) do
            local bytes = redis.call("MEMORY", "USAGE", "asynq:default:t:" .. id)
            sample_total = sample_total + bytes
        end
        local n = redis.call("ZCARD", "asynq:default:" .. ({"scheduled", "retry", "archived", "completed"})[i - 2])
        local avg = sample_total / table.getn(ids)
        memusg = memusg + (avg * n)
    end
    local m = redis.call("MEMORY", "USAGE", "asynq:default:" .. ({"scheduled", "retry", "archived", "completed"})[i - 2])
    if (m) then
        memusg = memusg + m
    end
end
local groups = redis.call("SMEMBERS", "asynq:default:groups")
if table.getn(groups) > 0 then
    local agg_task_count = 0
    local agg_task_sample_total = 0
    local agg_task_sample_size = 0
    for i, gname in ipairs(groups) do
        local group_key = "asynq:default:g:" .. gname
        agg_task_count = agg_task_count + redis.call("ZCARD", group_key)
        if i <= tonumber(15) then
            local ids = redis.call("ZRANGE", group_key, 0, sample_size - 1)
            for _, id in ipairs(ids) do
                local bytes = redis.call("MEMORY", "USAGE", "asynq:default:t:" .. id)
                agg_task_sample_total = agg_task_sample_total + bytes
                agg_task_sample_size = agg_task_sample_size + 1
            end
        end
    end
    local avg = agg_task_sample_total / agg_task_sample_size
    memusg = memusg + (avg * agg_task_count)
end
return memusg

If so is there some way for me to enable the key being executed in a script?

When using the same application with normal redis it is working without issues.

version: df-v1.13.0-f39eac5bcaf7c8ffe5c433a0e8e15747391199d9

Hi @munificent-gnu , are you using dragonflydb or redis?

Dragonfly

@munificent-gnu how do you run dragonfly? Can you please follow the guidelines in
https://www.dragonflydb.io/docs/integrations/bullmq#advanced--optimized-configurations

also please provide the EVAL arguments that you used

@munificent-gnu you are getting this error - “This Redis command is not allowed from scrip” because we do not allow running “memory” command under script I will check why this is limitted under script and will update

Alright thanks, do you need the information that roman requested as well?

I believe I dont need it\

Hi @munificent-gnu I just merged a fix so that memory commands will not be blocked under script. https://github.com/dragonflydb/dragonfly/pull/2382 this will be available in our next dfly release. If you want to check out dragonfly with this change before the next release we will have a build tomorrow midnit. You can pull from here -https://github.com/dragonflydb/dragonfly/pkgs/container/dragonfly-weekly

thank you very much! I will check out the weekly build tomorrow :slight_smile:

Hi, I just tried everything out and the “not allowed from script” error is now gone.

But there seems to be a difference in behaviour in dragonfly vs redis when a key is not found.

Using redis

127.0.0.1:6379> memory usage 123
(nil)

Using df

127.0.0.1:6379> memory usage 123
(error) ERR no such key

Would it be possible to bring the behaviour in line with redis?

should I open a gh issue for this?

Yes, you can open one. So far, you can escape the error in the script (pcall should turn it into a value)