Home > Backend Development > PHP Tutorial > In-depth analysis of the usage of redis in PHP_PHP tutorial

In-depth analysis of the usage of redis in PHP_PHP tutorial

WBOY
Release: 2016-07-13 10:24:57
Original
966 people have browsed it

Redis is a key-value storage system. Similar to Memcached, it supports relatively more stored value types, including string (string), list (linked list), set (set) and zset (ordered set). These data types all support push/pop, add/remove, intersection, union, difference, and richer operations, and these operations are all atomic. On this basis, redis supports various different ways of sorting. Like memcached, data is cached in memory to ensure efficiency. The difference is that redis will periodically write updated data to disk or write modification operations to additional record files, and on this basis, master-slave (master-slave) synchronization is achieved.

Redis is a high-performance key-value database. The emergence of redis has largely compensated for the shortcomings of keyvalue storage such as memcached, and can play a very good supplementary role to relational databases in some situations. It provides Python, Ruby, Erlang, and PHP clients, which are very convenient to use.

If you want to use redis in PHP, you must first install redis. Then configure the extension in PHP.

1. Install redis.

First download the redis installation file and extract it to the D drive or other drive.

Then install via Dos command line.

Copy this folder to other places, such as the D: redis directory.
Open a cmd window and use the cd command to switch directories to D:redis and run redis-server.exe redis.conf
If you want to make it easier, you can add the redis path to the system environment variable, so you don’t have to worry about it again. After entering the path, the following redis.conf can be omitted. If omitted, the default one will be enabled. After input, the following interface will be displayed:


At this time, open another cmd window. Do not close the original one, otherwise you will not be able to access the server.
Switch to the redis directory to run redis -cli.exe -h 127.0.0.1 -p 6379 The following picture appears:


At this time, the configuration has been completed.

After completing the configuration, you need to add the redis extension to PHP, and then you can use it flexibly with PHP.

It is very simple to install the redis extension of php under windows. Download a .dll extension package and put it in the ext directory of php. Just add a line of configuration in 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!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825284.htmlTechArticleredis is a key-value storage system. Similar to Memcached, it supports relatively more stored value types, including string (string), list (linked list), set (set) and zset (ordered set). This...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template