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

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dcb9/yii2-phpredis
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: nuwber/yii2-phpredis
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 4 commits
  • 15 files changed
  • 2 contributors

Commits on Jun 26, 2019

  1. phpredis >3 compatibility (#1)

    * add src path, fixes for phpredis 4, update php version, other minor fixes
    
    * update picture
    
    * fix doc, fix build
    andrew-nuwber authored Jun 26, 2019

    Unverified

    This user has not yet uploaded their public signing key.
    Copy the full SHA
    0891e0d View commit details

Commits on Jun 28, 2019

  1. Change namespace (#3)

    * chage namespace
    
    * readme minor fixes
    andrew-nuwber authored Jun 28, 2019
    Copy the full SHA
    89c34ea View commit details

Commits on Jul 13, 2021

  1. Remove ping method redifining (#4)

    * remove ping method redifining
    
    * add more php versions to ci
    
    * use github actions
    
    * add redis to ci
    
    * update phpunit, remove old php versions
    
    * more ci fixes
    
    * add badges
    andrew-nuwber authored Jul 13, 2021
    Copy the full SHA
    6739b5b View commit details
  2. update license

    andrew-nuwber committed Jul 13, 2021
    Copy the full SHA
    4629ab3 View commit details
33 changes: 33 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Build

on: [push]

jobs:
run:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.2', '7.3', '7.4', '8.0']
name: Testing on PHP ${{ matrix.php-versions }}
steps:
- uses: actions/checkout@v2
- name: setup
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: igbinary,redis
tools: composer

- name: start redis service
uses: supercharge/redis-github-action@1.2.0

- name: install deps
run: composer install -o -q

- name: phpunit
run: ./vendor/bin/phpunit --coverage-clover ./coverage.xml

- name: upload coverage report
uses: codecov/codecov-action@v1
with:
file: './coverage.xml'
28 changes: 0 additions & 28 deletions .travis.yml

This file was deleted.

47 changes: 15 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -4,40 +4,26 @@ 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?branch=master)](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)
[![Test Coverage](https://codeclimate.com/github/dcb9/yii2-phpredis/badges/coverage.svg)](https://codeclimate.com/github/dcb9/yii2-phpredis/coverage)
[![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)
[![Build](https://github.com/nuwber/yii2-phpredis/actions/workflows/build.yml/badge.svg)](https://github.com/nuwber/yii2-phpredis/actions/workflows/build.yml)
[![codecov](https://codecov.io/gh/nuwber/yii2-phpredis/branch/master/graph/badge.svg?token=87YQF09NJ4)](https://codecov.io/gh/nuwber/yii2-phpredis)

**Notice: THIS REPO DOES NOT SUPPORT ACTIVE RECORD.**

Requirements
------------

- PHP >= 5.4.0
- Redis >= 2.6.12
- ext-redis >= 2.2.7
- Yii2 ~2.0.4

Installation
------------

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist dcb9/yii2-phpredis
```bash
composer require --prefer-dist nuwber/yii2-phpredis
```

or add

```json
"dcb9/yii2-phpredis": "~1.0"
"nuwber/yii2-phpredis": "^2.0"
```

to the require section of your composer.json.
@@ -50,15 +36,20 @@ To use this extension, you have to configure the Connection class in your applic

```php
return [
//....
'components' => [
'redis' => [
'class' => 'dcb9\redis\Connection',
'class' => \nuwber\yii2redis\Connection::class,
'hostname' => 'localhost',
'port' => 6379,
'database' => 0,
],
]
'cache' => [
'class' => \nuwber\yii2redis\Cache::class,
],
'session' => [
'class' => \nuwber\yii2redis\Session::class,
],
],
];
```

@@ -67,22 +58,14 @@ Run unit test

You can specific your redis config

```
```bash
$ cp tests/config.php tests/config-local.php
$ vim tests/config-local.php
```

and Run

```
```bash
$ ./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
8 changes: 8 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
codecov:
token: ffaa516c-04a1-4cb7-960f-2e017dcc29f7
coverage:
status:
project:
default:
target: auto
threshold: 0.5
32 changes: 18 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
{
"name": "dcb9/yii2-phpredis",
"name": "nuwber/yii2-phpredis",
"description": "yii2 with phpredis",
"minimum-stability": "stable",
"license": "BSD",
"license": "BSD-3-Clause",
"authors": [
{
"name": "Bob Chengbin",
"email": "bob@phpor.me"
},
{
"name": "Andrew",
"email": "a.kl@nuwber.com"
}
],
"require": {
"yiisoft/yii2": "~2.0.4",
"ext-redis": ">=2.2.7",
"php": ">=5.4.0"
"ext-json": "*",
"yiisoft/yii2": "~2.0.14",
"ext-redis": ">=3",
"php": ">=7.2"
},
"autoload": {
"psr-4": {
"dcb9\\redis\\": ""
"nuwber\\yii2redis\\": "src/",
"nuwber\\yii2redis\\tests\\": "tests/"
}
},
"require-dev": {
"phpunit/phpunit": "<6.0",
"phpunit/phpunit": ">=8.0",
"yiisoft/yii2-redis": "^2.0"
},
"config": {
"fxp-asset": {
"vcs-driver-options": {
"github-no-api": true
},
"pattern-skip-version": "(-build|-patch)"
"repositories": [
{
"type": "composer",
"url": "https://asset-packagist.org"
}
}
]
}
Binary file modified 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.
8 changes: 3 additions & 5 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -11,10 +11,8 @@
</testsuite>
</testsuites>
<filter>
<whitelist>
<file>./Cache.php</file>
<file>./Connection.php</file>
<file>./Session.php</file>
</whitelist>
<whitelist>
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
5 changes: 2 additions & 3 deletions Cache.php → src/Cache.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace dcb9\redis;
namespace nuwber\yii2redis;

use yii\di\Instance;

@@ -23,11 +23,10 @@ class Cache extends \yii\caching\Cache
public function init()
{
parent::init();
$this->redis = Instance::ensure($this->redis, Connection::className());
$this->redis = Instance::ensure($this->redis, Connection::class);
$this->redis->open();
}


/**
* @inheritdoc
*/
23 changes: 3 additions & 20 deletions Connection.php → src/Connection.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace dcb9\redis;
namespace nuwber\yii2redis;

use Redis;
use Yii;
@@ -9,7 +9,7 @@

/**
* Class Connection
* @package dcb9\redis
* @package nuwber\yii2redis
*/
class Connection extends Redis implements Configurable
{
@@ -64,15 +64,6 @@ public function __construct($config = [])
}
}

/**
* Returns the fully qualified name of this class.
* @return string the fully qualified name of this class.
*/
public static function className()
{
return get_called_class();
}

/**
* Establishes a DB connection.
* It does nothing if a DB connection has already been established.
@@ -115,15 +106,7 @@ public function open( $host = null, $port = null, $timeout = null, $retry_interv
}
}

/**
* @return bool
*/
public function ping()
{
return parent::ping() === '+PONG';
}

public function flushdb()
public function flushdb($async = null)
{
return parent::flushDB();
}
8 changes: 4 additions & 4 deletions Session.php → src/Session.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace dcb9\redis;
namespace nuwber\yii2redis;

use yii\base\InvalidConfigException;
use Yii;
@@ -19,7 +19,7 @@
* [
* 'components' => [
* 'session' => [
* 'class' => 'dcb9\redis\Session',
* 'class' => 'nuwber\yii2redis\Session',
* 'redis' => [
* 'hostname' => 'localhost',
* 'port' => 6379,
@@ -36,7 +36,7 @@
* [
* 'components' => [
* 'session' => [
* 'class' => 'dcb9\redis\Session',
* 'class' => 'nuwber\yii2redis\Session',
* // 'redis' => 'redis' // id of the connection application component
* ],
* ],
@@ -77,7 +77,7 @@ public function init()
$this->redis = Yii::$app->get($this->redis);
} elseif (is_array($this->redis)) {
if (!isset($this->redis['class'])) {
$this->redis['class'] = Connection::className();
$this->redis['class'] = Connection::class;
}
$this->redis = Yii::createObject($this->redis);
}
13 changes: 6 additions & 7 deletions tests/CacheTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace dcb9\redis\tests;
namespace nuwber\yii2redis\tests;

use dcb9\redis\Cache;
use dcb9\redis\Connection;
use nuwber\yii2redis\Cache;
use nuwber\yii2redis\Connection;

class CacheTest extends TestCase
{
@@ -97,7 +97,7 @@ public function testMultiSet()
$this->assertEquals('v1', $cache->get('k1'));
$this->assertEquals('v2', $cache->get('k2'));
$this->assertEquals('v3', $cache->get('k3'));
sleep(1);
usleep(1100000);
$this->assertFalse($cache->get('k1'));
$this->assertFalse($cache->get('k2'));
$this->assertFalse($cache->get('k3'));
@@ -107,7 +107,6 @@ public function testMultiSet()
$this->assertFalse($cache->exists('k3'));

$cache->multiSet($items);
sleep(2);
$this->assertEquals('v1', $cache->get('k1'));
$this->assertEquals('v2', $cache->get('k2'));
$this->assertEquals('v3', $cache->get('k3'));
@@ -118,7 +117,7 @@ public function testSetGet()
$cache = $this->getCacheInstance();
$cache->set('key', 'val', 1);
$this->assertEquals('val', $cache->get('key'));
sleep(1);
usleep(1100000);
$this->assertFalse($cache->get('key'));
$this->assertFalse($cache->exists('key'));

@@ -150,7 +149,7 @@ public function testMultiAdd()
'k1' => 'v1',
], 1));
$this->assertEquals('vv55', $cache->get('k5'));
sleep(1);
usleep(1100000);
$this->assertFalse($cache->exists('k5'));
$this->assertTrue($cache->exists('k1'));
}
2 changes: 1 addition & 1 deletion tests/ConnectionTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace dcb9\redis\tests;
namespace nuwber\yii2redis\tests;

class ConnectionTest extends TestCase
{
16 changes: 9 additions & 7 deletions tests/SessionTest.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
<?php

namespace dcb9\redis\tests;
namespace nuwber\yii2redis\tests;

use dcb9\redis\Connection;
use Yii;
use nuwber\yii2redis\Connection;
use nuwber\yii2redis\Session;

class SessionTest extends TestCase
{
public function testSession()
{
$params = self::getParam();
$params['class'] = Connection::className();
$this->mockApplication([
'components' => [
'redis' => $params,
'session' => 'dcb9\\redis\\Session',
'redis' => array_merge(self::getParam(), [
'class' => Connection::class,
]),
'session' => Session::class,
]
]);

$sessionId = 'sessionId';
$session = Yii::$app->session;
$session->setTimeout(1);
$sessionData = json_encode([
'sessionId' => $sessionId,
'username' => 'bob',
]);

$session->writeSession($sessionId, $sessionData);

$this->assertEquals($sessionData, $session->readSession($sessionId));
$this->assertTrue($session->destroySession($sessionId));
$this->assertEquals('', $session->readSession($sessionId));
10 changes: 5 additions & 5 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php

namespace dcb9\redis\tests;
namespace nuwber\yii2redis\tests;

use yii\di\Container;
use yii\helpers\ArrayHelper;
use Yii;
use dcb9\redis\Connection;
use nuwber\yii2redis\Connection;

/**
* This is the base class for all yii framework unit tests.
*/
abstract class TestCase extends \PHPUnit_Framework_TestCase
abstract class TestCase extends \PHPUnit\Framework\TestCase
{
public static $params;

@@ -35,7 +35,7 @@ public static function getParam()
* Clean up after test.
* By default the application created with [[mockApplication]] will be destroyed.
*/
protected function tearDown()
protected function tearDown(): void
{
parent::tearDown();
$this->destroyApplication();
@@ -81,7 +81,7 @@ protected function destroyApplication()
Yii::$container = new Container();
}

protected function setUp()
protected function setUp(): void
{
$params = self::getParam();
if ($params === null) {
18 changes: 16 additions & 2 deletions tests/performance.php
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
$param = include(__DIR__ . '/config.php');
}

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

$app = new \yii\console\Application([
@@ -24,7 +24,7 @@
$count = 10000;
echo "phpredis run SET $count times in";
$start = microtime(true);
/* @var $phpRedis \dcb9\redis\Connection */
/* @var $phpRedis \nuwber\yii2redis\Connection */
$phpRedis = Yii::$app->phpRedis;
$phpRedis->open();
$phpRedis->flushdb();
@@ -56,3 +56,17 @@
$yiiRedis->get('yii_redis_prefix' . $i);
}
echo " " . ((microtime(true) - $start) * 1000) . " micro seconds.\n";

echo "phpredis run DEL $count times in";
$start = microtime(true);
for ($i = 0; $i < $count; $i++) {
$phpRedis->del('php_redis_prefix' . $i);
}
echo " " . ((microtime(true) - $start) * 1000) . " micro seconds.\n";

echo "yii redis run DEL $count times in";
$start = microtime(true);
for ($i = 0; $i < $count; $i++) {
$yiiRedis->del('yii_redis_prefix' . $i);
}
echo " " . ((microtime(true) - $start) * 1000) . " micro seconds.\n";