Home > Backend Development > PHP Tutorial > Php+Redis implements the lua script function provided by Redis, redislua_PHP tutorial

Php+Redis implements the lua script function provided by Redis, redislua_PHP tutorial

WBOY
Release: 2016-07-13 10:23:28
Original
1485 people have browsed it

Php+Redis implements the lua script function provided by Redis, 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>?>
Copy after login

How to set the plug value for redis effectively using lua Time

There is no ready-made method

If you want to achieve the function you mentioned
Generally speaking, you should increase or decrease the value of the table through insert or remove in the normal way
And then add additional Perform a monitoring on the table and when the specified time is reached, remove the relevant values ​​

How to solve the problem of reply function in php redis

Redis will store data in memory and will be lost when power is turned off. Pay attention to this and make it persistent if necessary. The persistence method is difficult to explain in one sentence, you can refer to online articles.

php’s redis extension is called php-redis. There is a Chinese manual for php-redis on the Internet. Here is an example:
connect('127.0.0.1', 6379); / / 6379 is the default port $result = $redis->set('9639002718',"comment"); // Set the key value echo $result = $redis->get('9639002718'); // Get the key value $all = $redis->getMultiple(array('9639002718', '9639002718')); // Get multiple key values ​​at the same time // There is no method to get all key values. I'm not sure if the following sentence can be used, you can give it a try. $all = $redis->getMultiple(array('*'));
Hope to adopt it, thank you for your support!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/839928.htmlTechArticlePhp+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 ['por...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template