Skip to content

Commit

Permalink
Merge commit '09d22b99f9800bcc53773776686155006f31c265'
Browse files Browse the repository at this point in the history
  • Loading branch information
huangzhhui committed Nov 21, 2018
2 parents 29b7e81 + 61469f2 commit f89a166
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 57 deletions.
4 changes: 4 additions & 0 deletions src/AbstractRedisConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ protected function initRedis()
$error = sprintf('Redis connection authentication failed host=%s port=%d auth=%s', $host, (int)$port, (string)$config['auth']);
throw new RedisException($error);
}
if (isset($config['database']) && $config['database'] < 16 && false === $redis->select($config['database'])) {
$error = sprintf('Redis selection database failure host=%s port=%d database=%d', $host, (int)$port, (int)$config['database']);
throw new RedisException($error);
}

return $redis;
}
Expand Down
5 changes: 1 addition & 4 deletions src/Operator/Hashes/HashGetAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ public function getId()
*/
public function parseResponse($data)
{
if ($data === false) {
return false;
}
$result = array();

$result = [];
for ($i = 0; $i < count($data); ++$i) {
$result[$data[$i]] = $data[++$i];
}
Expand Down
6 changes: 1 addition & 5 deletions src/Operator/Hashes/HashGetMultiple.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,10 @@ public function getId()
*/
public function parseResponse($data)
{
if ($data === false) {
return false;
}

$result = [];
$hashKeys = $this->getArgument(1);
foreach ($data as $key => $value) {
if (!isset($hashKeys[$key])) {
if (! isset($hashKeys[$key])) {
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Operator/Keys/KeyPreciseExpire.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
class KeyPreciseExpire extends Command
{
/**
* [Keys] pexpire
* [Keys] pexipre
*
* @return string
*/
public function getId()
{
return 'pexpire';
return 'pexipre';
}
}
1 change: 0 additions & 1 deletion src/Operator/Processor/PrefixProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ public function init()
'ZADD' => 'static::first',
'ZINCRBY' => 'static::first',
'ZREM' => 'static::first',
'ZDELETE' => 'static::first',
'ZRANGE' => 'static::first',
'ZREVRANGE' => 'static::first',
'ZRANGEBYSCORE' => 'static::first',
Expand Down
3 changes: 3 additions & 0 deletions src/Pool/RedisPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public function createConnection(): ConnectionInterface
$redis = new SyncRedisConnection($this);
}

$dbIndex = $this->poolConfig->getDb();
$redis->select($dbIndex);

return $redis;
}
}
4 changes: 0 additions & 4 deletions src/RedisConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ public function createConnection()
{
$redis = $this->initRedis();
$this->connection = $redis;

/** @var RedisPoolConfig $config */
$config = $this->getPool()->getPoolConfig();
$redis->select($config->getDb());
}

/**
Expand Down
4 changes: 0 additions & 4 deletions src/SyncRedisConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ public function createConnection()
$redis->setOption(\Redis::OPT_PREFIX, $prefix);
}
$this->connection = $redis;

/** @var RedisPoolConfig $config */
$config = $this->getPool()->getPoolConfig();
$redis->select($config->getDb());
}

/**
Expand Down
24 changes: 0 additions & 24 deletions test/Cases/HashTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,6 @@ public function testHmsetAndHmget()
];
$values = $this->redis->hMGet($key, ['NotExistKey', 'NotExistKey2']);
$this->assertEquals($data, $values);

$this->redis->set($key, 'xxxxx');
$result = $this->redis->hMGet($key,['key']);
$this->assertFalse($result);

$this->redis->delete($key);
$result = $this->redis->hMGet($key, ['key']);
$this->assertEquals(['key' => false], $result);

$this->redis->sAdd($key, 'xxxxx');
$result = $this->redis->hMGet($key, ['key']);
$this->assertFalse($result);
}

public function testHmsetAndHmgetByCo()
Expand All @@ -55,18 +43,6 @@ public function testHGetAll()

$result = $this->redis->hGetAll($key);
$this->assertEquals(['key' => 'value', 'key2' => 'value2', 'key3' => 'value3'], $result);

$this->redis->set($key, 'xxxxx');
$result = $this->redis->hGetAll($key);
$this->assertFalse($result);

$this->redis->delete($key);
$result = $this->redis->hGetAll($key);
$this->assertEquals([], $result);

$this->redis->sAdd($key, 'xxxxx');
$result = $this->redis->hGetAll($key);
$this->assertFalse($result);
}

public function testHGetAllByCo()
Expand Down
13 changes: 0 additions & 13 deletions test/Cases/PoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Swoft\App;
use Swoft\Redis\Exception\RedisException;
use Swoft\Redis\Redis;
use SwoftTest\Redis\Pool\RedisEnvPoolConfig;
use SwoftTest\Redis\Pool\RedisPptPoolConfig;
use SwoftTest\Redis\Testing\Clients\TimeoutRedis;
Expand Down Expand Up @@ -74,16 +73,4 @@ public function testRedisTimeout()
});

}

public function testRedisReconnectSelectDb()
{
$redis = bean(Redis::class);
$redis->set('test_select_db', 1);

$redis->reconnect();

$res = $redis->get('test_select_db');

$this->assertEquals(1, $res);
}
}

0 comments on commit f89a166

Please sign in to comment.