php-Redis 常用命令專題

來源:互聯網
上載者:User

標籤:back   ttl   top   scan   模式比對   檢查   current   add   序列化   

Keys
  • del,delete - 刪除鍵
  • dump - 返回儲存在指定索引值的序列化版本。
  • exists - 確定鍵是否存在
  • expire,setTimeout,pexpire - 設定鍵的存留時間(以秒為單位)
  • expireAt,pexpireAt - 將密鑰的到期時間設定為UNIX時間戳記
  • keys,getKeys - 尋找與給定模式比對的所有鍵
  • scan - 掃描鍵空間中的鍵(Redis> = 2.8.0)
  • migrate - 將密鑰從Redis執行個體原子傳輸到另一個執行個體
  • move - 將鍵移動到另一個資料庫
  • object - 檢查Redis對象的內部
  • persist - 從密鑰中刪除到期
  • randomKey - 從鍵空間返回隨機密鑰
  • rename,renameKey - 重新命名鍵
  • renameNx - 重新命名鍵,僅當新鍵不存在時
  • type - 確定儲存在鍵上的類型
  • sort - 對列表中的元素,集合或排序集進行排序
  • ttl,pttl - 擷取時間為一個鍵住
  • restore - 使用提供的序列化值建立密鑰,以前通過dump擷取。
scan

描述:掃描鍵的鍵空間

返回:Array,boolean:如果沒有更多的鍵,此函數將返回一個鍵的數組或FALSE

參考網址:http://stackoverflow.com/questions/19910527/how-to-use-hscan-command-in-redis

 

$it = NULL; /* Initialize our iterator to NULL */$redis->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY); /* retry when we get no keys back */while($arr_keys = $redis->scan($it)) {    foreach($arr_keys as $str_key) {        echo "Here is a key: $str_key\n";    }    echo "No more keys to scan!\n";}

 

Strings
  • append - 將值附加到鍵
  • bitCount - 計算字串中的設定位
  • bitOp - 在字串之間執行按位操作
  • decr,decrBy - 遞減鍵的值
  • get - 擷取鍵的值
  • getBit - 返回在key處儲存的字串值中位移處的位值
  • getRange - 擷取儲存在鍵上的字串的子字串
  • getSet - 設定鍵的字串值並返回其舊值
  • incr,incrBy - 遞增鍵的值
  • incrByFloat - 將鍵的浮點值增加給定的量
  • mGet,getMultiple - 擷取所有給定鍵的值
  • mSet,mSetNX - 將多個鍵設定為多個值
  • set - 設定鍵的字串值
  • setBit - 設定或清除儲存在鍵的字串值中位移處的位
  • setEx,pSetEx - 設定鍵的值和到期時間
  • setNx - 設定鍵的值,僅當鍵不存在時
  • setRange - 在指定位移處開始的鍵處覆蓋字串的一部分
  • strLen - 擷取儲存在鍵中的值的長度
pSetEx

描述:PSETEX使用以毫秒為單位的TTL

$ redis-> pSetEx(‘key‘,100,‘value‘); //設定鍵→值,0.1秒TTL。
setNx

描述:如果鍵在資料庫中不存在,則將參數中的字串值設定為鍵的值。

$redis->setNx(‘key‘, ‘value‘); /* return TRUE */$redis->setNx(‘key‘, ‘value‘); /* return FALSE */
incr, incrBy

描述:將儲存在鍵上的數字增加1。 如果第二個參數被填充,它將被用作增量的整數值。

$redis->incr(‘key1‘); / * key1不存在,在增加前設定為0 * /                       / *,現在的值為1 * /$redis->incr(‘key1‘); /* 2 */$redis->incr(‘key1‘); /* 3 */$redis->incr(‘key1‘); /* 4 */$redis->incrBy(‘key1‘, 10); /* 14 */
incrByFloat

描述:使用浮點精度遞增鍵

$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); /* 4 */
mGet, getMultiple

描述:擷取所有指定鍵的值。 如果一個或多個鍵不存在,數組將在鍵的位置包含FALSE。

$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`, ‘value1‘, `FALSE`);
getSet

描述:設定一個值並返回該鍵上的上一個條目。

$redis->set(‘x‘, ‘42‘);$exValue = $redis->getSet(‘x‘, ‘lol‘);  // return ‘42‘, replaces x by ‘lol‘$newValue = $redis->get(‘x‘)‘       // return ‘lol‘
move

描述:將鍵移動到其他資料庫。

$redis->select(0);  // switch to DB 0$redis->set(‘x‘, ‘42‘); // write 42 to x$redis->move(‘x‘, 1);   // move to DB 1$redis->select(1);  // switch to DB 1$redis->get(‘x‘);   // will return 42
rename, renameKey

描述:

$redis->set(‘x‘, ‘42‘);$redis->rename(‘x‘, ‘y‘);$redis->get(‘y‘);   // → 42$redis->get(‘x‘);   // → `FALSE
renameNx

描述:與重新命名相同,但如果目標已存在,則不會替換密鑰。 這與setNx的行為相同。

$redis->set(‘x‘, ‘42‘);$redis->setTimeout(‘x‘, 3); // x will disappear in 3 seconds.sleep(5);               // wait 5 seconds$redis->get(‘x‘);       // will return `FALSE`, as ‘x‘ has expired.
expireAt, pexpireAt 

這個適合設定從Unix時間戳記。 鑰匙的死亡日期,從紀元時間起的秒數。

描述:在項目上設定到期日(時間戳記)。 pexpireAt需要一個以毫秒為單位的時間戳記。

$redis->set(‘x‘, ‘42‘);$now = time(NULL); // current timestamp$redis->expireAt(‘x‘, $now + 3);    // x will disappear in 3 seconds.sleep(5);               // wait 5 seconds$redis->get(‘x‘);       // will return `FALSE`, as ‘x‘ has expired.

 

 

 

 

 

 

 

 

 

 

Description: Set the string value in argument as value of the key, with a time to live. PSETEX uses a TTL in milliseconds.

Parameters

Key TTL Value

Return value

Bool TRUE if the command is successful.

Examples

php-Redis 常用命令專題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.