Skip to content
This repository has been archived by the owner on Aug 15, 2018. It is now read-only.

Commit

Permalink
Add docs, travis and codeclimate
Browse files Browse the repository at this point in the history
  • Loading branch information
dcb9 committed Oct 17, 2016
1 parent 25589cd commit b5eb7b9
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 1 deletion.
18 changes: 18 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -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/
27 changes: 27 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

**<font color="red">Notice: THIS REPO DID NOT SUPPORT ACTIVE RECORD.</font>**

Requirements
Expand Down Expand Up @@ -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)
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Binary file added phpredis-vs-yii-redis.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions tests/performance.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

include __DIR__ . "/bootstrap.php";

if (file_exists(__DIR__ . '/config-local.php')) {
$param = include(__DIR__ . '/config-local.php');
} else {
$param = include(__DIR__ . '/config.php');
}

$phpRedisConfig = $param['class'] = 'dcb9\redis\Connection';
$yiiRedisConfig = $param['class'] = 'yii\redis\Connection';

$app = new \yii\console\Application([
'id' => '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";

0 comments on commit b5eb7b9

Please sign in to comment.