diff --git a/.codeclimate.yml b/.codeclimate.yml new file mode 100644 index 0000000..130915b --- /dev/null +++ b/.codeclimate.yml @@ -0,0 +1,18 @@ +--- +engines: + duplication: + enabled: true + config: + languages: + - php + fixme: + enabled: true + phpcodesniffer: + enabled: true + phpmd: + enabled: true +ratings: + paths: + - "**.php" +exclude_paths: +- tests/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..45d16c0 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,27 @@ +language: php + +php: + - '5.4' + - '5.5' + - '5.6' + - '7.0' + +services: + - redis-server + +before_install: echo "extension = redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini + +install: + - composer global require "fxp/composer-asset-plugin:^1.2.0" + - composer require codeclimate/php-test-reporter --dev + - composer install --no-progress --no-interaction + +script: + - ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml + +addons: + code_climate: + repo_token: 255db28eb13c47dff54362135d879145fc97afff3eb91d97158608818bb4d1a9 + +after_script: + - vendor/bin/test-reporter diff --git a/README.md b/README.md index 50499de..83f7f4a 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,14 @@ This extension provides the [redis](http://redis.io/) key-value store support fo It includes a `Cache` and `Session` storage handler in redis. + +[![Build Status](https://travis-ci.org/dcb9/yii2-phpredis.svg)](https://travis-ci.org/dcb9/yii2-phpredis) +[![Code Climate](https://codeclimate.com/github/dcb9/yii2-phpredis/badges/gpa.svg)](https://codeclimate.com/github/dcb9/yii2-phpredis) +[![Issue Count](https://codeclimate.com/github/dcb9/yii2-phpredis/badges/issue_count.svg)](https://codeclimate.com/github/dcb9/yii2-phpredis) +[![Latest Stable Version](https://poser.pugx.org/dcb9/yii2-phpredis/version)](https://packagist.org/packages/dcb9/yii2-phpredis) +[![Total Downloads](https://poser.pugx.org/dcb9/yii2-phpredis/downloads)](https://packagist.org/packages/dcb9/yii2-phpredis) +[![License](https://poser.pugx.org/dcb9/yii2-phpredis/license)](https://packagist.org/packages/dcb9/yii2-phpredis) + **Notice: THIS REPO DID NOT SUPPORT ACTIVE RECORD.** Requirements @@ -52,3 +60,35 @@ return [ ] ]; ``` + +Run unit test +------------- + +You can specific your redis config + +``` +$ cp tests/config.php tests/config-local.php +$ vim tests/config-local.php +``` + +and Run + +``` +$ ./vendor/bin/phpunit +PHPUnit 5.6.1 by Sebastian Bergmann and contributors. + +............ 12 / 12 (100%) + +Time: 600 ms, Memory: 10.00MB + +OK (12 tests, 50 assertions) +``` + +Performance test +------------------ + +``` +$ php tests/performance.php +``` + +![phpredis-vs-yii-redis](./phpredis-vs-yii-redis.png) diff --git a/composer.json b/composer.json index 0d49550..bdce011 100644 --- a/composer.json +++ b/composer.json @@ -11,11 +11,16 @@ ], "require": { "yiisoft/yii2": "~2.0.4", - "ext-redis": ">=2.2.7" + "ext-redis": ">=2.2.5", + "php": ">=5.4.0" }, "autoload": { "psr-4": { "dcb9\\redis\\": "" } + }, + "require-dev": { + "phpunit/phpunit": "*", + "yiisoft/yii2-redis": "^2.0" } } diff --git a/phpredis-vs-yii-redis.png b/phpredis-vs-yii-redis.png new file mode 100644 index 0000000..d977632 Binary files /dev/null and b/phpredis-vs-yii-redis.png differ diff --git a/tests/performance.php b/tests/performance.php new file mode 100644 index 0000000..02b3c79 --- /dev/null +++ b/tests/performance.php @@ -0,0 +1,58 @@ + 'test-performance-app', + 'basePath' => __DIR__, + 'vendorPath' => dirname(__DIR__) . '/vendor', + 'components' => [ + 'phpRedis' => $phpRedisConfig, + 'yiiRedis' => $yiiRedisConfig, + ], +]); + +$count = 10000; +echo "phpredis run SET $count times in"; +$start = microtime(true); +/* @var $phpRedis \dcb9\redis\Connection */ +$phpRedis = Yii::$app->phpRedis; +$phpRedis->open(); +$phpRedis->flushdb(); +for ($i = 0; $i < $count; $i++) { + $phpRedis->set('php_redis_prefix' . $i, $i); +} +echo " " . ((microtime(true) - $start) * 1000) . " micro seconds.\n"; + +echo "yii redis run SET $count times in"; +$start = microtime(true); +/* @var $yiiRedis \yii\redis\Connection */ +$yiiRedis = Yii::$app->yiiRedis; +$yiiRedis->flushdb(); +for ($i = 0; $i < $count; $i++) { + $yiiRedis->set('yii_redis_prefix' . $i, $i); +} +echo " " . ((microtime(true) - $start) * 1000) . " micro seconds.\n"; + +echo "phpredis run GET $count times in"; +$start = microtime(true); +for ($i = 0; $i < $count; $i++) { + $phpRedis->get('php_redis_prefix' . $i); +} +echo " " . ((microtime(true) - $start) * 1000) . " micro seconds.\n"; + +echo "yii redis run GET $count times in"; +$start = microtime(true); +for ($i = 0; $i < $count; $i++) { + $yiiRedis->get('yii_redis_prefix' . $i); +} +echo " " . ((microtime(true) - $start) * 1000) . " micro seconds.\n";