Skip to content

Latest commit

 

History

History
71 lines (49 loc) · 2.33 KB

README.md

File metadata and controls

71 lines (49 loc) · 2.33 KB

PHP Redis Wrapper around the phpredis extension

Just another Redis Wrapper, around the https://github.com/phpredis/phpredis extension.

Latest Stable Version Total Downloads

Installation

Simple enough.

composer require mfonte/redisw

Required environment:

  1. PHP >= 8.1
  2. ext-redis module
  3. optional (but recommended) : igbinary support for better serialization

Basic Usage

Usage is simple enough with a nice, expressive API:

<?php
use Mfonte\Redisw\RedisClient as Redisw;

try {
    $client = Redisw::instance([
        'host' => '127.0.0.1', 
        'port' => 6379, 
        'connect_timeout' => 1, // optional
        'connect_tries' => 10, // optional
        'persistent' => true, // optional
        'db_index' => 1, // optional
        'cache_ttl' => 60, // optional. Defaults to 60 sec.
        'auth_password' => '', // optional
        'ssl' => '', // optional
        'key_prefix' => 'some_prefix', // optional
        'serializer' => 'ibginary', // optional. One of: igbinary, json, php
        'compression' => 'lzf', // optional. One of: lzf, zstd, lz4
    ]);

    // set a key
    $client->set('somekey', ['value', 'value', 'value']);

    // get a key
    $value = $client->get('somekey');
}
catch(\Exception $ex) {
    echo "Something got wrong: {$ex->getMessage()}";
}

// don't want exceptions while setting/getting/whatever?
$client->wrap('set', 'wont-throw-exceptions', [1, 2, 3, 4]);

$value = $client->wrap('get', 'wont-throw-exceptions');

Testing

Simply run composer install over this module's installation directory.

Then, run composer test to run all the tests.

Thank you's

A big thank you goes to https://github.com/alxmsl for his base implementation on https://github.com/alxmsl/Redis. This package heavily relies on his work.

Another big thank you goes to https://github.com/ukko for his phpredis extension autocomplete on https://github.com/ukko/phpredis-phpdoc. This package was easier to be written thanks to his work.