How to install Redis extensions for the PHP under win

Source: Internet
Author: User
Tags install redis
The advantage of Redis is that it can improve the speed of website access, but PHP itself is not a redis extension, and we need to use Redis to install it manually, this article we will talk about how to install the Redis extension of PHP

1. Download the Redis extension for PHP

Open URL http://pecl.php.net/(PHP extensions), search Redis, go to address: Http://pecl.php.net/package/redis, Click the DLL hyperlink next to the Windows System icon in the row for version 2.2.7, such as:


Go to Address: http://pecl.php.net/package/redis/2.2.7/windows, click Download and your PHP version corresponding to the Php_redis extension. Such as:


(Note: My xampp is 32-bit, PHP version is 5.5 and thread-safe, so download is Php_redis-2.2.7-5.5-ts-vc11-x86.zip)

2. Installing the Php_redis Extension

Unzip the Php_redis-2.2.7-5.5-ts-vc11-x86.zip, locate the Php_redis.dll file, copy it, copy it to the PHP installation directory's extension library directory (for example: E:\xampp\php\ext), To modify the PHP configuration file php.ini, add the following line of code:

Extension=php_redis.dll

Save the exit and restart the Apache server.

3. Verify that the Php_redis extension is installed successfully

Write a PHP file, run the Phpinfo () method, on the output page, find Redis, if you see the following information, the installation is successful; otherwise, the installation fails, please check the problem and reinstall.

4. How PHP operates the Redis database

Once the Php_redis extension is installed, you can operate the Redis database in PHP.

Open Http://pecl.php.net/package/redis, click on the https://github.com/nicolasff/phpredis/inside, such as:


You can enter Phpredis's github page with detailed instructions for using Phpredis.

Example:

$redis = new Redis (); Create a Redis Client object $redis->connect (' 127.0.0.1 ') | | Die (' Connect to Redis server failed! '); Connect Redis server $redis->auth (' foobared '); Password Authentication $redis->select (0); Select Database $redis->setoption No. No. 0 (Redis::opt_prefix, ' my-prefix: '); Set the prefix of the key name (equivalent to the table prefix of MySQL)//Here is a hash data type for example $redis->del (' Test '); First delete the hash table test (that is, the hash type key test) $redis->hsetnx (' Test ', ' key1 ', ' hello '); Insert a record (key-value pair) $redis->hsetnx (' Test ', ' Key2 ', ' world ') only if there is no field key1 in the hash table, $redis->hmset (' Test ', Array (' User_ Id ' =>1, ' name ' = ' Jack '); Insert multiple records at once (existing on update) $redis->expire (' Test ', 600); The set test is valid for 600 seconds $res = $redis->hgetall (' hash '); Gets all the records in the hash table test, returning the data format to the array $redis->close (); Close connection

Related articles recommended:

How PHP installs Redis extension code sharing in Windows

This article is mainly to share with you how PHP installs the Redis Extension Code share in window, hoping to help everyone.

PHP using Redis instance to explain

The request processing of the instantaneous server is replaced by asynchronous processing, which alleviates the pressure of the server and achieves the order of data. 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.