Php + Redis implements the lua script function provided by Redis, redislua

Source: Internet
Author: User
Tags php redis

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!

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.