Skip to content

marufmax/deja-vu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel - DejaVu

Laravel Redis sentinel support for High Availability ⬆️ ⬆️ 🔥

Features

  • Supports Multiple Sentinel, Slaves and Master
  • Reading to slaves and writing to master if there is instance available it will send request to that instance
  • Connection pooling by default, so there is no multiple TCP connection
  • Master and Slave Auto Discovery and random traffic passing

Installation

This package requires minimum PHP 7.2 and Laravel 7.x version. And PHPRedis according to your PHP Version.

Install PHPRedis (Skip if you have it)

Installing PHP-Pear

apt install -y php-pear

Installing Redis Client

printf "no\n" | pecl install redis

Adding Extension to php module

echo "extension=redis.so" > /etc/php/7.YOUR_PHP_VERSION/mods-available/redis.in

Symlinking with FPM and CLI

ln -sf /etc/php/7.YOUR_PHP_VERSION/mods-available/redis.ini /etc/php/7.YOUR_PHP_VERSION/fpm/conf.d/20-redis.ini
ln -sf /etc/php/7.YOUR_PHP_VERSION/mods-available/redis.ini /etc/php/7.YOUR_PHP_VERSION/cli/conf.d/20-redis.ini

Restarting PHP Service

systemctl restart php7.YOUR_PHP_VERSION-fpm.service

Installing DejaVu Package

run this command from terminal:

composer require marufmax/dejavu

Add those to your .env file:

# Redis Configuration (Use comma Separated if have multiple)
REDIS_SENTINELS=localhost,localhost
REDIS_SENTINELS_PORTS=27379,27380
REDIS_PASS=AStrongPassword

Here there is two redis sentinels server. Please put only sentinel server not any master or slaves IPs. Due to redis sentinel limitation please set same password to every host. see https://github.com/bitnami/bitnami-docker-redis-sentinel/issues/23

Quick Usages

Simply use DejaVu Facade instead of Cache Facade. Below is a very simple example

\MarufMax\DejaVu\Facades\DejaVu::put('hi', 'hello', 36);

dd(\MarufMax\DejaVu\Facades\DejaVu::get('hi'));

Thanks 🐱

About

Redis Sentinel Cache with phpredis

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages