Installation of Redis and Phpredis extensions under Windows (Windows Redis PHP&PHP7)

Source: Internet
Author: User
Tags pconnect redis windows download redis server

First, tool preparation

1. Redis for Windows download Https://github.com/MSOpenTech/redis

2. PHP Extended Download http://pecl.php.net/package-stats.php (Redis and Igbinary)

PHP 7 Extended Download http://windows.php.net/downloads/pecl/snaps/redis/20160319/

Note: Download extension is to look at your own PHP version and x86orx64 and compiler compiled version


Second, Redis installation

1.redis Installation

Unzip the downloaded Redis file to the installation directory

2.redis Boot

1). Windows+r then cmd into the D:\program Files\redis (according to their own Redis path adjustment)

2). Input Redis-server.exe Click Enter, take a look at the file under the Redis directory, different versions of the startup way a little different. The following figure identifies a successful execution. when successful, do not close the current window, Operation Redis to ensure that this window open, close this window to close the Reids, reopen a cmd


3. cmd into the D:\program Files\redis (according to their own Redis path adjustment) and then input Redis-cli.exe click Enter. Now we can do some testing the following figure to identify Redis installation started successfully.

Note: Two cmd windows open at the same time, before the Redis window can not be turned off

Third, PHP expansion

1. Copy the downloaded php_redis.dll and php_igbinary.dll extension files to the Php\ext

2. Open php.ini; Add the following code

#php for Redis
extension=php_igbinary.dll
Extension=php_redis.dll

3. Restart Service, Redis in Phpinfo to indicate success


Four. Demo

<span style= "FONT-SIZE:18PX;" > $redis = new Redis ();  
$redis->connect ("127.0.0.1", "6379");  PHP Client set IP and port  
//Store a value  
$redis->set ("type");  
echo $redis->get ("type");  
  
Store multiple values  
$array = Array (' First_key ' => ' first_val ', '  
    second_key ' => ' second_val ',  
    ' Third_key ' => ') Third_val ');  
$array _get = Array (' First_key ', ' second_key ', ' Third_key ');  
$redis->mset ($array);  
Var_dump ($redis->mget ($array _get)); </span>


attached: Some properties and methods of Redis class


A Connect Redis server
Connect: Connect server pconnect: Long connection Auth: Permissions validation select: Select DB Close: Turn off connection setOption: Set client Options Getop tion: Get client option ping:ping Redis server echo: Output string

Note that if you frequently operate Redis, Non-stop Connect and close will be very performance, this time, it is recommended to use Pconnect to establish a long connection

b) string read-write function append: Append value after value DECR: decrements the value of a key incr: increments the value of a key
Get: Gets a value set: Sets a value Getset: sets a value and returns the old value mget: bulk Get value mset: Batch Set value strlen: Get value length

Note: If you can use bulk operation as much as possible, reduce frequent connection Redis database performance

c) Hash read-write function Hdel: Delete a multiple domain hexists: Determine if a hash field exists Hget: Get the value of the hash field Hgetall: Get all field values Hincrby: self-growing value of a hash int field Hkeys: Get hash All domains Hlen: Get the number of domains Hmget: bulk Get the value of a field Hmset: The value of a batch set field Hset: Set the value of a field hvals: Get the value of all fields

d) List read-write function Linsert: Insert element llen:list length Lpop: Remove and get first color Lpush: Insert an element lrem: remove element LSet: Set element value

e) Set Sadd: Add one or more members Sismember: include Smembers: Get member Smove: Move member Spop: Remove member Srandmember: Get random member Srem: delete

f) Sorted set Zadd: Add one or more Zcard: number of members Zincrby: incrementing member score Zrange: Returning members in the index range Zrangebyscore: Returning members within score range Zscore: Get member score Zrem: Remove one or more members

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.