mfonte / redisw
Redis客户端实现库,基于phpredis PECL包构建。
v1.0.6
2023-10-26 16:18 UTC
Requires
- php: ^8.1
- ext-redis: >=2.2.7
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.4
- mockery/mockery: ^1.3.3
- orchestra/testbench: ^7.0
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^9.5
README
Redis包装器,基于https://github.com/phpredis/phpredis扩展。
安装
足够简单。
composer require mfonte/redisw
所需环境
- PHP >= 8.1
ext-redis
模块- 可选(但推荐) : igbinary支持以获得更好的序列化
基本用法
使用简单,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');
测试
简单地在该模块的安装目录下运行composer install
。
然后,运行composer test
以运行所有测试。
感谢
向https://github.com/alxmsl表示感谢,他基于https://github.com/alxmsl/Redis的基础实现。此包在很大程度上依赖于他的工作。
还要向https://github.com/ukko表示感谢,他的phpredis扩展自动完成功能在https://github.com/ukko/phpredis-phpdoc。多亏了他的工作,这个包更容易编写。