redis 字符串(string)函數

字符串(string)函數redis

get 命令/方法/函數
Description

Get the value related to the specified key 取得與指定的鍵值相關聯的值 Parameters key Return Value String or Bool: If key didn't exist, FALSE is returned. Otherwise, the value related to this key is returned. 返回相關值或者BOOL值,若是KEY不存在,返回FALSE。若是有相關的KEY和值返回值。 Examples $redis->get('key');
set 命令/方法/函數
Description

Set the string value in argument as value of the key. 設置值到KEY Parameters Key Value Timeout (optional). Calling SETEX is preferred if you want a timeout. Return value Bool TRUE if the command is successful. Examples $redis->set('key', 'value');
setex 命令/方法/函數
Description

Set the string value in argument as value of the key, with a time to live. PSETEX uses a TTL in milliseconds. 設置一個有生命週期的KEY-VALUE,psetex()使用的週期單位爲毫秒。 Parameters Key TTL Value Return value Bool TRUE if the command is successful. Examples $redis->setex('key', 3600, 'value'); // sets key → value, with 1h TTL.
psetex 命令/方法/函數
Description

Set the string value in argument as value of the key, with a time to live(milliseconds). 設置一個有生命週期的KEY-VALUE,psetex()使用的週期單位爲毫秒。 Return value Bool TRUE if the command is successful. Examples $redis->psetex('key', 100, 'value'); // sets key → value, with 0.1 sec TTL.
setnx 命令/方法/函數
Description

Set the string value in argument as value of the key if the key doesn't already exist in the database. setnx用於設置一個KEY-VALUE,這個函數會先判斷Redis中是否有這個KEY,若是沒有就SET,有就返回False。 Parameters key value Return value Bool TRUE in case of success, FALSE in case of failure. Examples $redis->setnx('key', 'value'); /* return TRUE */ $redis->setnx('key', 'value'); /* return FALSE */
delete 命令/方法/函數
Description

Remove specified keys. 移除已經存在KEYS Parameters An array of keys, or an undefined number of parameters, each a key: key1 key2 key3 ... keyN 能夠是一個KEYS的數組,或者一個未定義的數字參數,或者一個一個的寫KEY Return value Long Number of keys deleted. 返回刪除KEY-VALUE的數量 Examples $redis->set('key1', 'val1'); $redis->set('key2', 'val2'); $redis->set('key3', 'val3'); $redis->set('key4', 'val4'); $redis->delete('key1', 'key2'); /* return 2 */ $redis->delete(array('key3', 'key4')); /* return 2 */
getSet 命令/方法/函數
Description

Sets a value and returns the previous entry at that key. 設置一個VALUE 而且返回該KEY當前的VALUE。 Parameters Key: key STRING: value Return value A string, the previous value located at this key. Example $redis->set('x', '42'); $exValue = $redis->getSet('x', 'lol'); // return '42', replaces x by 'lol' $newValue = $redis->get('x')' // return 'lol'
multi, exec, discard 命令/方法/函數
Description

Enter and exit transactional mode. 進入、退出事務處理模式。 Parameters (optional) Redis::MULTI or Redis::PIPELINE. Defaults to Redis::MULTI. A Redis::MULTI block of commands runs as a single transaction; a Redis::PIPELINE block is simply transmitted faster to the server, but without any guarantee of atomicity. discardcancels a transaction. multi函數的參數選項爲Redis::MULTI或者是Redis::PIPELINE.默認的是參數是Redis::MULTI。 Redis::MULTI將多個操做當作一個事務來處理。Redis::PIPELINE將做爲一個簡單快速的處理通道給服務器進行處理,可是不保證處理數據的原子性。 discard()函數取消一個事物處理模式。 Return value multi() returns the Redis instance and enters multi-mode. Once in multi-mode, all subsequent method calls return the same object until exec() is called. multi()返回一個Redis實例,而且這個實例進入到了事務處理模式(批量處理)。當進入到事務處理模式,全部的方法調用都將返回相同的Redis實例,一直到exec()被調用執行事務處理。 Example $ret = $redis->multi() ->set('key1', 'val1') ->get('key1') ->set('key2', 'val2') ->get('key2') ->exec(); /* $ret == array( 0 => TRUE, 1 => 'val1', 2 => TRUE, 3 => 'val2'); */
watch 命令/方法/函數
Description

