First download the Redis installation package
[[Email protected] ~] #wget http://download.redis.io/releases/redis-3.0.2.tar.gz
[Email protected] ~]# tar xzf redis-3.0.2].tar.gz
[Email protected] ~]# CD redis-3.0.2
[[email protected] redis-3.0.2] #ls
[[email protected] redis-3.0.2] #make
Compilation succeeded:
To start and run Redis:
[Email protected] redis-3.0.2]# Src/redis-server
If the error:
Open another terminal to run, Redis client
[Email protected] redis-3.0.2]# Src/redis-server
127.0.0.1:6379> Set Name * * *
127.0.0.1:6379> Get Name
127.0.0.1:6379>
Redis Installation succeededDownload
[Email protected] src]# wget https://github.com/nicolasff/phpredis/archive/master.zip
[[email protected] src]# ls
[[email protected] src]# unzip Master.zip[[email protected] src]# CD Phpredis-master
[Email protected] src]#/usr/local/webserver/php/bin/phpize
[Email protected] src]#/configure--with-php-config=/usr/local/webserver/php/bin/php-config
[[email protected] src]# make && make install
[Email protected] src]# Vi/usr/local/webserver/php/etc/php.ini
Underneath the extension.
Extension=redis.so
Restart Apache after saving, if it is a connected nginx, you will need to restart PHP-FPM.
Phpredis Installation Success
Output phpinfo () under the Linux domain name;
<?php
Echo Phpinfo ();
?>
Detailed
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 random Members
- Srem: Delete
f) Sorted set
- zadd: Add one or more
- Zcard: Number of Members
- Zincrby: incrementing member score
- Zrange: Returns a member within an index range
- Zrangebyscore : Returns members within the score range
- Zscore: Get member Score
- zrem: Remove one or more members
Example:
<?php $redis = new Redis ();//Instantiate Redis class file $redis->connect (' 127.0.0.1 ', 6379); Connect to Redis server $redis->set (' name ', ' Zhangsan ');//Set value echo $redis->get (' name ');//Get value
Redis and Phpredis installation in Linux under detailed and simple operation