Home >php教程 >php手册 >Php+Redis 实现Redis提供的lua脚本功能,redislua

Php+Redis 实现Redis提供的lua脚本功能,redislua

WBOY
WBOYOriginal
2016-06-13 09:29:221171browse

Php+Redis 实现Redis提供的lua脚本功能,redislua

<?<span>php
  </span><span>require_once</span> "predis-0.8/autoload.php"<span>;
  </span><span>$config</span>['schema'] = 'tcp'<span>;
  </span><span>$config</span>['host']= "192.168.1.7"<span>;
  </span><span>$config</span>['port'] = 6379<span>;
  </span><span>$redis</span> = <span>new</span> Predis\Client(<span>$config</span><span>);
  </span><span>class</span> wode <span>extends</span><span> Predis\Command\ScriptedCommand {
    </span><span>public</span> <span>function</span><span> getKyesCount(){
      </span><span>return</span> <span>false</span><span>;
    }
    </span><span>public</span> <span>function</span><span> getScript(){
      </span><span>return</span> 
<<<<span>LUA
local result </span>=<span> {}
</span><span>for</span> i,v in ipairs(KEYS) <span>do</span><span>
  result[i] </span>= redis.call("HGETALL",<span>v)
</span><span>end</span>
<span>return</span><span> result
LUA;
    }
  }
  </span><span>$redis</span>->getProfile()->defineCommand('ri','wode'<span>);
  </span><span>$a</span> = <span>$redis</span>->ri(0,'tt1','tt2','tt3'<span>);
  </span><span>print_r</span>(<span>$a</span><span>);
</span>?>

用lua 给redis 中塞值要怎设置有效时间

不存在现成的方法

如果要实现你说的功能
一般来说 还是按照正常的方法通过insert 或remove对表进行值的增减
然后再额外的对表进行一个监听 当达到规定时间的时候,remove掉相关的值
 

php redis 怎解决回复功可以

redis会将数据存储在内存中,断电丢失。这个要注意一下,如有必要就做个持久化。持久化的方法一言难尽,可以参考网上的文章。

php的redis扩展叫php-redis。网上有php-redis的中文手册,下面给你一个示例:
connect('127.0.0.1', 6379); // 6379是默认端口$result = $redis->set('9639002718',"comment"); // 设置键值echo $result = $redis->get('9639002718'); // 获取键值$all = $redis->getMultiple(array('9639002718', '9639002718')); // 同时获得多个键值// 没有提供获得所有键值的方法。下面这句我不确定是否能用,你可以试一试。$all = $redis->getMultiple(array('*'));
望采纳,谢谢支持!

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn