Home > Backend Development > PHP Tutorial > php-redis Chinese Document 2

php-redis Chinese Document 2

WBOY
Release: 2016-07-25 09:05:44
Original
1120 people have browsed it
This article is the second part of the php-redis Chinese document. It continues from the previous article and continues to introduce the usage skills of some commands officially provided by redis. Friends in need can refer to it.

This article is the second part of the php-redis Chinese document. It continues from the previous article and continues to introduce the usage skills of some commands officially provided by redis. Friends in need can refer to it.

mset (can only be used with redis version 1.1 or above) Assign values ​​to multiple keys at the same time $redis->mset(array('key0' => 'value0', 'key1' => 'value1')); multi, exec, discard Enter or exit transaction mode The parameter can be Redis::MULTI or Redis::PIPELINE. The default is Redis::MULTI Redis::MULTI: execute multiple operations as one transaction Redis::PIPELINE: allows (multiple) execution commands to be sent to the server simply and faster, but without any atomicity guarantee discard: delete a transaction return value multi(), returns a redis object and enters multi-mode mode. Once it enters multi-mode mode, all methods called in the future will return the same object until the exec() method is called. watch, unwatch (after testing the code, the stated effect cannot be achieved) Monitor whether the value of a key has been changed by other programs. If this key is modified between watch and exec (method), the execution of this MULTI/EXEC transaction will fail (return false) unwatch cancels all keys monitored by this program Parameters, a list of a pair of keys $redis->watch('x'); $ret = $redis->multi() ->incr('x') ->exec(); subscribe* Method callback. Note that this approach may change in the future publish* Post content to a certain channel. Note that this approach may change in the future exists Determine whether the key exists. exists true and is not false incr, incrBy The value in key will be incremented by 1. If the second parameter is filled in, it will be incremented by the value filled in the second parameter. $redis->incr('key1'); $redis->incrBy('key1', 10); decr, decrBy To do subtraction, use the same method as incr getMultiple Passing on parameters array composed of keys Return parameters If the key exists, return value; if it does not exist, return false. $redis->set('key1', 'value1'); $redis->set('key2', 'value2'); $redis->set('key3', 'value3'); $redis->getMultiple (array('key1', 'key2', 'key3')); $redis->lRem('key1', 'A', 2); $redis->lRange('key1', 0, -1); list related operations lPush $redis->lPush(key, value); Add an element with value to the left (head) of the list named key rPush $redis->rPush(key, value); Add an element with value to the right (end) of the list named key lPushx/rPushx $redis->lPushx(key, value); Add an element with value to the left (head)/right (tail) of the list named key. If value already exists, it will not be added. lPop/rPop $redis->lPop('key'); Output the first element from the left (head)/right (tail) of the list named key, and delete the element blPop/brPop $redis->blPop('key1', 'key2', 10); Block version of lpop command. That is, when timeout is 0, if the list named key i does not exist or the list is empty, the command ends. If timeout>0, when encountering the above situation, wait for timeout seconds. If the problem is not solved, perform pop operation on the list starting from keyi+1 lSize $redis->lSize('key'); Returns how many elements the list named key has lIndex, lGet $redis->lGet('key', 0); Returns the element at index position in the list named key lSet $redis->lSet('key', 0, 'X'); Assign value to the element at index position in the list named key lRange, lGetRange $redis->lRange('key1', 0, -1); Returns the elements between start and end in the list named key (end is -1, return all) lTrim, listTrim $redis->lTrim('key', start, end); Intercept the list named key and keep the elements between start and end lRem, lRemove $redis->lRem('key', 'A', 2); Delete count elements whose value is value in the list named key. count is 0, delete all elements with value, count>0 deletes count elements with value from beginning to end, count



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template