Check the current connection status
检查当前连接实例的状态
(none)
STRING: +PONG
on success. Throws a RedisException object on connectivity error, as described above.
如果失败,Throws一个RedisException对象报出连接错误。
Sends a string to Redis, which replies with the same string
发送一个字符串到Redis,返回一个相同的字符串
STRING: The message to send.
STRING: the same message.
Get the value related to the specified key
取得与指定的键值相关联的值
key
String or Bool: If key didn't exist, FALSE
is returned. Otherwise, the value related to this key is returned.
返回相关值或者BOOL值,如果KEY不存在,返回FALSE。如果有相关的KEY和值返回值。
$redis->get('key');
Set the string value in argument as value of the key.
设置值到KEY
Key
Value
Timeout (optional). Calling SETEX
is preferred if you want a timeout.
Bool TRUE
if the command is successful.
$redis->set('key', 'value');
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()使用的周期单位为毫秒。
Key TTL Value
Bool TRUE
if the command is successful.
$redis->setex('key', 3600, 'value'); // sets key → value, with 1h TTL. $redis->psetex('key', 100, 'value'); // sets key → value, with 0.1 sec TTL.
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。
key value
Bool TRUE
in case of success, FALSE
in case of failure.
$redis->setnx('key', 'value'); /* return TRUE */ $redis->setnx('key', 'value'); /* return FALSE */
Remove specified keys.
移除已经存在KEYS
An array of keys, or an undefined number of parameters, each a key: key1 key2 key3 ... keyN
可以是一个KEYS的数组,或者一个未定义的数字参数,或者一个一个的写KEY
Long Number of keys deleted.
返回删除KEY-VALUE的数量
$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 */
Sets a value and returns the previous entry at that key.
设置一个VALUE 并且返回该KEY当前的VALUE。
Key: key
STRING: value
A string, the previous value located at this key.
$redis->set('x', '42'); $exValue = $redis->getSet('x', 'lol'); // return '42', replaces x by 'lol' $newValue = $redis->get('x')' // return 'lol'