redis翻译_redislua脚本(十)

2015-07-24 07:47:25 · 作者: · 浏览: 5
5 127.0.0.1:6379> eva l 'return bit.tohex(422342)' 0 "000671c6" It supports several other functions: bit.tobit, bit.tohex, bit.bnot, bit.band, bit.bor,bit.bxor, bit.lshift, bit.rshift, bit.arshift, bit.rol, bit.ror, bit.bswap. All available functions are documented in the Lua BitOp documentation
支持的方法有:bit.tobit, bit.tohex, bit.bnot, bit.band, bit.bor,bit.bxor, bit.lshift, bit.rshift, bit.arshift, bit.rol, bit.ror, bit.bswap.所有方法的文档在Lua BitOp documentation上。

redis.sha1hex

Perform the SHA1 of the input string.

执行输入的SHA1字符串。 Example:
127.0.0.1:6379> eva l 'return redis.sha1hex(ARGV[1])' 0 "foo"
"0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"

?

Emitting Redis logs from scripts从脚本记录日志

It is possible to write to the Redis log file from Lua scripts using the redis.logfunction.

?

可以使用lua脚本的redis.log函数记录Redis的日志文件。
redis.log(loglevel,message)

loglevel is one of: loglevel 是下面中的一个

redis.LOG_DEBUG
redis.LOG_VERBOSE
redis.LOG_NOTICE
redis.LOG_WARNING They correspond directly to the normal Redis log levels. Only logs emitted by scripting using a log level that is equal or greater than the currently configured Redis instance log level will be emitted.
与一般Redis日志的级别相同。仅仅是记录来自脚本,等效或者更高于当前Redis的日志配置的记录。 The message argument is simply a string. Example:
参数message是一个简单的字符串。例如:
redis.log(redis.LOG_WARNING,"Something is wrong with this script.")
Will generate the following: 将生产:
[32343] 22 Mar 15:21:39 # Something is wrong with this script.

?

Sandbox and maximum execution time 研究最大执行时间

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.

脚本应该不要去使用外部的系统,比如文件或者其他的系统。一个脚本应该仅仅是操作Redis的数据和传递参数。

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.

脚本也应该受制于一个最大执行时间(缺省是5秒)。因为脚本应该一般运行时间都是毫米级别的,所以这个缺省的时间是很大的。这个限制主要是去处理脚本运行期间可能发生的死循环。

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.

可以通过redis.conf或者使用CONGIG GET/CONFIG SET命令设置脚本运行时间为毫秒级别。 配置最大脚本运行时间的参数名是 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:
如果脚本达到最大运行时间没有自动中断,那是因为Redis的脚本引擎保证了脚本的原子性。中断脚本可能导致数据只写了一半。当一个脚本执行时间超过最大运行时间会是发生下面情况:
Redis logs that a script is running too long.
Redis日志脚本运行很长时间。
It starts accepting commands again from other clients, but will reply with a BUSY error to all the clients sending normal commands. The only allowed commands in this status are SCRIPT KILL and SHUTDOWN NOSAVE.
开始接收来自其他客户端的命令,但是将返回一个BUSY的错误。这时仅仅允许运行的命令是 SCRIPT KILL 和SHUTDOWN NOSAVE
It is possible to terminate a script that executes only read-only commands using the SCRIPT KILL command. This does not violate the scripting semantic as no data was yet written to the dataset by the script.
可能会使用SCRI