12
12
13
13
class IcingaRedis
14
14
{
15
- /** @var static The singleton */
16
- protected static $ instance ;
17
-
18
15
/** @var Redis Connection to the Icinga Redis */
19
16
private $ redis ;
20
17
@@ -24,35 +21,30 @@ class IcingaRedis
24
21
/**
25
22
* Get the singleton
26
23
*
24
+ * @deprecated Use {@see Backend::getRedis()} instead
27
25
* @return static
28
26
*/
29
27
public static function instance (): self
30
28
{
31
- if (self ::$ instance === null ) {
32
- self ::$ instance = new static ();
33
- }
34
-
35
- return self ::$ instance ;
29
+ return Backend::getRedis ();
36
30
}
37
31
38
32
/**
39
33
* Get whether Redis is unavailable
40
34
*
41
35
* @return bool
42
36
*/
43
- public static function isUnavailable (): bool
37
+ public function isUnavailable (): bool
44
38
{
45
- $ self = self ::instance ();
46
-
47
- if (! $ self ->redisUnavailable && $ self ->redis === null ) {
39
+ if (! $ this ->redisUnavailable && $ this ->redis === null ) {
48
40
try {
49
- $ self ->getConnection ();
41
+ $ this ->getConnection ();
50
42
} catch (Exception $ _ ) {
51
43
// getConnection already logs the error
52
44
}
53
45
}
54
46
55
- return $ self ->redisUnavailable ;
47
+ return $ this ->redisUnavailable ;
56
48
}
57
49
58
50
/**
@@ -126,7 +118,7 @@ public function getConnection(): Redis
126
118
*/
127
119
public static function fetchHostState (array $ ids , array $ columns ): Generator
128
120
{
129
- return self :: fetchState ('icinga:host:state ' , $ ids , $ columns );
121
+ return Backend:: getRedis ()-> fetchState ('icinga:host:state ' , $ ids , $ columns );
130
122
}
131
123
132
124
/**
@@ -139,7 +131,7 @@ public static function fetchHostState(array $ids, array $columns): Generator
139
131
*/
140
132
public static function fetchServiceState (array $ ids , array $ columns ): Generator
141
133
{
142
- return self :: fetchState ('icinga:service:state ' , $ ids , $ columns );
134
+ return Backend:: getRedis ()-> fetchState ('icinga:service:state ' , $ ids , $ columns );
143
135
}
144
136
145
137
/**
@@ -151,10 +143,10 @@ public static function fetchServiceState(array $ids, array $columns): Generator
151
143
*
152
144
* @return Generator
153
145
*/
154
- protected static function fetchState (string $ key , array $ ids , array $ columns ): Generator
146
+ protected function fetchState (string $ key , array $ ids , array $ columns ): Generator
155
147
{
156
148
try {
157
- $ results = self :: instance () ->getConnection ()->hmget ($ key , $ ids );
149
+ $ results = $ this ->getConnection ()->hmget ($ key , $ ids );
158
150
} catch (Exception $ _ ) {
159
151
// The error has already been logged elsewhere
160
152
return ;
@@ -192,7 +184,7 @@ protected static function fetchState(string $key, array $ids, array $columns): G
192
184
public static function getLastIcingaHeartbeat (Redis $ redis = null )
193
185
{
194
186
if ($ redis === null ) {
195
- $ redis = self :: instance ()->getConnection ();
187
+ $ redis = Backend:: getRedis ()->getConnection ();
196
188
}
197
189
198
190
// Predis doesn't support streams (yet).
0 commit comments