php使用redis执行muti pipeline lua eval脚本及锁示例代码
代码语言:php
所属分类:其他
代码描述:php使用redis执行muti pipeline lua eval脚本及锁示例代码
代码标签: php redis muti pipeline lua eval 脚本 锁
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<?php $redis = new Redis(); #实例化redis类 $redis->connect('127.0.0.1'); #连接服务器 $lua = <<<SCRIPT return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]} SCRIPT; //对应的redis命令如下 eval "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}" 2 key1 key2 first second $s = $redis->eval($lua,array('key1','key2','first','second'),2); var_dump($s); //解锁 $redis->del('lockkey'); $redis->set('lockkey','123'); $lock=['key'=>'lockkey','token'=>'123']; var_dump(unlock($redis,$lock)); //批量获取hash的值 $redis->del('user:1','user:2','errKey'); $redis->hmset('user:1',["age"=>21,"name"=>"jack"]); $redis->hset("user:2","age","22"); $redis->hset("user:2","name","tom"); $pipe = $redis->multi(Redis::PIPELINE); $pipe->hgetAll('user:1'); $pipe->lpop('errKey'); $pipe->set('a',100); $pipe->hgetAll('.........完整代码请登录后点击上方下载按钮下载查看
网友评论0