Redis series-php How to use redis_php tutorials with Redis extensions

Source: Internet
Author: User
Tags pconnect set set zts redis server
1. Install PHP extension a) Install PHP extension Phpredis: [plain] [root@xsf002 tool]# git clone https://github.com/nicolasff/phpredis.git Phpredis [ root@xsf002 tool]# CD phpredis/[root@xsf002 phpredis]#/usr/local/php/bin/phpize # Suppose PHP directory: /usr/local/php [root@xsf002 phpredis]#./configure--with-php-config=/usr/local/php/bin/php-config [root@xsf002 phpredis]# make [ root@xsf002 phpredis]# make install [root@xsf002 tool]# git clone https://github.com/nicolasff/phpredis.git phpredis[ root@xsf002 tool]# cd phpredis/[root@xsf002 phpredis]#/usr/local/php/bin/phpize #假设 php Directory:/usr/local/php[root@xsf002 phpredis]#./configure--with-php-config=/usr/local/php/bin/php-config[root@xsf002 phpredis]# make[root@xsf002 phpredis]# make install if it goes well, you will get a prompt similar to the following: [Plain] Installing shared extensions:/usr/local/php/lib/php/extensions/ No-debug-non-zts-20060613/installing Shared extensions:/usr/local/php/lib/php/extensions/ no-debug-non-zts-20060613/php the extension file directory, there will be a redis.so file. b) Load redis.so in the php.ini file, add the configuration: [Plain] [Redis] extension=redis.so [redis]extension=redis.so Restart the Web server, Echo phpinfo (), You will see roughly the following: 2. Access to Redis server by extension How does PHP Access data using Redis server? It is only through the Phpredis expansion module, through the following steps: 1, Instantiate Redis class "New Redis ()" 2, call the Redis class method, connect Redis Server "Connect,pconnect" 3, set connection option "SetOption" 4, save/Fetch data 5, close connection "Close" If you use the default option, step 3 is not required. See the following code example: [PHP] Connect (' 127.0.0.1 '); #连接服务器 $redis->set (' key ', ' hello '); #调用方法, set the string type value $redis->append (' key ', ' world '); #修改string类型值 echo $redis->get (' key '); #获取redis the value of key, and the output shows echo $redis->type (' key '); #获取key data type echo $redis->echo (' would close ... '); # output String $redis->close (); #关闭连接 Connect (' 127.0.0.1 '); #连接服务器 $redis->set (' key ', ' hello '); #调用方法, set the string type value $redis->append (' Key ', ' world '); #修改string类型值echo $redis->get (' key '); #获取redis the value of key, and the output shows echo $redis->type (' key '); #获取key data type echo $redis->echo (' would close ... '); # output string $redis->close (); #关闭连接 through the above code, we basically complete a simple Redis access operation. Here are some of the properties and methods of the Redis Class A) connecting Redis Server:connect: Connection serverpconnect: Long connection Auth: Authorization Verification Select: Select dbclose: Close connection setOption: Set CLI ENT options getoption: Get client options ping:ping Redis server echo: Output string Note that if you operate redis frequently, connect and close will be very expensive, and this time, it is recommended to use the Pconnect 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 the value and returns the old value mget: bulk Get value mset: Bulk Set Set value strlen: Get value Length Note: If you can use bulk operations as much as possible, reduce the frequent connection of Redis database performance C) hash read-write function Hdel: Delete a multiple domain hexists: Determine if a hash domain exists hget : Gets the value of the hash field Hgetall: Gets 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 the domain hmset: bulk Set the value of the field Hset : Set the value of the 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) setSadd: 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: Increment member Scorezrange: Returns the member within the index range Zrangebyscore : Returns a member of the score range Zscore: Get member Scorezrem: remove one or more members

http://www.bkjia.com/PHPjc/477640.html www.bkjia.com true http://www.bkjia.com/PHPjc/477640.html techarticle 1. Install PHP extension a) Install PHP extension Phpredis: [plain] [root@xsf002 tool]# git clone https://github.com/nicolasff/phpredis.git Phpredis [root@xsf002 tool]# cd phpredis/[root@x ...

  • 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.