
While doing redis.call() in a lua script, can I assume that these calls are atomic (all or none)?
Thanks,
Shannon
--
--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To post to this group, send email to redi...@googlegroups.com.
To unsubscribe from this group, send email to redis-db+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/redis-db?hl=en.

Running limit is a redis setting, not client's. Even though redis won't explicitly call SCRIPT KILL, it will still kill long running scripts according to running limit setting, right ?
Thanks!
Scripts should never try to access the external system, like the file system or any other system call. A script should only operate on Redis data and passed arguments.
Scripts are also subject to a maximum execution time (five seconds by default). This default timeout is huge since a script should usually run in under a millisecond. The limit is mostly to handle accidental infinite loops created during development.
It is possible to modify the maximum time a script can be executed with millisecond precision, either via redis.conf or using the CONFIG GET / CONFIG SET command. The configuration parameter affecting max execution time is called lua-time-limit.
When a script reaches the timeout it is not automatically terminated by Redis since this violates the contract Redis has with the scripting engine to ensure that scripts are atomic. Interrupting a script means potentially leaving the dataset with half-written data. For this reasons when a script executes for more than the specified time the following happens:
SCRIPT KILL and SHUTDOWN NOSAVE.SCRIPT KILL command. This does not violate the scripting semantic as no data was yet written to the dataset by the script.SHUTDOWN NOSAVE that stops the server without saving the current data set on disk (basically the server is aborted).redis 127.0.0.1:6379> set foo 100
OK
redis 127.0.0.1:6379> eval "redis.call('set', 'foo', 200); redis.call('lpush', 'foo', 300)" 0
(error) ERR Error running script (call to f_18507169045dda984b7ec9ae42a857413800dbd5): ERR Operation against a key holding the wrong kind of value
redis 127.0.0.1:6379> get foo
"200"
redis 127.0.0.1:6379> eval "redis.call('set', 'foo', 300); redis.call('lpush', 'foo', 300); redis.call('set', 'foo2', 5678)" 0
(error) ERR Error running script (call to f_ba41622270712b5cdf299f8c90be4f9f5afd7c9d): ERR Operation against a key holding the wrong kind of value
redis 127.0.0.1:6379> get foo
"300"
redis 127.0.0.1:6379> get foo2
(nil)
And as long as your script doesn't run too long and get killed via "SCRIPT KILL"
Looks like that if a multi-step script fails in the middle, the steps that have already been done will not be rolled back, as shown in this example:
redis 127.0.0.1:6379> set foo 100
OK
redis 127.0.0.1:6379> eval "redis.call('set', 'foo', 200); redis.call('lpush', 'foo', 300)" 0
(error) ERR Error running script (call to f_18507169045dda984b7ec9ae42a857413800dbd5): ERR Operation against a key holding the wrong kind of value
redis 127.0.0.1:6379> get foo
"200"
redis 127.0.0.1:6379> eval "redis.call('set', 'foo', 300); redis.call('lpush', 'foo', 300); redis.call('set', 'foo2', 5678)" 0
(error) ERR Error running script (call to f_ba41622270712b5cdf299f8c90be4f9f5afd7c9d): ERR Operation against a key holding the wrong kind of value
redis 127.0.0.1:6379> get foo
"300"
redis 127.0.0.1:6379> get foo2
(nil)
So it would mean one has to be ultra careful in writing a Lua redis script. Can there be an option to test run the script first and then execute it for real, in the same atomic EVAL command? like
test_and_eval "redis.call('set', 'foo', 300); redis.call('lpush', 'foo', 300); redis.call('set', 'foo2', 5678)" 0
In typical SQL programming, one would rollback on coding error -- not nice but safer.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/redis-db?hl=en.For more options, visit https://groups.google.com/groups/opt_out.