Redis usage in PHP deep parsing _php Tips

Source: Internet
Author: User
Tags memcached redis install redis

Redis is a key-value storage system. Like memcached, it supports a relatively larger number of stored value types, including string (string), list (linked list), set (set), and Zset (ordered set). These data types support Push/pop, Add/remove and intersection-set and differential sets and richer operations, and these operations are atomic. On this basis, Redis supports a variety of different ways of ordering. As with memcached, data is cached in memory to ensure efficiency. The difference is that Redis periodically writes the updated data to the disk or writes the modification operation to the appended record file, and on this basis, it realizes the Master-slave (master-slave) synchronization.

Redis is a high-performance key-value database. The emergence of Redis, to a large extent, compensates for the shortage of such keyvalue storage in memcached, and in some cases can complement the relational database well. It provides a python,ruby,erlang,php client and is easy to use.

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

1. Install Redis.

First download a good Redis installation file, extract to D disk or other disk.

It is then installed through the DOS command line.

Copy this folder to other places, such as the D:\redis directory.
Open a CMD window using the CD command to switch directories to D:\redis run Redis-server.exe redis.conf
If you want to be convenient, you can add Redis path to the system's environment variables, so as to save the path again, the back of the redis.conf can be omitted, if omitted, will enable the default. After entering, the following interface is displayed:


At this time a separate CMD window, the original do not close, otherwise you will not be able to access the service side
Switch to the Redis directory to run Redis-cli.exe-h 127.0.0.1-p 6379 appears in the following figure:


At this point, the configuration has been completed.

After the configuration is complete, add redis extensions to PHP before you can use PHP flexibly.

The Redis extension of PHP installed under Windows is very simple, download a. dll extension pack and put it in the Ext directory of PHP, add a row of configuration to the php.ini inside.

PHP Code Test

$redis = new Redis ();
$redis->connect (' 127.0.0.1′,6379);
$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.