Two small scripts for php to operate redis

Source: Internet
Author: User
Redis is not as convenient as mysql. You can only write scripts on your own. The following is the first script of the two small scripts written at work. Find the keys with lottery | and delete them all. | print them out? Php $ redisnewRedis (); # instantiate the redis class $ redis-connect (127.0.0.1); # connect to the server $ m $ redis-keys (

Redis is not as convenient as mysql. You can only write scripts on your own. The following is the first script of the two small scripts written at work. Find the keys with lottery | and delete them all. | print them out? Php $ redis = new Redis (); # instantiate the redis class $ redis-connect ('2017. 0.0.1 '); # connect to the server $ m = $ redis-keys ('

Redis is not as convenient as mysql. You can only write scripts on your own. Below are two small scripts written at work

In the first script, find the keys with lottery | and delete them all. | print them out.

 Connect ('2017. 0.0.1 '); # connect to the server $ m = $ redis-> keys ('lottery | *'); print_r ($ m ); foreach ($ m as $ key =>$ value) {// $ redis-> del ($ value) ;}$ redis-> close (); # close the connection?>

The Second Script sets several key values and prints them out.

 Connect ('2017. 0.0.1 '); # connect to the server // provide a set of user IDs, activity IDs, and qualification IDs for ($ I = 1; $ I <10; $ I ++) {$ redis-> set ('lottery | 7 | cust_id :'. $ I. '| grant', 27) ;}for ($ I = 1; $ I <10; $ I ++) {$ tmp = $ redis-> get ('lottery | 7 | cust_id :'. $ I. '| grant'); echo $ tmp; echo PHP_EOL;} $ redis-> close (); # close the connection?>

  

 

Related Article

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.