The use of Redis in PHP in-depth analysis _php tutorial

Source: Internet
Author: User
Tags install redis
Redis is a key-value storage system. Similar to memcached, it supports storing more value types, including string (string), list (linked list), set (set), and Zset (ordered collection). These data types support Push/pop, Add/remove, and intersection-set and difference sets, and richer operations, and these operations are atomic. Based on this, Redis supports sorting in a variety of different ways. As with memcached, data is cached in memory to ensure efficiency. The difference is that Redis periodically writes the updated data to disk or writes the modified operation to the appended record file, and Master-slave (Master-Slave) synchronization is implemented on this basis.

Redis is a high-performance Key-value database. The emergence of Redis, to a large extent, compensates for the lack of memcached such keyvalue storage, in some cases can be a good complement to the relational database. It provides the python,ruby,erlang,php client, which is very convenient to 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 unzip it to D or other disk.

The installation is then done through the DOS command line.

Copy this folder to a different location, 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 the path of Redis to the environment variables of the system, so as to save the path again, the latter redis.conf can be omitted, if omitted, the default is enabled. After entering, the following interface is displayed:


At this time another cmd window, the original do not close, otherwise you will not be able to access the server
Switch to Redis directory running Redis-cli.exe-h 127.0.0.1-p 6379 appears:


At this point, the configuration is complete.

After the configuration is complete, you will need to add the Redis extension in PHP before you can use PHP flexibly.

The Redis extension for installing PHP under Windows is very simple, download a. dll extension package into the PHP ext directory, and add a line of configuration to the php.ini.

PHP Code Testing

$redis = new Redis ();
$redis->connect (' 127.0.0.1′,6379);
$redis->set (' Test ', ' Hello world! ');
echo $redis->get (' Test ');

Output Hello world!

http://www.bkjia.com/PHPjc/825284.html www.bkjia.com true http://www.bkjia.com/PHPjc/825284.html techarticle Redis is a key-value storage system. Similar to memcached, it supports storing more value types, including string (string), list (linked list), set (set), and Zset (ordered collection). This ...

  • 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.