| This article is the second part of the Php-redis Chinese document, followed by an article, continue to introduce the use of some of the official Redis command skills, the need for friends can refer to.
This article is the second part of the Php-redis Chinese document, followed by an article, continue to introduce the use of some of the official Redis command skills, the need for friends can refer to.
Mset (Redis version 1.1 or more can be used) at the same time to assign multiple keys $redis->mset (' key0 ' + ' value0 ', ' key1 ' = ' value1 ')); Multi, exec, discard enter or exit the transaction mode parameter optional Redis::multi or Redis::P ipeline. The default is Redis::multiredis::multi: Use multiple operations as a single transaction to perform Redis::P ipeline: Let (multiple) execute commands simply and faster to the server, but without any atomic guarantees discard: Deletes a transaction return value multi (), returns a Redis object, and enters Multi-mode mode, once the multi-mode mode is entered, all subsequent calls to the method will return the same object, only to the Exec () method being called. Watch, Unwatch (after the code test, can not achieve the said effect) to monitor the value of a key is changed by other programs. If this key is modified between watch and Exec (method), the execution of this multi/exec transaction fails (return false) Unwatch cancels all key parameters that are monitored by this program, the list of a pair of keys $redis->watch ( ' X '); $ret = $redis->multi ()->incr (' x ')->exec (); Subscribe * Method Callback. Note that the method may change in the future publish * post content to a certain channel. Note that this method may change in the future exists determine if the key exists. Existence true does not false incr, the value in Incrbykey is increased by 1, if the second parameter is filled in, the value of the second parameter is added $redis->incr (' Key1 '); $redis->incrby (' Key1 ', 10 ); DECR, Decrby do subtraction, using the method with the incr getmultiple parameter consists of an array of key return parameters if key exists return value, there is no 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 operation Lpush$redis->lpush (key, value); Add a value of element Rpush$redis->rpush (key, value) to the left (header) of the list named key; Add a value of element lpushx/rpushx$redis->lpushx (key, value) to the right (end) of the list with the name key, and add an element with value to the left (head)/Right (tail) of list with the name key , if value already exists, do not add lpop/rpop$redis->lpop (' key '), the first element of the list with the output name key is the left (head)/Right (tail), and the element is deleted blpop/brpop$redis-> Blpop (' Key1 ', ' Key2 ', ten); The block version of the Lpop command. That is, when timeout is 0 o'clock, if a list with the name key I does not exist or the list is empty, the command ends. If Timeout>0 is encountered, wait for timeout seconds, and if the problem is not resolved, perform a pop operation Lsize$redis->lsize (' key ') on the list starting with keyi+1; Returns the number of elements of the list with the name Key LIndex, Lget$redis->lget (' key ', 0), and returns the element Lset$redis->lset (' key ', 0, ' X ') of the index position in the list named key ); Assigns the element of the index position in the list named key to value Lrange, Lgetrange$redis->lrange (' Key1 ', 0,-1); Returns the element between start and end of the list named key (end is-1, returns all) LTrim, Listtrim$redis->ltrim (' key ', start, end), and a list with the name key, Keep the elements between start and end Lrem, Lremove$redis->lrem (' key ', ' A ', 2); Delete count names as key LAn element of value in the IST. Count is 0, removing all elements that value is count>0, removing the element with count values of value from start to finish, count<0 the element that |count| value is removed from the end of a header |