Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit be3089c

Browse files
cookiegurumichael-grunder
authored andcommitted
Add syntax highlighting to cluster readme
1 parent 34c8c68 commit be3089c

1 file changed

Lines changed: 16 additions & 18 deletions

File tree

cluster.markdown

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Redis introduces cluster support as of version 3.0.0, and to communicate with a
88
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.
99

1010
#### Declaring a cluster with an array of seeds
11-
<pre>
11+
~~~php
1212
// Create a cluster setting two nodes as seeds
1313
$obj_cluster = new RedisCluster(NULL, Array('host:7000', 'host:7001', 'host:7003'));
1414

@@ -21,25 +21,24 @@ $obj_cluster = new RedisCluster(NULL, Array("host:7000", "host:7001"), 1.5, 1.5,
2121

2222
// Connect with cluster using password.
2323
$obj_cluster = new RedisCluster(NULL, Array("host:7000", "host:7001"), 1.5, 1.5, true, "password");
24-
25-
</pre>
24+
~~~
2625

2726
#### Loading a cluster configuration by name
2827
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.
2928

30-
<pre>
29+
~~~ini
3130
# In redis.ini
3231
redis.clusters.seeds = "mycluster[]=localhost:7000&test[]=localhost:7001"
3332
redis.clusters.timeout = "mycluster=5"
3433
redis.clusters.read_timeout = "mycluster=10"
3534
redis.clusters.auth = "mycluster=password"
36-
</pre>
35+
~~~
3736

3837
Then, this cluster can be loaded by doing the following
3938

40-
<pre>
39+
~~~php
4140
$obj_cluster = new RedisCluster('mycluster');
42-
</pre>
41+
~~~
4342

4443
## Connection process
4544

@@ -61,7 +60,7 @@ Because of this, the RedisCluster class will update its keyspace mapping wheneve
6160
## Automatic slave failover / distribution
6261
By default, RedisCluster will only ever send commands to master nodes, but can be configured differently for readonly commands if requested.
6362

64-
<pre>
63+
~~~php
6564
// The default option, only send commands to master nodes
6665
$obj_cluster->setOption(RedisCluster::OPT_SLAVE_FAILOVER, RedisCluster::FAILOVER_NONE);
6766

@@ -77,24 +76,24 @@ $obj_cluster->setOption(
7776
$obj_cluster->setOption(
7877
RedisCluster::OPT_SLAVE_FAILOVER, RedisCluster::FAILOVER_DISTRIBUTE_SLAVES
7978
);
80-
</pre>
79+
~~~
8180

8281
## Main command loop
8382
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:
8483

85-
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.
8685
2. We have been bounced around longer than the timeout which was set on construction.
87-
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.
8887
4. We receive a valid response, in which case the data is returned to the caller.
8988

9089
## Transactions
9190
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.
9291

93-
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.
9493

9594
Consider the following example:
9695

97-
<pre>
96+
~~~php
9897
// Cluster is put into MULTI state locally
9998
$obj_cluster->multi();
10099

@@ -109,7 +108,7 @@ $obj_cluster->get("myotherkey");
109108
// This will always return an array, even in the event of a failed transaction
110109
// on one of the nodes, in which case that element will be FALSE
111110
print_r($obj_cluster->exec());
112-
</pre>
111+
~~~
113112

114113
## Pipelining
115114
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.
@@ -122,11 +121,11 @@ For all of these multiple key commands (with the exception of MGET and MSET), th
122121
### MGET and MSET
123122
RedisCluster has specialized processing for MGET and MSET which allows you to send any number of keys (hashing to whichever slots) without having to consider where they live. The way this works, is that the RedisCluster class will split the command as it iterates through keys, delivering a subset of commands per each key's slot.
124123

125-
<pre>
124+
~~~php
126125
// This will be delivered in two commands. First for all of the {hash1} keys,
127126
// and then to grab 'otherkey'
128127
$obj_cluster->mget(Array("{hash1}key1","{hash1}key2","{hash1}key3","otherkey"));
129-
</pre>
128+
~~~
130129

131130
This operation can also be done in MULTI mode transparently.
132131

@@ -141,7 +140,6 @@ $obj_cluster->echo("mykey","Hello World!");
141140
foreach ($obj_cluster->_masters() as $arr_master) {
142141
$obj_cluster->echo($arr_master, "Hello: " . implode(':', $arr_master));
143142
}
144-
145143
~~~
146144

147145
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:
@@ -168,7 +166,7 @@ You can use the cluster functionality of phpredis to store PHP session informati
168166

169167
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.
170168

171-
~~~
169+
~~~ini
172170
session.save_handler = rediscluster
173171
session.save_path = "seed[]=host1:port1&seed[]=host2:port2&seed[]=hostN:portN&timeout=2&read_timeout=2&failover=error&persistent=1&auth=password"
174172
~~~

0 commit comments

Comments
 (0)