You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*timeout*: float, value in seconds (optional, default is 0 meaning unlimited)
201
204
*persistent_id*: string. identity for the requested persistent connection
205
+
*retry_interval*: int, value in milliseconds (optional)
202
206
203
207
##### *Return value*
204
208
@@ -322,6 +326,7 @@ _**Description**_: Sends a string to Redis, which replies with the same string
322
326
1.[save](#save) - Synchronously save the dataset to disk (wait to complete)
323
327
1.[slaveof](#slaveof) - Make the server a slave of another instance, or promote it to master
324
328
1.[time](#time) - Return the current server time
329
+
1.[slowlog](#slowlog) - Access the Redis slowlog entries
325
330
326
331
### bgrewriteaof
327
332
-----
@@ -539,6 +544,36 @@ the unix timestamp, and element one being microseconds.
539
544
$redis->time();
540
545
~~~
541
546
547
+
### slowlog
548
+
-----
549
+
_**Description**_: Access the Redis slowlog
550
+
551
+
##### *Parameters*
552
+
*Operation* (string): This can be either `GET`, `LEN`, or `RESET`
553
+
*Length* (integer), optional: If executing a `SLOWLOG GET` command, you can pass an optional length.
554
+
#####
555
+
556
+
##### *Return value*
557
+
The return value of SLOWLOG will depend on which operation was performed.
558
+
SLOWLOG GET: Array of slowlog entries, as provided by Redis
559
+
SLOGLOG LEN: Integer, the length of the slowlog
560
+
SLOWLOG RESET: Boolean, depending on success
561
+
#####
562
+
563
+
##### *Examples*
564
+
~~~
565
+
// Get ten slowlog entries
566
+
$redis->slowlog('get', 10);
567
+
// Get the default number of slowlog entries
568
+
569
+
$redis->slowlog('get');
570
+
// Reset our slowlog
571
+
$redis->slowlog('reset');
572
+
573
+
// Retrieve slowlog length
574
+
$redis->slowlog('len');
575
+
~~~
576
+
542
577
## Keys and Strings
543
578
544
579
### Strings
@@ -604,19 +639,30 @@ $redis->get('key');
604
639
605
640
### set
606
641
-----
607
-
_**Description**_: Set the string value in argument as value of the key.
642
+
_**Description**_: Set the string value in argument as value of the key. If you're using Redis >= 2.6.12, you can pass extended options as explained below
608
643
609
644
##### *Parameters*
610
645
*Key*
611
646
*Value*
612
-
*Timeout* (optional). Calling `SETEX` is preferred if you want a timeout.
647
+
*Timeout or Options Array* (optional). If you pass an integer, phpredis will redirect to SETEX, and will try to use Redis >= 2.6.12 extended options if you pass an array with valid values
613
648
614
649
##### *Return value*
615
650
*Bool*`TRUE` if the command is successful.
616
651
617
652
##### *Examples*
618
653
~~~
654
+
// Simple key -> value set
619
655
$redis->set('key', 'value');
656
+
657
+
// Will redirect, and actually make an SETEX call
658
+
$redis->set('key','value', 10);
659
+
660
+
// Will set the key, if it doesn't exist, with a ttl of 10 seconds
Copy file name to clipboardExpand all lines: arrays.markdown
+22-3Lines changed: 22 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ There are several ways of creating Redis arrays; they can be pre-defined in red
17
17
18
18
#### Declaring a new array with a list of nodes
19
19
<pre>
20
-
$ra = new RedisArray(array("host1", "host2:63792, "host2:6380"));
20
+
$ra = new RedisArray(array("host1", "host2:63792", "host2:6380"));
21
21
</pre>
22
22
23
23
@@ -26,15 +26,27 @@ $ra = new RedisArray(array("host1", "host2:63792, "host2:6380"));
26
26
function extract_key_part($k) {
27
27
return substr($k, 0, 3); // hash only on first 3 characters.
28
28
}
29
-
$ra = new RedisArray(array("host1", "host2:63792, "host2:6380"), array("function" => "extract_key_part"));
29
+
$ra = new RedisArray(array("host1", "host2:63792", "host2:6380"), array("function" => "extract_key_part"));
30
30
</pre>
31
31
32
32
#### Defining a "previous" array when nodes are added or removed.
33
33
When a new node is added to an array, phpredis needs to know about it. The old list of nodes becomes the “previous” array, and the new list of nodes is used as a main ring. Right after a node has been added, some read commands will point to the wrong nodes and will need to look up the keys in the previous ring.
34
34
35
35
<pre>
36
36
// adding host3 to a ring containing host1 and host2. Read commands will look in the previous ring if the data is not found in the main ring.
37
-
$ra = new RedisArray(array('host1', 'host2', 'host3'), array('previous' => array('host1', 'host2')));
37
+
$ra = new RedisArray(array("host1", "host2", "host3"), array("previous" => array("host1", "host2")));
38
+
</pre>
39
+
40
+
#### Specifying the "retry_interval" parameter
41
+
The retry_interval is used to specify a delay in milliseconds between reconnection attempts in case the client loses connection with a server
42
+
<pre>
43
+
$ra = new RedisArray(array("host1", "host2:63792", "host2:6380"), array("retry_timeout" => 100)));
44
+
</pre>
45
+
46
+
#### Specifying the "lazy_connect" parameter
47
+
This option is useful when a cluster has many shards but not of them are necessarily used at one time.
48
+
<pre>
49
+
$ra = new RedisArray(array("host1", "host2:63792", "host2:6380"), array("lazy_connect" => true)));
38
50
</pre>
39
51
40
52
#### Defining arrays in Redis.ini
@@ -76,6 +88,13 @@ In order to control the distribution of keys by hand, you can provide a custom f
76
88
77
89
For instance, instanciate a RedisArray object with `new RedisArray(array("us-host", "uk-host", "de-host"), array("distributor" => "dist"));` and write a function called "dist" that will return `2` for all the keys that should end up on the "de-host" server.
This declares that we started with 2 shards and moved to 4 then 8 shards. The number of initial shards is 2 and the resharding level (or number of iterations) is 2.
97
+
79
98
## Migrating keys
80
99
81
100
When a node is added or removed from a ring, RedisArray instances must be instanciated with a “previous” list of nodes. A single call to `$ra->_rehash()` causes all the keys to be redistributed according to the new list of nodes. Passing a callback function to `_rehash()` makes it possible to track the progress of that operation: the function is called with a node name and a number of keys that will be examined, e.g. `_rehash(function ($host, $count){ ... });`.
0 commit comments