Watches a key for modifications by another client. If the key is modified between WATCH and EXEC, the MULTI/EXEC transaction will fail (return FALSE). 監控一個KEY是否被其餘的客戶端修改。若是KEY在調用watch()和exec()之間被修改,那麼批量處理最終的exec()執行將失敗。經過一些實驗,這個函數的效果其實並無那麼好,或者說不可以準確的去監控。 Parameters keys: a list of keys Example $redis->watch('x'); /* long code here during the execution of which other clients could well modify `x` */ $ret = $redis->multi() ->incr('x') ->exec(); /* $ret = FALSE if x has been modified between the call to WATCH and the call to EXEC. */
unwatch 命令/方法/函數
Description

unwatch cancels all the watching of all keys by this client. unwatch()取消對於全部KEY值的監控操做針對於這個Redis實例。經過一些實驗,這個函數的效果其實並無那麼好,或者說不可以準確的去監控。
subscribe 命令/方法/函數
Description

Subscribe to channels. Warning: this function will probably change in the future. 方法回調函數,注意:該方法在未來有可能被修改。 Parameters channels: an array of channels to subscribe to callback: either a string or an array($instance, 'method_name'). The callback function receives 3 parameters: the redis instance, the channel name, and the message. Example function f($redis, $chan, $msg) { switch($chan) { case 'chan-1': ... break; case 'chan-2': ... break; case 'chan-2': ... break; } } $redis->subscribe(array('chan-1', 'chan-2', 'chan-3'), 'f'); // subscribe to 3 chans
publish 命令/方法/函數
Description

Publish messages to channels. Warning: this function will probably change in the future. 將消息發佈到信道。警告:這個功能可能會在將來發生變化。 Parameters channel: a channel to publish to messsage: string Example $redis->publish('chan-1', 'hello, world!'); // send message.
exists 命令/方法/函數
Description

Verify if the specified key exists. 驗證一個指定的KEY是否存在。 Parameters key Return value BOOL: If the key exists, return TRUE, otherwise return FALSE. BOOL:若是key存在,返回true,不然返回false。 Examples $redis->set('key', 'value'); $redis->exists('key'); /* TRUE */ $redis->exists('NonExistingKey'); /* FALSE */
incr 命令/方法/函數
Description

Increment the number stored at key by one. If the second argument is filled, it will be used as the integer value of the increment. 對指定的KEY的值自增1。如何填寫了第二個參數,將把第二個參數自增給KEY的值。 Parameters key value: value that will be added to key (only for incrBy) Return value INT the new value 返回新的INT數值 Examples $redis->incr('key1'); /* key1 didn't exists, set to 0 before the increment 若是key1不存在,在自增以前的默認值爲0 */ /* and now has the value 1 執行incr後,如今爲1 */ $redis->incr('key1'); /* 2 */ $redis->incr('key1'); /* 3 */
incrBy 命令/方法/函數
Description

對key的值加num,好比 incrby("ab", 10),至關於:ab+10



Return value INT the new value 返回新的INT數值 Examples $redis->incrBy('key1', 10); /* 若是key1的值爲8,那麼結果爲:18 */
incrByFloat 命令/方法/函數
Increment the key with floating point precision. 自增一個浮點型的數值。 Parameters key value: (float) value that will be added to the key Return value FLOAT the new value Examples $redis->incrByFloat('key1', 1.5); /* key1 didn't exist, so it will now be 1.5 */ $redis->incrByFloat('key1', 1.5); /* 3 */ $redis->incrByFloat('key1', -1.5); /* 1.5 */ $redis->incrByFloat('key1', 2.5); /* 3.5 */
decr 命令/方法/函數
對指定的KEY的值自減1(若是要自減指定的值,可使用decrBy)



Parameters

key value: value that will be substracted to key (only for decrBy) Return value INT the new value Examples $redis->decr('key1'); /* key1 didn't exists, set to 0 before the increment */ /* and now has the value -1 */ $redis->decr('key1'); /* -2 */ $redis->decr('key1'); /* -3 */
decrBy 命令/方法/函數
減去指定的值。



