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

Skip to content

Commit 5a609fa

Browse files
yatsukhnenkomichael-grunder
authored andcommitted
Add documentation
1 parent 46da22b commit 5a609fa

2 files changed

Lines changed: 202 additions & 0 deletions

File tree

README.markdown

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ If you've found phpredis useful and would like to buy the maintainers a coffee (
2323
* [PHP Session handler](#php-session-handler)
2424
* [Distributed Redis Array](#distributed-redis-array)
2525
* [Redis Cluster support](#redis-cluster-support)
26+
* [Redis Sentinel support](#redis-sentinel-support)
2627
* [Running the unit tests](#running-the-unit-tests)
2728
1. [Classes and methods](#classes-and-methods)
2829
* [Usage](#usage)
@@ -97,6 +98,10 @@ See [dedicated page](./arrays.markdown#readme).
9798

9899
See [dedicated page](./cluster.markdown#readme).
99100

101+
## Redis Sentinel support
102+
103+
See [dedicated page](./sentinel.markdown#readme).
104+
100105
## Running the unit tests
101106

102107
phpredis uses a small custom unit test suite for testing functionality of the various classes. To run tests, simply do the following:
@@ -114,6 +119,9 @@ tests/mkring.sh stop
114119
tests/make-cluster.sh start
115120
php tests/TestRedis.php --class RedisCluster
116121
tests/make-cluster.sh stop
122+
123+
# Run tests for RedisSentinel class
124+
php tests/TestRedis.php --class RedisSentinel
117125
~~~
118126

119127
Note that it is possible to run only tests which match a substring of the test itself by passing the additional argument '--test <str>' when invoking.

sentinel.markdown

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
Redis Sentinel
2+
==============
3+
4+
Redis Sentinel provides high availability for Redis. In practical terms this means that using Sentinel you can create a Redis deployment that resists without human intervention certain kinds of failures.
5+
6+
Redis Sentinel also provides other collateral tasks such as monitoring, notifications and acts as a configuration provider for clients.
7+
8+
## Class RedisSentinel
9+
-----
10+
11+
##### *Parameters*
12+
13+
*host*: String, IP address or hostname
14+
*port*: Int (optional, default is 26379)
15+
*timeout*: Float, value in seconds (optional, default is 0 meaning unlimited)
16+
*persistent*: String, persistent connection id (optional, default is NULL meaning not persistent)
17+
*retry_interval*: Int, value in milliseconds (optional, default is 0)
18+
*read_timeout*: Float, value in seconds (optional, default is 0 meaning unlimited)
19+
20+
##### *Example*
21+
22+
~~~php
23+
$sentinel = new RedisSentinel('127.0.0.1'); // default parameters
24+
$sentinel = new RedisSentinel('127.0.0.1', 26379, 2.5); // 2.5 sec timeout.
25+
$sentinel = new RedisSentinel('127.0.0.1', 26379, 0, 'sentinel'); // persistent connection with id 'sentinel'
26+
$sentinel = new RedisSentinel('127.0.0.1', 26379, 0, ''); // also persistent connection with id ''
27+
$sentinel = new RedisSentinel('127.0.0.1', 26379, 1, null, 100); // 1 sec timeout, 100ms delay between reconnection attempts.
28+
~~~
29+
30+
### Usage
31+
-----
32+
33+
* [ckquorum](#ckquorum) - Check if the current Sentinel configuration is able to reach the quorum needed to failover.
34+
* [failover](#failover) - Force a failover as if the master was not reachable.
35+
* [flushconfig](#flushconfig) - Force Sentinel to rewrite its configuration on disk.
36+
* [getMasterAddrByName](#getMasterAddrByName) - Return the ip and port number of the master with that name.
37+
* [master](#master) - Return the state and info of the specified master.
38+
* [masters](#masters) - Return a list of monitored masters and their state.
39+
* [ping](#ping) - Ping the sentinel.
40+
* [reset](#reset) - Reset all the masters with matching name.
41+
* [sentinels](#sentinels) - Return a list of sentinel instances for this master, and their state.
42+
* [slaves](#slaves) - Return a list of replicas for this master, and their state.
43+
44+
-----
45+
46+
### ckquorum
47+
-----
48+
_**Description**_: Check if the current Sentinel configuration is able to reach the quorum needed to failover a master, and the majority needed to authorize the failover. This command should be used in monitoring systems to check if a Sentinel deployment is ok.
49+
50+
##### *Parameters*
51+
*String*: master name
52+
53+
##### *Return value*
54+
*Bool*: `TRUE` in case of success, `FALSE` in case of failure.
55+
56+
##### *Example*
57+
~~~php
58+
$sentinel->ckquorum('mymaster');
59+
~~~
60+
61+
### failover
62+
-----
63+
_**Description**_: Force a failover as if the master was not reachable, and without asking for agreement to other Sentinels (however a new version of the configuration will be published so that the other Sentinels will update their configurations).
64+
65+
##### *Parameters*
66+
*String*: master name
67+
68+
##### *Return value*
69+
*Bool*: `TRUE` in case of success, `FALSE` in case of failure.
70+
71+
##### *Example*
72+
~~~php
73+
$sentinel->failover('mymaster');
74+
~~~
75+
76+
### flushconfig
77+
-----
78+
_**Description**_: Force Sentinel to rewrite its configuration on disk, including the current Sentinel state. Normally Sentinel rewrites the configuration every time something changes in its state (in the context of the subset of the state which is persisted on disk across restart). However sometimes it is possible that the configuration file is lost because of operation errors, disk failures, package upgrade scripts or configuration managers. In those cases a way to to force Sentinel to rewrite the configuration file is handy. This command works even if the previous configuration file is completely missing.
79+
80+
##### *Parameters*
81+
(none)
82+
83+
##### *Return value*
84+
*Bool*: `TRUE` in case of success, `FALSE` in case of failure.
85+
86+
##### *Example*
87+
~~~php
88+
$sentinel->flushconfig();
89+
~~~
90+
91+
### getMasterAddrByName
92+
-----
93+
_**Description**_: Return the ip and port number of the master with that name. If a failover is in progress or terminated successfully for this master it returns the address and port of the promoted replica.
94+
95+
##### *Parameters*
96+
*String*: master name
97+
98+
##### *Return value*
99+
*Array*, *Bool*: ['address', 'port'] in case of success, `FALSE` in case of failure.
100+
101+
##### *Example*
102+
~~~php
103+
$sentinel->getMasterAddrByName('mymaster');
104+
~~~
105+
106+
### master
107+
-----
108+
_**Description**_: Return the state and info of the specified master.
109+
110+
##### *Parameters*
111+
*String*: master name
112+
113+
##### *Return value*
114+
*Array*, *Bool*: Associative array with info in case of success, `FALSE` in case of failure.
115+
116+
##### *Example*
117+
~~~php
118+
$sentinel->master('mymaster');
119+
~~~
120+
121+
### masters
122+
-----
123+
_**Description**_: Return a list of monitored masters and their state.
124+
125+
##### *Parameters*
126+
(none)
127+
128+
##### *Return value*
129+
*Array*, *Bool*: List of arrays with info for each master in case of success, `FALSE` in case of failure.
130+
131+
##### *Example*
132+
~~~php
133+
$sentinel->masters();
134+
~~~
135+
136+
### ping
137+
-----
138+
_**Description**_: Ping the sentinel.
139+
140+
##### *Parameters*
141+
(none)
142+
143+
##### *Return value*
144+
*Bool*: `TRUE` in case of success, `FALSE` in case of failure.
145+
146+
##### *Example*
147+
~~~php
148+
$sentinel->ping();
149+
~~~
150+
151+
### reset
152+
-----
153+
_**Description**_: This command will reset all the masters with matching name. The pattern argument is a glob-style pattern. The reset process clears any previous state in a master (including a failover in progress), and removes every replica and sentinel already discovered and associated with the master.
154+
155+
##### *Parameters*
156+
*String*: pattern
157+
158+
##### *Return value*
159+
*Bool*: `TRUE` in case of success, `FALSE` in case of failure.
160+
161+
##### *Example*
162+
~~~php
163+
$sentinel->reset('*');
164+
~~~
165+
166+
### sentinels
167+
-----
168+
_**Description**_: Return a list of sentinel instances for this master, and their state.
169+
170+
##### *Parameters*
171+
*String*: master name
172+
173+
##### *Return value*
174+
*Array*, *Bool*: List of arrays with info for each sentinels in case of success, `FALSE` in case of failure.
175+
176+
##### *Example*
177+
~~~php
178+
$sentinel->sentinels('mymaster');
179+
~~~
180+
181+
### slaves
182+
-----
183+
_**Description**_: Return a list of replicas for this master, and their state.
184+
185+
##### *Parameters*
186+
*String*: master name
187+
188+
##### *Return value*
189+
*Array*, *Bool*: List of arrays with info for each replicas in case of success, `FALSE` in case of failure.
190+
191+
##### *Example*
192+
~~~php
193+
$sentinel->slaves('mymaster');
194+
~~~

0 commit comments

Comments
 (0)