开发手册 欢迎您!
软件开发者资料库

Redis - 脚本

Redis脚本 - 从简单和简单的步骤学习Redis No / SQL,从基本到高级概念,包括概述,环境,配置,数据类型,键,字符串,哈希,列表,集,命令集,HyperLogLog,Pub /等命令Sub,Transactions,Scripting,Connection,Server,Backup,Security,Benchmarks,Client Connection,Pipelining and Partitioning。

Redis脚本用于使用Lua解释器评估脚本.它从版本2.6.0开始内置于Redis中.用于编写脚本的命令是 EVAL 命令.

语法

以下是 EVAL

redis 127.0.0.1:6379> EVAL script numkeys key [key ...] arg [arg ...]

示例

以下示例说明Redis脚本如何工作.

redis 127.0.0.1:6379> EVAL "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}" 2 key1 key2 first second  1) "key1" 2) "key2" 3) "first" 4) "second"

Redis脚本命令

下表列出了与Redis Scripting相关的一些基本命令.

Sr.NoCommand&说明
1EVAL脚本numkeys键[key ...] arg [arg ...]

执行Lua脚本.

2EVALSHA sha1 numkeys key [key ...] arg [arg ...]

执行Lua脚本.

3SCRIPT EXISTS脚本[脚本...]

检查脚本缓存中是否存在脚本.

4SCRIPT FLUSH

从脚本缓存中删除所有脚本.

5SCRIPT K ILL

杀死当前正在执行的脚本.

6SCRIPT LOAD脚本

加载将Lua脚本指定到脚本缓存中.