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.