Use of redis in PHP

Source: Internet
Author: User
Tags install redis

Redis is a key-value storage system. Similar to memcached, memcached supports more storage value types, including string, list, set, and zset ). These data types support push/pop, Add/Remove, Intersection Set and difference set, and more abundant operations, and these operations are atomic. On this basis, redis supports sorting in different ways. Like memcached, data is cached in the memory to ensure efficiency. The difference is that redis periodically writes the updated data to the disk or writes the modification operation to the append record file, and on this basis implements master-slave (master-slave) synchronization.
Redis is a high-performance Key-value database. The emergence of redis largely compensates for the shortage of keyValue storage such as memcached, and can play a very good complementary role in relational databases. It provides python, Ruby, Erlang, and PHP clients for ease of use.

To use redis in PHP, first install redis. Then configure the extension in PHP.

1. Install redis.

First download the redis Installation File (download) and decompress it to disk D or another disk.

Then install the SDK through the doscommand line.

Copy this folder to other places, such as the D: \ redis directory. Open a cmd window and use the CD command to switch the directory to D: \ redis and run the redis-server.exe redis. if you want to facilitate the conf operation, you can add the redis path to the system's environment variables, saving you the trouble of losing the path. conf can be omitted. If it is omitted, the default value is enabled. The following page is displayed:

At this time, another cmd window, the original do not close, or you will not be able to access the server to switch to the redis directory to run the redis-cli.exe-H 127.0.0.1-P 6379:

At this time, the configuration has been completed.

After the configuration is complete, you must add the redis extension in PHP before using PHP flexibly.

Installing the redis extension of PHP in Windows is very simple. Download A. dll extension package and put it in the ext directory of PHP. Add a line of configuration in PHP. ini.

 

PHPCodeTest

$ Redis = new redis ();
$ Redis-> connect ('2017. 0.0.1 ', 127 );
$ Redis-> set ('test', 'Hello world! ');
Echo $ redis-> get ('test ');

Output Hello world!

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.