Keys
del,delete - 刪除鍵
dump - 返回存儲在指定鍵值的序列化版本。
exists - 確定鍵是否存在
expire,setTimeout,pexpire - 設置鍵的生存時間(以秒為單位)
expireAt,pexpireAt - 將密鑰的到期時間設置為UNIX時間戳
keys,getKeys - 查找與給定模式匹配的所有鍵
scan - 掃描鍵空間中的鍵(Redis = 2.8.0)
migrate - 將密鑰從Redis實例原子傳輸?shù)搅硪粋€實例
move - 將鍵移動到另一個數(shù)據(jù)庫
object - 檢查Redis對象的內(nèi)部
persist - 從密鑰中刪除過期
randomKey - 從鍵空間返回隨機密鑰
rename,renameKey - 重命名鍵
renameNx - 重命名鍵,僅當新鍵不存在時
type - 確定存儲在鍵上的類型
sort - 對列表中的元素,集合或排序集進行排序
ttl,pttl - 獲取時間為一個鍵住
restore - 使用提供的序列化值創(chuàng)建密鑰,以前通過dump獲取。
scan
描述:掃描鍵的鍵空間
返回:Array,boolean:如果沒有更多的鍵,此函數(shù)將返回一個鍵的數(shù)組或FALSE
參考網(wǎng)址: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 - 在字符串之間執(zhí)行按位操作
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
描述:如果鍵在數(shù)據(jù)庫中不存在,則將參數(shù)中的字符串值設置為鍵的值。
$redis- setNx( key , value /* return TRUE */$redis- setNx( key , value /* return FALSE */
incr, incrBy
描述:將存儲在鍵上的數(shù)字增加1。 如果第二個參數(shù)被填充,它將被用作增量的整數(shù)值。
$redis- incr( key1 / * key1不存在,在增加前設置為0 * / / *,現(xiàn)在的值為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
描述:獲取所有指定鍵的值。 如果一個或多個鍵不存在,數(shù)組將在鍵的位置包含F(xiàn)ALSE。
$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
描述:將鍵移動到其他數(shù)據(jù)庫。
$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時間戳。 鑰匙的死亡日期,從紀元時間起的秒數(shù)。
描述:在項目上設置到期日期(時間戳)。 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.
以上就是php-redis常用命令總結的詳細內(nèi)容,PHP教程
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。
新聞熱點
疑難解答