Returns a random key.php
返回一个随机的KEY。git
None.github
STRING: an existing key in redis.redis
STRING:一个存在于REDIS中的KEY数据库
$key = $redis->randomKey(); $surprise = $redis->get($key); // who knows what's in there.
Switches to a given database.服务器
选择数据库网络
INTEGER: dbindex, the database number to switch to.app
整数值:数据库索引,数据库的IDdom
TRUE
in case of success, FALSE
in case of failure.异步
(See following function)
Moves a key to a different database.
移动一个KEY-VALUE到另外一个DB
Key: key, the key to move.
key:要移动的key
INTEGER: dbindex, the database number to move the key to.
整数值:要移动到的数据库ID
BOOL: TRUE
in case of success, FALSE
in case of failure.
$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
Renames a key.
重命名一个KEY
STRING: srckey, the key to rename.
STRING:源KEY,须要更名的KEY
STRING: dstkey, the new name for the key.
STRING:目标KEY,KEY的新名字
BOOL: TRUE
in case of success, FALSE
in case of failure.
$redis->set('x', '42'); $redis->rename('x', 'y'); $redis->get('y'); // → 42 $redis->get('x'); // → `FALSE`
Same as rename, but will not replace a key if the destination already exists. This is the same behaviour as setNx.
看起来功能和rename是同样的,可是renameNx不是KEY更名的功能,而是复制一个KEY的VALUE到一个新的KEY。是复制出一个新的KEY-VALUE,而VALUE则是srcKEY的VALUE,而不是PHP中的引用概念。
$redis->set('x', '42'); $redis->renameNx('x', 'y'); $redis->get('y'); // → 42 $redis->get('x'); // → 42
$redis->set('x','39');
$redis->get('x'); //->39
$redis->get('y'); //->42
Sets an expiration date (a timeout) on an item. pexpire requires a TTL in milliseconds.
给KEY设置一个生存周期,pexpire使用毫秒做为计算单位
Key: key. The key that will disappear.
Key:将被销毁的KEY
Integer: ttl. The key's remaining Time To Live, in seconds.
integer:生命周期
BOOL: TRUE
in case of success, FALSE
in case of failure.
$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.
Sets an expiration date (a timestamp) on an item. pexpireAt requires a timestamp in milliseconds.
给一个KEY设置一个生命周期,单位是UNIX的时间戳。
Key: key. The key that will disappear.
Key:将被销毁的key
Integer: Unix timestamp. The key's date of death, in seconds from Epoch time.
integer:Unix 时间戳
BOOL: TRUE
in case of success, FALSE
in case of failure.
$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.
Returns the keys that match a certain pattern.
返回某种计算模式取得的KEYS。
STRING: pattern, using '*' as a wildcard.
STRING:计算符
Array of STRING: The keys that match a certain pattern.
$allKeys = $redis->keys('*'); // all keys will match this. $keyWithUserPrefix = $redis->keys('user*');
Returns the current database's size.
返回当前DB的KEY的数量
None.
INTEGER: DB size, in number of keys.
$count = $redis->dbSize(); echo "Redis has $count keys\n";
Authenticate the connection using a password. Warning: The password is sent in plain-text over the network.
使用PASSWORD验证连接。警告:PASSWD以明码的形式在网络中传输。
STRING: password
BOOL: TRUE
if the connection is authenticated, FALSE
otherwise.
$redis->auth('foobared');
Starts the background rewrite of AOF (Append-Only File)
使用aof来进行数据库持久化。
None.
BOOL: TRUE
in case of success, FALSE
in case of failure.
$redis->bgrewriteaof();
Changes the slave status
选择从服务器
Either host (string) and port (int), or no parameter to stop being a slave.
BOOL: TRUE
in case of success, FALSE
in case of failure.
$redis->slaveof('10.0.1.7', 6379); /* ... */ $redis->slaveof();
Describes the object pointed to by a key.
声明一个对象,并指向KEY。
The information to retrieve (string) and the key (string). Info can be one of the following:
STRING for "encoding", LONG for "refcount" and "idletime", FALSE
if the key doesn't exist.
$redis->object("encoding", "l"); // → ziplist $redis->object("refcount", "l"); // → 1 $redis->object("idletime", "l"); // → 400 (in seconds, with a precision of 10 seconds).
Performs a synchronous save.
同步执行写入到磁盘。
None.
BOOL: TRUE
in case of success, FALSE
in case of failure. If a save is already running, this command will fail and return FALSE
.
$redis->save();
Performs a background save.
异步保存到磁盘。
None.
BOOL: TRUE
in case of success, FALSE
in case of failure. If a save is already running, this command will fail and return FALSE
.
$redis->bgSave();
Returns the timestamp of the last disk save.
返回最后一次数据磁盘持久化的时间戳。
None.
INT: timestamp.
$redis->lastSave();
Returns the type of data pointed by a given key.
返回KEY所指向的VALUE的数据类型。
Key: key
Depending on the type of the data pointed by the key, this method will return the following value:
string: Redis::REDIS_STRING
set: Redis::REDIS_SET
list: Redis::REDIS_LIST
zset: Redis::REDIS_ZSET
hash: Redis::REDIS_HASH
other: Redis::REDIS_NOT_FOUND
$redis->type('key');
Append specified string to the string stored in specified key.
添加指定的字符串到指定的字符串KEY。
Key Value
INTEGER: Size of the value after the append
返回添加后KEY的SIZE
$redis->set('key', 'value1'); $redis->append('key', 'value2'); /* 12 */ $redis->get('key'); /* 'value1value2' */
Return a substring of a larger string
返回字符串的一部分
key start end
STRING: the substring
$redis->set('key', 'string value'); $redis->getRange('key', 0, 5); /* 'string' */ $redis->getRange('key', -5, -1); /* 'value' */
Changes a substring of a larger string.
修改字符串的一部分。
key
offset
value
STRING: the length of the string after it was modified.
$redis->set('key', 'Hello world'); $redis->setRange('key', 6, "redis"); /* returns 11 */ $redis->get('key'); /* "Hello redis" */
Get the length of a string value.
返回字符串的长度。
key
INTEGER
$redis->set('key', 'value'); $redis->strlen('key'); /* 5 */
Return a single bit out of a larger string
key
offset
LONG: the bit value (0 or 1)
$redis->set('key', "\x7f"); // this is 0111 1111 $redis->getBit('key', 0); /* 0 */ $redis->getBit('key', 1); /* 1 */
Changes a single bit of a string.
key
offset
value: bool or int (1 or 0)
LONG: 0 or 1, the value of the bit before it was set.
$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") */
Bitwise operation on multiple keys.
operation: either "AND", "OR", "NOT", "XOR"
ret_key: return key
key1
key2...
LONG: The size of the string stored in the destination key.
Count bits in a string.
key
LONG: The number of bits set to 1 in the value behind the input key.
Removes all entries from the current database.
强制刷新当前DB的内存数。
None.
BOOL: Always TRUE
.
$redis->flushDB();
Removes all entries from all databases.
强制刷新全部的DB。
None.
BOOL: Always TRUE
.
$redis->flushAll();
Description
筛选
Key: key Options: array(key => value, ...) - optional, with the following keys and values:
'by' => 'some_pattern_*', 'limit' => array(0, 1), 'get' => 'some_other_pattern_*' or an array of patterns, 'sort' => 'asc' or 'desc', 'alpha' => TRUE, 'store' => 'external-key'
An array of values, or a number corresponding to the number of elements stored if that was used.
$redis->delete('s'); $redis->sadd('s', 5); $redis->sadd('s', 4); $redis->sadd('s', 2); $redis->sadd('s', 1); $redis->sadd('s', 3); var_dump($redis->sort('s')); // 1,2,3,4,5 var_dump($redis->sort('s', array('sort' => 'desc'))); // 5,4,3,2,1 var_dump($redis->sort('s', array('sort' => 'desc', 'store' => 'out'))); // (int)5
Returns an associative array from REDIS that provides information about the server. Passing no arguments to INFO will call the standard REDIS INFO command, which returns information such as the following:
返回redis的相关系统信息,相似于PHP的PHPINFO();能够选择参数,按照选择的参数返回相应的信息,也能够不写参数,返回全部的信息。
You can pass a variety of options to INFO (per the Redis documentation), which will modify what is returned.
option: The option to provide redis (e.g. "COMMANDSTATS", "CPU")
$redis->info(); /* standard redis INFO command */ $redis->info("COMMANDSTATS"); /* Information on the commands that have been run (>=2.6 only) $redis->info("CPU"); /* just CPU information from Redis INFO */
Resets the statistics reported by Redis using the INFO command (info()
function).
使用info()重置静态的日志。
These are the counters that are reset:
None.
BOOL: TRUE
in case of success, FALSE
in case of failure.
$redis->resetStat();
Returns the time to live left for a given key, in seconds. If the key doesn't exist, FALSE
is returned. pttl returns a time in milliseconds.
取得一个KEY已经存在的时间。若是这个KEY不存在,则返回FLASE。PTTL使用毫秒为单位。
Key: key
Long, the time left to live in seconds.
$redis->ttl('key');
Remove the expiration timer from a key.
删除一个KEY的生命周期设置。
Key: key
BOOL: TRUE
if a timeout was removed, FALSE
if the key didn’t exist or didn’t have an expiration timer.
若是确实有生命周期而且成功移除,则返回TRUE。若是KEY不存在,或者KEY没有生命周期则返回FLASE。
$redis->persist('key');
Sets 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,则全部的操做都不被执行。
Pairs: array(key => value, ...)
Bool TRUE
in case of success, FALSE
in case of failure.
$redis->mset(array('key0' => 'value0', 'key1' => 'value1')); var_dump($redis->get('key0')); var_dump($redis->get('key1'));
Output:
string(6) "value0" string(6) "value1"
Pops a value from the tail of a list, and pushes it to the front of another list. Also return this value.
从源LIST的最后弹出一个元素,而且把这个元素从目标LIST的顶部(左侧)压入目标LIST。
Key: srckey
Key: dstkey
STRING The element that was moved in case of success, FALSE
in case of failure.
$redis->delete('x', 'y'); $redis->lPush('x', 'abc'); $redis->lPush('x', 'def'); $redis->lPush('y', '123'); $redis->lPush('y', '456'); // move the last of x to the front of y. var_dump($redis->rpoplpush('x', 'y')); var_dump($redis->lRange('x', 0, -1)); var_dump($redis->lRange('y', 0, -1));
Output:
string(3) "abc" array(1) { [0]=> string(3) "def" } array(3) { [0]=> string(3) "abc" [1]=> string(3) "456" [2]=> string(3) "123" }
A blocking version of rpoplpush
, with an integral timeout in the third parameter.
rpoplpush的阻塞版本,这个版本有第三个参数用于设置阻塞时间,即若是源LIST为空,那么能够阻塞监听timeout的时间,若是有元素了则执行操做。
Key: srckey
Key: dstkey
Long: timeout
STRING The element that was moved in case of success, FALSE
in case of timeout.