Return value INT the new value Examples $redis->set('key1', 50); $redis->decrBy('key1', 10); /* result:40 */
mGet 命令/方法/函數
Description

Get the values of all the specified keys. If one or more keys dont exist, the array will contain FALSE at the position of the key. 取得全部指定KEYS的值,若是一個或者更多的KEYS不存在,那麼返回的ARRAY中將在相應的KEYS的位置填充FALSE。 Parameters Array: Array containing the list of the keys 數組:一個KEYS的數組 Return value Array: Array containing the values related to keys in argument 數組:返回相應的KEYS的值 Examples $redis->set('key1', 'value1'); $redis->set('key2', 'value2'); $redis->set('key3', 'value3'); $redis->mGet(array('key1', 'key2', 'key3')); /* array('value1', 'value2', 'value3'); $redis->mGet(array('key0', 'key1', 'key5')); /* array(`FALSE`, 'value2', `FALSE`);
append 命令/方法/函數
Description

Append specified string to the string stored in specified key. 添加指定的字符串到指定的字符串KEY。 Parameters Key Value Return value INTEGER: Size of the value after the append 返回添加後KEY的SIZE Example $redis->set('key', 'value1'); $redis->append('key', 'value2'); /* 12 */ $redis->get('key'); /* 'value1value2' */
getRange 命令/方法/函數
getRange(substr also supported but deprecated in redis) Description Return a substring of a larger string 返回字符串的一部分 Parameters key start end Return value STRING: the substring Example $redis->set('key', 'string value'); $redis->getRange('key', 0, 5); /* 'string' */ $redis->getRange('key', -5, -1); /* 'value' */
setRange 命令/方法/函數
Description

Changes a substring of a larger string. 修改字符串的一部分。 Parameters key offset value Return value STRING: the length of the string after it was modified. Example $redis->set('key', 'Hello world'); $redis->setRange('key', 6, "redis"); /* returns 11 */ $redis->get('key'); /* "Hello redis" */
strlen 命令/方法/函數
Description

Get the length of a string value. 返回字符串的長度。 Parameters key Return value INTEGER Example $redis->set('key', 'value'); $redis->strlen('key'); /* 5 */
getBit 命令/方法/函數
Description

Return a single bit out of a larger string 將一個位返回一個較大的字符串 Parameters key offset Return value LONG: the bit value (0 or 1) Example $redis->set('key', "\x7f"); // this is 0111 1111 $redis->getBit('key', 0); /* 0 */ $redis->getBit('key', 1); /* 1 */
setBit 命令/方法/函數
Description

Changes a single bit of a string. Parameters key offset value: bool or int (1 or 0) Return value LONG: 0 or 1, the value of the bit before it was set. Example $redis->set('key', "*"); // ord("*") = 42 = 0x2f = "0010 1010" $redis->setBit('key', 5, 1); /* returns 0 */ $redis->setBit('key', 7, 1); /* returns 0 */ $redis->get('key'); /* chr(0x2f) = "/" = b("0010 1111") */
bitop 命令/方法/函數
Description

Bitwise operation on multiple keys. 對一個或多個保存二進制位的字符串 key 進行位元操做,並將結果保存到 destkey 上。 Parameters operation: either "AND", "OR", "NOT", "XOR" ret_key: return key key1 key2... Return value LONG: The size of the string stored in the destination key.
bitcount 命令/方法/函數
Description

Count bits in a string. Parameters key Return value LONG: The number of bits set to 1 in the value behind the input key. example https://blog.csdn.net/ma_jiang/article/details/61421888
mset 命令/方法/函數
Description

Sets multiple key-value pairs in one atomic command. MSETNX only returns TRUE if all the keys were set (see SETNX). 批量設置多個KEY-VALUE。若是全部的KEYS都被設置成功,若是這些KEY-VALUE都SET成功,使用msetnx將僅僅返回一個TURE,而若是有一個是已經存在的KEY,則全部的操做都不被執行。 Parameters Pairs: array(key => value, ...) Return value Bool TRUE in case of success, FALSE in case of failure. Example $redis->mset(array('key0' => 'value0', 'key1' => 'value1')); var_dump($redis->get('key0')); var_dump($redis->get('key1')); Output: string(6) "value0" string(6) "value1"
相關文章
相關標籤/搜索