redis 字串(string)函數

來源:互聯網
上載者:User

標籤:eth   pipeline   sim   been   ant   case   ase   des   value   

字串(string)函數

get 命令/方法/函數DescriptionGet the value related to the specified key取得與指定的索引值相關聯的值ParameterskeyReturn ValueString 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 命令/方法/函數DescriptionSet the string value in argument as value of the key.設定值到KEYParametersKeyValueTimeout (optional). Calling SETEX is preferred if you want a timeout.Return valueBool TRUE if the command is successful.Examples$redis->set(‘key‘, ‘value‘);
setex 命令/方法/函數DescriptionSet the string value in argument as value of the key, with a time to live. PSETEX uses a TTL in milliseconds.設定一個有生命週期的KEY-VALUE,psetex()使用的周期單位為毫秒。ParametersKey TTL ValueReturn valueBool TRUE if the command is successful.Examples$redis->setex(‘key‘, 3600, ‘value‘); // sets key → value, with 1h TTL.
psetex 命令/方法/函數DescriptionSet the string value in argument as value of the key, with a time to live(milliseconds).設定一個有生命週期的KEY-VALUE,psetex()使用的周期單位為毫秒。Return valueBool TRUE if the command is successful.Examples$redis->psetex(‘key‘, 100, ‘value‘); // sets key → value, with 0.1 sec TTL.
setnx 命令/方法/函數DescriptionSet 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。Parameterskey valueReturn valueBool TRUE in case of success, FALSE in case of failure.Examples$redis->setnx(‘key‘, ‘value‘); /* return TRUE */$redis->setnx(‘key‘, ‘value‘); /* return FALSE */
delete 命令/方法/函數DescriptionRemove specified keys.移除已經存在KEYSParametersAn array of keys, or an undefined number of parameters, each a key: key1 key2 key3 ... keyN可以是一個KEYS的數組,或者一個未定義的數字參數,或者一個一個的寫KEYReturn valueLong 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 命令/方法/函數DescriptionSets a value and returns the previous entry at that key.設定一個VALUE 並且返回該KEY當前的VALUE。ParametersKey: keySTRING: valueReturn valueA 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 命令/方法/函數DescriptionEnter 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 valuemulti() 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 命令/方法/函數DescriptionWatches 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()執行將失敗。通過一些實驗,這個函數的效果其實並沒有那麼好,或者說不能夠準確的去監控。Parameterskeys: a list of keysExample$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 命令/方法/函數Descriptionunwatch cancels all the watching of all keys by this client.unwatch()取消對於所有KEY值的監控操作針對於這個Redis執行個體。通過一些實驗,這個函數的效果其實並沒有那麼好,或者說不能夠準確的去監控。
subscribe 命令/方法/函數DescriptionSubscribe to channels. Warning: this function will probably change in the future.方法回呼函數,注意:該方法在將來有可能被修改。Parameterschannels: an array of channels to subscribe tocallback: either a string or an array($instance, ‘method_name‘). The callback function receives 3 parameters: the redis instance, the channel name, and the message.Examplefunction 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 命令/方法/函數DescriptionPublish messages to channels. Warning: this function will probably change in the future.將訊息發布到通道。警告:這個功能可能會在未來發生變化。Parameterschannel: a channel to publish tomesssage: stringExample$redis->publish(‘chan-1‘, ‘hello, world!‘); // send message.
exists 命令/方法/函數DescriptionVerify if the specified key exists.驗證一個指定的KEY是否存在。ParameterskeyReturn valueBOOL: 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 命令/方法/函數DescriptionIncrement 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的值。Parameterskeyvalue: value that will be added to key (only for incrBy)Return valueINT 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+10Return valueINT the new value返回新的INT數值Examples$redis->incrBy(‘key1‘, 10); /* 如果key1的值為8,那麼結果為:18 */
incrByFloat 命令/方法/函數Increment the key with floating point precision.自增一個浮點型的數值。Parameterskeyvalue: (float) value that will be added to the keyReturn valueFLOAT the new valueExamples$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)Parameterskeyvalue: value that will be substracted to key (only for decrBy)Return valueINT the new valueExamples$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 valueINT the new valueExamples$redis->set(‘key1‘, 50);$redis->decrBy(‘key1‘, 10); /* result:40 */
mGet 命令/方法/函數DescriptionGet 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。ParametersArray: Array containing the list of the keys數組:一個KEYS的數組Return valueArray: 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 命令/方法/函數DescriptionAppend specified string to the string stored in specified key.添加指定的字串到指定的字串KEY。ParametersKey ValueReturn valueINTEGER: Size of the value after the append返回添加後KEY的SIZEExample$redis->set(‘key‘, ‘value1‘);$redis->append(‘key‘, ‘value2‘); /* 12 */$redis->get(‘key‘); /* ‘value1value2‘ */
getRange 命令/方法/函數getRange(substr also supported but deprecated in redis)DescriptionReturn a substring of a larger string返回字串的一部分Parameterskey start endReturn valueSTRING: the substringExample$redis->set(‘key‘, ‘string value‘);$redis->getRange(‘key‘, 0, 5); /* ‘string‘ */$redis->getRange(‘key‘, -5, -1); /* ‘value‘ */
setRange 命令/方法/函數DescriptionChanges a substring of a larger string.修改字串的一部分。ParameterskeyoffsetvalueReturn valueSTRING: 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 命令/方法/函數DescriptionGet the length of a string value.返回字串的長度。ParameterskeyReturn valueINTEGERExample$redis->set(‘key‘, ‘value‘);$redis->strlen(‘key‘); /* 5 */
getBit 命令/方法/函數DescriptionReturn a single bit out of a larger string將一個位返回一個較大的字串ParameterskeyoffsetReturn valueLONG: 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 命令/方法/函數DescriptionChanges a single bit of a string.Parameterskeyoffsetvalue: bool or int (1 or 0)Return valueLONG: 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 命令/方法/函數DescriptionBitwise operation on multiple keys.對一個或多個儲存二進位位的字串 key 進行位元操作,並將結果儲存到 destkey 上。Parametersoperation: either "AND", "OR", "NOT", "XOR"ret_key: return keykey1key2...Return valueLONG: The size of the string stored in the destination key.
bitcount 命令/方法/函數DescriptionCount bits in a string.ParameterskeyReturn valueLONG: The number of bits set to 1 in the value behind the input key.example61421888
mset 命令/方法/函數DescriptionSets 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,則所有的操作都不被執行。ParametersPairs: array(key => value, ...)Return valueBool 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"

redis 字串(string)函數

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.