Merge pull request #57 from vus520/master

redis cache 优化
This commit is contained in:
Chino Chang
2016-05-07 15:55:20 +08:00
4 changed files with 74 additions and 36 deletions

View File

@@ -41,10 +41,23 @@ class redisTest extends cacheTestCase
$cache = $this->prepare();
$this->assertEquals('string_test', $cache->get('string_test'));
$this->assertEquals(11, $cache->get('number_test'));
$result = $cache->get('array_test');
$this->assertEquals('array_test', $result['array_test']);
}
public function testStoreSpecialValues()
{
$redis = new \think\cache\driver\Redis(['length' => 3]);
$redis->set('key', 'value');
$redis->get('key');
$redis->handler()->setnx('key', 'value');
$value = $redis->handler()->get('key');
$this->assertEquals('value', $value);
$redis->handler()->hset('hash', 'key', 'value');
$value = $redis->handler()->hget('hash', 'key');
$this->assertEquals('value', $value);
}
public function testExpire()

View File

@@ -9,13 +9,12 @@
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace tests\thinkphp\library\think\cache\driver;
/**
* Redisd缓存驱动测试
* @author 尘缘 <130775@qq.com>
*/
namespace tests\thinkphp\library\think\cache\driver;
class redisdTest extends cacheTestCase
{
private $_cacheInstance = null;
@@ -31,7 +30,7 @@ class redisdTest extends cacheTestCase
protected function getCacheInstance()
{
if (null === $this->_cacheInstance) {
$this->_cacheInstance = new \think\cache\driver\Redisd(['length' => 3]);
$this->_cacheInstance = new \think\cache\driver\Redisd();
}
return $this->_cacheInstance;
}
@@ -47,6 +46,20 @@ class redisdTest extends cacheTestCase
public function testStoreSpecialValues()
{
$redis = new \think\cache\driver\Redisd(['length' => 3]);
$redis->master(true);
$redis->handler()->setnx('key', 'value');
$value = $redis->handler()->get('key');
$this->assertEquals('value', $value);
$redis->handler()->hset('hash', 'key', 'value');
$value = $redis->handler()->hget('hash', 'key');
$this->assertEquals('value', $value);
$redis->master(true)->hset('hash', 'key', 'value');
$value = $redis->master(false)->hget('hash', 'key');
$this->assertEquals('value', $value);
}
public function testExpire()