marufmax/deja-vu

Caching with redis sentinal, master and slave. Supports PHPRedis client

1.0.1 2020-08-17 05:25 UTC

This package is auto-updated.

Last update: 2024-04-24 04:35:48 UTC


README

dejavu.svg

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 🐱