1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
namespace yiiunit\extensions\redis;
/**
* @group redis
*/
class RedisConnectionTest extends RedisTestCase
{
/**
* test connection to redis and selection of db
*/
public function testConnect()
{
$db = $this->getConnection(false);
$db->open();
$this->assertTrue($db->ping());
$db->set('YIITESTKEY', 'YIITESTVALUE');
$db->close();
$db = $this->getConnection(false);
$db->database = 0;
$db->open();
$this->assertEquals('YIITESTVALUE', $db->get('YIITESTKEY'));
$db->close();
$db = $this->getConnection(false);
$db->database = 1;
$db->open();
$this->assertNull($db->get('YIITESTKEY'));
$db->close();
}
public function keyValueData()
{
return [
[123],
[-123],
[0],
['test'],
["test\r\ntest"],
[''],
];
}
/**
* @dataProvider keyValueData
*/
public function testStoreGet($data)
{
$db = $this->getConnection(true);
$db->set('hi', $data);
$this->assertEquals($data, $db->get('hi'));
}
/**
* https://github.com/yiisoft/yii2/issues/4745
*/
public function testReturnType()
{
$redis = $this->getConnection();
$redis->executeCommand('SET',['key1','val1']);
$redis->executeCommand('HMSET',['hash1','hk3','hv3','hk4','hv4']);
$redis->executeCommand('RPUSH',['newlist2','tgtgt','tgtt','44',11]);
$redis->executeCommand('SADD',['newset2','segtggttval','sv1','sv2','sv3']);
$redis->executeCommand('ZADD',['newz2',2,'ss',3,'pfpf']);
$allKeys = $redis->executeCommand('KEYS',['*']);
sort($allKeys);
$this->assertEquals(['hash1', 'key1', 'newlist2', 'newset2', 'newz2'], $allKeys);
$expected = [
'hash1' => 'hash',
'key1' => 'string',
'newlist2' => 'list',
'newset2' => 'set',
'newz2' => 'zset',
];
foreach($allKeys as $key) {
$this->assertEquals($expected[$key], $redis->executeCommand('TYPE',[$key]));
}
}
}