Welcome Guest, Not a member yet? Register   Sign In
[question] Redis cache driver thrown exeption in phpunit?
#1
Question 
(This post was last modified: 10-26-2015, 11:41 AM by feryardiant. Edit Reason: grammar )

Anyone here had experience using Redis cache driver (CI v3.0.2) and test it using PHPUnit (v4.8.16)?

I just tried it as described here and it seems works well in browser, but when I go to my terminal and try to test it using phpunit I got this:

Code:
Fatal error: Uncaught exception 'RedisException' with message 'Redis server went away' in /path/to/my-app/system/libraries/Cache/drivers/Cache_redis.php on line 317

Call Stack:
   0.0002     247008   1. {main}() /path/to/my-app/vendor/phpunit/phpunit/phpunit:0
   0.0128    1116832   2. PHPUnit_TextUI_Command::main() /path/to/my-app/vendor/phpunit/phpunit/phpunit:47
   0.0128    1117456   3. PHPUnit_TextUI_Command->run() /path/to/my-app/vendor/phpunit/phpunit/src/TextUI/Command.php:100
   0.1355    6531040   4. PHPUnit_TextUI_TestRunner->doRun() /path/to/my-app/vendor/phpunit/phpunit/src/TextUI/Command.php:149
   0.1437    6885808   5. PHPUnit_Framework_TestSuite->run() /path/to/my-app/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:440
   0.1647    7612208   6. PHPUnit_Framework_TestSuite->run() /path/to/my-app/vendor/phpunit/phpunit/src/Framework/TestSuite.php:747
   0.1704    7615816   7. PHPUnit_Framework_TestCase->run() /path/to/my-app/vendor/phpunit/phpunit/src/Framework/TestSuite.php:747
   0.1704    7616272   8. PHPUnit_Framework_TestResult->run() /path/to/my-app/vendor/phpunit/phpunit/src/Framework/TestCase.php:724
   0.1705    7617952   9. PHPUnit_Framework_TestCase->runBare() /path/to/my-app/vendor/phpunit/phpunit/src/Framework/TestResult.php:612
   0.1729    7937600  10. PHPUnit_Framework_TestCase->runTest() /path/to/my-app/vendor/phpunit/phpunit/src/Framework/TestCase.php:768
   0.1729    7938368  11. ReflectionMethod->invokeArgs() /path/to/my-app/vendor/phpunit/phpunit/src/Framework/TestCase.php:909
   0.1729    7938640  12. ControllersTest->testLoadController() /path/to/my-app/vendor/phpunit/phpunit/src/Framework/TestCase.php:909
   0.1731    7941912  13. CI_Controller->__construct() /path/to/my-app/tests/core/ControllersTest.php:33
   0.1732    7943440  14. load_class() /path/to/my-app/system/core/Controller.php:75

RedisException: Redis server went away in /path/to/my-app/system/libraries/Cache/drivers/Cache_redis.php on line 317

Here my environment:

Code:
$ redis-cli --version
redis-cli 3.0.5

$ php --version
PHP 5.6.14-1+deb.sury.org~wily+1 (cli)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
   with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
   with Xdebug v2.3.3, Copyright (c) 2002-2015, by Derick Rethans

and here my 'application/config/redis.php' file:

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

/**
 * Redis Cache Configuration
 * @link https://codeigniter.com/user_guide/libraries/caching.html#redis-caching
 */

$config['socket_type'] = 'tcp';
// $config['socket'] = '/var/run/redis.sock';
$config['host'] = '127.0.0.1';
$config['password'] = NULL;
$config['port'] = 6379;
$config['timeout'] = 0
Here My blog  Big Grin
Reply
#2

Noticed that i've repost this thread but seems still no solution yet  Undecided
Here My blog  Big Grin
Reply
#3

Hi, feryardiant.

Now I wrote like this:
Code:
// application/libraries/Cache/drivers/MY_Cache_redis.php
public function __destruct()
{
 if ($this->_redis)
 {
   try {
     $this->_redis->close();
   } catch (Exception $e) {
     // Do nothing
     // log_message('info', $e);
   }
 }
}
Reply
#4

(This post was last modified: 10-26-2015, 07:41 PM by feryardiant.)

(10-26-2015, 02:39 PM)trsw Wrote: Hi, feryardiant.

Now I wrote like this:


Code:
// application/libraries/Cache/drivers/MY_Cache_redis.php
public function __destruct()
{
 if ($this->_redis)
 {
   try {
     $this->_redis->close();
   } catch (Exception $e) {
     // Do nothing
     // log_message('info', $e);
   }
 }
}

Hi, trsw.

Thank you, it works and I really hope it will implemented by the team. Anyway, it still couldn't work with PHPunit.

Code:
Unable to locate the specified class: Cache.php

for now I can just disable it

   
Here My blog  Big Grin
Reply




Theme © iAndrew 2016 - Forum software by © MyBB