ping
Description
Check the current connection status
檢查當前連接實例的狀態
Parameters
(none)
Return Value
STRING: +PONG on success. Throws a RedisException object on connectivity error, as described above.
如果失敗,Throws一個RedisException對象報出連接錯誤。
echo
Description
Sends a string to Redis, which replies with the same string
發送一個字符串到Redis,返回一個相同的字符串
Parameters
STRING: The message to send.
Return Value
STRING: the same message.
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, psetex
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.
$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 */
del, delete
Description
Remove specified keys.
移除已經存在KEYS www.2cto.com
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 */