|
1
|
|
|
<?php |
|
2
|
|
|
// +---------------------------------------------------------------------- |
|
|
|
|
|
|
3
|
|
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ] |
|
4
|
|
|
// +---------------------------------------------------------------------- |
|
5
|
|
|
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. |
|
6
|
|
|
// +---------------------------------------------------------------------- |
|
7
|
|
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) |
|
8
|
|
|
// +---------------------------------------------------------------------- |
|
9
|
|
|
// | Author: liu21st <[email protected]> |
|
10
|
|
|
// +---------------------------------------------------------------------- |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Redis缓存驱动测试 |
|
14
|
|
|
* @author 7IN0SAN9 <[email protected]> |
|
|
|
|
|
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
namespace tests\thinkphp\library\think\cache\driver; |
|
18
|
|
|
|
|
19
|
|
|
class redisTest extends cacheTestCase |
|
|
|
|
|
|
20
|
|
|
{ |
|
21
|
|
|
private $_cacheInstance = null; |
|
22
|
|
|
|
|
23
|
|
|
protected function setUp() |
|
|
|
|
|
|
24
|
|
|
{ |
|
25
|
|
|
if (!extension_loaded("redis")) { |
|
26
|
|
|
$this->markTestSkipped("Redis没有安装,已跳过测试!"); |
|
27
|
|
|
} |
|
28
|
|
|
\think\Cache::connect(array('type' => 'redis', 'expire' => 2)); |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
protected function getCacheInstance() |
|
|
|
|
|
|
32
|
|
|
{ |
|
33
|
|
|
if (null === $this->_cacheInstance) { |
|
34
|
|
|
$this->_cacheInstance = new \think\cache\driver\Redis(['length' => 3]); |
|
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
return $this->_cacheInstance; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testGet() |
|
|
|
|
|
|
40
|
|
|
{ |
|
41
|
|
|
$cache = $this->prepare(); |
|
42
|
|
|
$this->assertEquals('string_test', $cache->get('string_test')); |
|
43
|
|
|
$this->assertEquals(11, $cache->get('number_test')); |
|
44
|
|
|
$result = $cache->get('array_test'); |
|
45
|
|
|
$this->assertEquals('array_test', $result['array_test']); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function testStoreSpecialValues() |
|
|
|
|
|
|
49
|
|
|
{ |
|
50
|
|
|
$redis = new \think\cache\driver\Redis(['length' => 3]); |
|
51
|
|
|
$redis->set('key', 'value'); |
|
52
|
|
|
$redis->get('key'); |
|
53
|
|
|
|
|
54
|
|
|
$redis->handler()->setnx('key', 'value'); |
|
55
|
|
|
$value = $redis->handler()->get('key'); |
|
56
|
|
|
$this->assertEquals('value', $value); |
|
57
|
|
|
|
|
58
|
|
|
$redis->handler()->hset('hash', 'key', 'value'); |
|
59
|
|
|
$value = $redis->handler()->hget('hash', 'key'); |
|
60
|
|
|
$this->assertEquals('value', $value); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function testExpire() |
|
|
|
|
|
|
64
|
|
|
{ |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|