SentinelQueue   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 2
c 2
b 1
f 0
lcom 1
cbo 5
dl 0
loc 25
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getConnection() 0 14 2
1
<?php
2
3
namespace RedisSentinel\Laravel;
4
5
use Illuminate\Queue\RedisQueue;
6
use Illuminate\Redis\Connections\PredisConnection;
7
use Predis\Client;
8
9
class SentinelQueue extends RedisQueue
10
{
11
    /**
12
     * Get the connection for the queue.
13
     *
14
     * Since we're using sentinels and Predis does not support transactions over aggregate queries then
15
     * make sure return only the 'master' client.
16
     *
17
     * @return \Illuminate\Redis\Connections\Connection
18
     */
19
    protected function getConnection()
20
    {
21
        $connection = $this->redis->connection($this->connection);
22
23
        /** @var \Predis\ClientInterface $client */
24
        $client = $connection->client();
25
26
        if ($client instanceof Client) {
27
            // getClientFor is not in the client interface.
28
            return new PredisConnection($client->getClientFor('master'));
29
        }
30
31
        return $connection;
32
    }
33
}
34