Just another Redis Wrapper, around the https://github.com/phpredis/phpredis extension.
Simple enough.
composer require mfonte/redisw
Required environment:
- PHP >= 8.1
ext-redis
module- optional (but recommended) : igbinary support for better serialization
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');
Simply run composer install
over this module's installation directory.
Then, run composer test
to run all the tests.
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.