Php + Redis implements the lua script function provided by Redis, redislua
<?php require_once "predis-0.8/autoload.php"; $config['schema'] = 'tcp'; $config['host']= "192.168.1.7"; $config['port'] = 6379; $redis = new Predis\Client($config); class wode extends Predis\Command\ScriptedCommand { public function getKyesCount(){ return false; } public function getScript(){ return <<<LUAlocal result = {}for i,v in ipairs(KEYS) do result[i] = redis.call("HGETALL",v)endreturn resultLUA; } } $redis->getProfile()->defineCommand('ri','wode'); $a = $redis->ri(0,'tt1','tt2','tt3'); print_r($a);?>
How can I set a valid time for the redis value with lua?
No existing method exists
If you want to implement the function
In general, you can use insert or remove to increase or decrease the value of a table in the normal way.
Then, an additional listener is added to the table. When the specified time is reached, the related values are removed.
How can php redis respond?
Redis stores data in the memory and loses power. Pay attention to this. Make a persistence if necessary. The persistence method is hard to understand. For more information, see the article on the Internet.
Php's redis extension is called php-redis. The php-redis Chinese manual is available on the Internet. The following is an example:
<? Php $ redis = new redis (); $ result = $ redis-> connect ('2017. 0.0.1 ', 6379); // 6379 is the default port $ result = $ redis-> set ('123', "comment "); // set the key value echo $ result = $ redis-> get ('20140901'); // get the key value $ all = $ redis-> getMultiple (array ('20140901 ', '9639002718'); // obtain multiple key values at the same time // The method for obtaining all key values is not provided. I'm not sure whether it can be used. You can give it a try. $ All = $ redis-> getMultiple (array ('*'));
Thank you for your support!