In-depth analysis of redis usage in PHP

Source: Internet
Author: User
This article mainly introduces the usage of redis in PHP in detail. if you need it, you can refer to it and hope to help you. 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 and decompress it to drive D or another disk.

Then install the SDK through the doscommand line.

Copy this folder to another place, such as the D: edis directory.
Open a cmd window and use the cd command to switch the directory to D: \ redis and run the redis-server.exe redis. conf
If you want to make it easy, you can add the redis path to the system's environment variables, which saves 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:


In this case, another cmd window is opened. do not close the original window, or you will not be able to access the server.
Switch to the redis directory and run redis-cli.exe-h 127.0.0.1-p 6379 appears:


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.

Php code test

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

Output hello world!

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.