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
Copy file name to clipboardExpand all lines: cluster.markdown
+20-20Lines changed: 20 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ Redis introduces cluster support as of version 3.0.0, and to communicate with a
8
8
To maintain consistency with the RedisArray class, one can create and connect to a cluster either by passing it one or more 'seed' nodes, or by defining these in redis.ini as a 'named' cluster.
9
9
10
10
#### Declaring a cluster with an array of seeds
11
-
~~~php
11
+
```php
12
12
// Create a cluster setting three nodes as seeds
13
13
$obj_cluster = new RedisCluster(NULL, Array('host:7000', 'host:7001', 'host:7003'));
$obj_cluster = new RedisCluster(NULL, Array("host:7000", "host:7001"), 1.5, 1.5, true, "password");
24
-
~~~
24
+
```
25
25
26
26
#### Loading a cluster configuration by name
27
27
In order to load a named array, one must first define the seed nodes in redis.ini. The following lines would define the cluster 'mycluster', and be loaded automatically by phpredis.
With the exception of commands that are directed to a specific node, each command executed via RedisCluster is processed through a command loop, where we make the request, handle any MOVED or ASK redirection, and repeat if necessary. This continues until one of the following conditions is met:
83
83
84
-
1. We fail to communicate with *any* node that we are aware of, in which case a ~~~RedisClusterException~~~ is raised.
84
+
1. We fail to communicate with *any* node that we are aware of, in which case a `RedisClusterException` is raised.
85
85
2. We have been bounced around longer than the timeout which was set on construction.
86
-
3. Redis cluster returns to us a ~~~CLUSTERDOWN~~~ error, in which case a ~~~RedisClusterException~~~ is raised.
86
+
3. Redis cluster returns to us a `CLUSTERDOWN` error, in which case a `RedisClusterException` is raised.
87
87
4. We receive a valid response, in which case the data is returned to the caller.
88
88
89
89
## Transactions
90
90
The RedisCluster class fully supports MULTI ... EXEC transactions, including commands such as MGET and MSET which operate on multiple keys. There are considerations that must be taken into account here however.
91
91
92
-
When you call ~~~RedisCluster->multi()~~~, the cluster is put into a MULTI state, but the MULTI command is not delivered to any nodes until a key is requested on that node. In addition, calls to EXEC will always return an array (even in the event that a transaction to a given node failed), as the commands can be going to any number of nodes depending on what is called.
92
+
When you call `RedisCluster->multi()`, the cluster is put into a MULTI state, but the MULTI command is not delivered to any nodes until a key is requested on that node. In addition, calls to EXEC will always return an array (even in the event that a transaction to a given node failed), as the commands can be going to any number of nodes depending on what is called.
// This will always return an array, even in the event of a failed transaction
109
109
// on one of the nodes, in which case that element will be FALSE
110
110
print_r($obj_cluster->exec());
111
-
~~~
111
+
```
112
112
113
113
## Pipelining
114
114
The RedisCluster class does not support pipelining as there is no way to detect whether the keys still live where our map indicates that they do and would therefore be inherently unsafe. It would be possible to implement this support as an option if there is demand for such a feature.
@@ -123,25 +123,25 @@ RedisCluster has specialized processing for MGET, MSET, DEL, and UNLINK which al
123
123
124
124
*Note: If you send keys that hash to more than one slot, these commands are no longer atomic.*
125
125
126
-
~~~php
126
+
```php
127
127
// This will send two `MGET` commands. One for `{hash1}` keys, and one for `otherkey`
This operation can also be done in MULTI mode transparently.
132
132
133
133
## Directed node commands
134
134
There are a variety of commands which have to be directed at a specific node. In the case of these commands, the caller can either pass a key (which will be hashed and used to direct our command), or an array with host:port.
135
135
136
-
~~~php
136
+
```php
137
137
// This will be directed at the slot/node which would store "mykey"
138
138
$obj_cluster->echo("mykey","Hello World!");
139
139
140
140
// Here we're iterating all of our known masters, and delivering the command there
141
141
foreach ($obj_cluster->_masters() as $arr_master) {
In the case of all commands which need to be directed at a node, the calling convention is identical to the Redis call, except that they require an additional (first) argument in order to deliver the command. Following is a list of each of these commands:
147
147
@@ -167,10 +167,10 @@ You can use the cluster functionality of phpredis to store PHP session informati
167
167
168
168
To do this, you must configure your `session.save_handler` and `session.save_path` INI variables to give phpredis enough information to communicate with the cluster.
Set this variable to "rediscluster" to inform phpredis that this is a cluster instance.
@@ -179,7 +179,7 @@ Set this variable to "rediscluster" to inform phpredis that this is a cluster in
179
179
The save path for cluster based session storage takes the form of a PHP GET request, and requires that you specify at least one `seed` node. Other options you can specify are as follows:
180
180
181
181
*_timeout (double)_: The amount of time phpredis will wait when connecting or writing to the cluster.
182
-
*_read_timeout (double)_: The amount of time phpredis will wait for a result from the cluster.
182
+
*_read\_timeout (double)_: The amount of time phpredis will wait for a result from the cluster.
183
183
*_persistent_: Tells phpredis whether persistent connections should be used.
184
184
*_failover (string)_: How phpredis should distribute session reads between master and slave nodes.
185
185
*_none_ : phpredis will only communicate with master nodes
0 commit comments