SentinelQueue::getConnection()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 14
rs 9.4285
cc 2
eloc 6
nc 2
nop 0
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