2017 © Pedro Peláez
 

yii2-extension yii2-redis-ha

Basic redis-ha client

image

pyurin/yii2-redis-ha

Basic redis-ha client

  • Tuesday, November 14, 2017
  • by pyurin
  • Repository
  • 3 Watchers
  • 13 Stars
  • 7,664 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 7 Forks
  • 0 Open issues
  • 7 Versions
  • 6 % Grown

The README.md

Client for redis Highly Available set for Yii2

This Yii2 component is based on core yii2-redis component https://github.com/yiisoft/yii2-redis but gives ability to work with master-slave redis clusters with sentiels.
It's rather simple - gets master server address from given sentinels and connects to it, then operates just like \yii\redis\Connection.
It works with sentinels only, does not connect to redis hosts without sentinels.
, (*1)

Workflow of connection process

Loop over given sentinels and search for an alive one that will give a master host address.
If a sentinel does not respond or it's respond is empty, then we'll try to check the next one.
If no successfull reply was received, then connection will fail.
After we've found a redis master, we'll connect to it.
If connection to the master server fails, we won't try anything else, we'll fail.
If we sucessfully connect to the master server, we'll then check with role command if it really is master (http://redis.io/topics/sentinel-clients).
If it's not - we'll fail, if it really is - we're sucessfully connected.
, (*2)

Adviced configuration

Redis HA cluster must be done with minimum 2 redis servers and 3 sentinels.
I suppose that in termes of performance, considering this implementation it's better to have a sentinel server for each app locally, to avoid unnecessary overheads.
That would not be important if we cached previously givem master server, but we dont. We ask sentinel each time before connecting to redis.
That's how I see a simple architecture:, (*3)

    -------                    -------
   |       |                  |       |
   | Redis |                  | Redis |
   |       |                  |       |
    ------- \                 /-------
       |     \               /   |
       |      \             /    |
       |       \-----------/     |
       |       |\         /|     |
       |       |  Sentinel |     |
       |       |   .    .  |     |
       |        --.------.-      |
       |         .        .      |
       |        .          .     |
  -----|-------.---        -.----|----------     
 |     |      .    |      |  .   |          |    
 |    Sentinel. . .| . . .|. . Sentinel     |    
 |         |       |      |         |       |    
 |  (localhost)    |      |  (localhost)    |    
 |         |       |      |         |       |    
 |         |       |      |         |       |    
 |        APP      |      |        APP      |    
 |                 |      |                 |    
  -----------------        -----------------     

Usage

Basic example: ``` 'session' => [ 'class' => '\yii\redis\Session', 'redis' => [ 'class' => '\pyurin\yii\redisHa\Connection', 'masterName' => 'mymaster', 'sentinels' => [ 'localhost' ] ] ],, (*4)

Sentinel servers are queried in the same order as exist in array.<br />

Installation
=============================================
Available with composer:

"require" : { "pyurin/yii2-redis-ha":"*" }, ```, (*5)

The Versions

14/11 2017

dev-master

9999999-dev

Basic redis-ha client

  Sources   Download

BSD-3-Clause

The Requires

 

by Petr Yurin

yii2 redis sentinel

14/11 2017

1.2

1.2.0.0

Basic redis-ha client

  Sources   Download

BSD-3-Clause

The Requires

 

by Petr Yurin

yii2 redis sentinel

13/07 2015

1.1.6

1.1.6.0

Basic redis-ha client

  Sources   Download

BSD-3-Clause

The Requires

 

by Petr Yurin

yii2 redis sentinel

02/05 2015

1.1.5

1.1.5.0

Basic redis-ha client

  Sources   Download

BSD-3-Clause

The Requires

 

by Petr Yurin

yii2 redis sentinel

05/03 2015

1.1.3

1.1.3.0

Basic redis-ha client

  Sources   Download

BSD-3-Clause

The Requires

 

by Petr Yurin

yii2 redis sentinel

03/03 2015

1.1.2

1.1.2.0

Basic redis-ha client

  Sources   Download

BSD-3-Clause

The Requires

 

by Petr Yurin

yii2 redis sentinel

01/03 2015

1.1.0

1.1.0.0

Basic redis-ha client

  Sources   Download

BSD-3-Clause

The Requires

 

by Petr Yurin

yii2 redis sentinel