First, tool preparation
1. Redis for Windows download Https://github.com/MSOpenTech/redis
2. php Extensions download http://pecl.php.net/package-stats.php (Redis and Igbinary)
PHP 7 extension Download http://windows.php.net/downloads/pecl/snaps/redis/20160319/
Note: Download extension is to watch 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 (self-tuning according to your Redis path)
2). Enter Redis-server.exe Click Enter to take a look at the Redis directory file situation, different versions of the startup mode a little difference. The identity execution occurred successfully. do not close the current window after success, to ensure that this window is open during Redis operation, close this window to close Reids, reopen a cmd
3). cmd go to D:\program files\redis (self-adjusting according to your Redis path) and enter Redis-cli.exe to click Return. Now we can do some tests. For example, the identity Redis installation started successfully.
Note: Two cmd windows open at the same time, the Redis window can not be turned off
Third, PHP extension
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
[HTML]View PlainCopy
- #php for Redis
- extension=Php_igbinary.dll
- extension=Php_redis.dll
3. Restart the service, there are redis entries in Phpinfo to indicate success
Four. Demo
[PHP]View PlainCopy
- <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", 12);
- 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 the Redis class
A) connect to Redis server
- Connect: Connecting to server
- Pconnect: Long Connection
- AUTH: Permission Validation
- Select: Choose DB
- Close: Closing the connection
- SetOption: Set client options
- GetOption: Get Client options
- ping:ping Redis Server
- Echo: Output string
Note that if you operate redis frequently, and the connect and close will be very expensive, it is recommended to use Pconnect to establish a long connection.
b) string read and write function
- Append: Append a value after a value
- DECR: decrements the value of a key
- INCR: Increments the value of a key
- Get: Get a value
- Set: Sets a value
- Getset: Sets the value and returns the old value
- MGet: Bulk Fetch values
- MSet: Batch Setting values
- Strlen: Get value length
Note: If you can use bulk operations as much as possible, reduce the frequent connection to Redis database performance
c) hash read and write function
- Hdel: Delete a multiple domain
- Hexists: Determine if a hash field exists
- Hget: Gets the value of the hash field
- Hgetall: Get all domain values
- Hincrby: Self-growing value of a hash int field
- Hkeys: Get hash all fields
- Hlen: Get the number of domains
- Hmget: Bulk Get the value of a domain
- Hmset: Bulk set values for a field
- Hset: Setting the value of a field
- Hvals: Get values for all domains
d) List read and write function
- Linsert: inserting elements
- Llen:list length
- Lpop: Remove and get the first color
- Lpush: Inserting an element
- Lrem: removing elements
- LSet: Setting element values
E) Set
- Sadd: Add one or more members
- Sismember: Whether it contains
- Smembers: Get member
- Smove: Moving Members
- SPop: removing members
- Srandmember: Get randomly into
Extensions for Redis and Phpredis installed under Windows (Windows Redis PHP&PHP7)