2

SPOP is not allowed to be executed in lua. And if you do some non-deterministic commands firstly, then you is not allowed to execute write commands. This seems confusing to me. So why redis has such limitation?

4 Answers 4

4

It's explained fairly well in the Redis docs here.

The scripts are replicated to slaves by sending the script over and running it on the slave, so the script needs to always produce the same results every time it's run or the data on the slave will diverge from the data on the master.

You could try the new 'scripts effects replication' in the same link if you need perform non deterministic operations in a script.

1

you need to run this replicate commands function before any data changing command

redis.replicate_commands()

it's explained here

0

On a single Redis instance I cannot think about any negativ effect.

But say you're running some master-slave setup. the result of those lua scripts which calls e.g. TIME wouldn't be equal on the master.

0

you can act like what proposed at the last of error description

Additional information: ERR Error running script (call to f_082d853d36ea323f47b6b00d36b7db66dac0bebd): @user_script:10: @user_script: 10: Write commands not allowed after non deterministic commands. Call redis.replicate_commands() at the start of your script in order to switch to single commands replication mode.

Call redis.replicate_commands() at the start of your script in order to switch to single commands replication mode. note that because of redis.call('time') call is non deterministic.

local function ticks(key,ticks) 
    redis.replicate_commands()
    local t = ticks
    local time = redis.call('time')
    local last=redis.call('get',key..'_last')
    if last==t then                                     
        local inc=redis.call('incr',key..'cnt')
        t  = t+inc
    else 
        redis.call('set',key..'cnt',0)                                    
    end         
    redis.call('set',key..'_last',t)
    return t
end   
return ticks(@key,@ticks)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.