lulco/redis-proxy

Library for Redis driver abstraction

1.2.0 2024-04-12 11:25 UTC

This package is auto-updated.

Last update: 2024-11-12 12:51:31 UTC


README

Library for creating redis instance depends on application / server possibilities

Build Status Scrutinizer Code Quality Code Coverage SensioLabsInsight Latest Stable Version Total Downloads PHP 7 ready

Installation

Composer

The fastest way to install Redis proxy is to add it to your project using Composer (http://getcomposer.org/).

  1. Install Composer:
    curl -sS https://getcomposer.org/installer | php
    
  2. Require Redis proxy as a dependency using Composer:
    php composer.phar require lulco/redis-proxy
    
  3. Install Redis proxy:
    php composer.phar update
    

Usage

Single redis node

$redis = new \RedisProxy\RedisProxy($host, $port);

// Call redis methods
$redis->select($database);
$redis->hset($key, $field, $value);
$redis->hlen($key);
$redis->hget($key, $field);
$redis->hgetall($key);
...

Sentinel

$sentinels = [
    ['host' => '172.19.0.5', 'port' => 26379],
    ['host' => '172.19.0.6', 'port' => 26379],
    ['host' => '172.19.0.7', 'port' => 26379],
];
$clusterId = 'mymaster';

$redis = new \RedisProxy\RedisProxy();
$redis->setSentinelConnectionPool($sentinels, $clusterId, $database);

// Call redis methods
$redis->hset($key, $field, $value);
$redis->hlen($key);
$redis->hget($key, $field);
$redis->hgetall($key);