Skip to content

Commit

Permalink
Better compatibility with yii2-redis
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavle Lee committed Aug 26, 2017
1 parent 9720d48 commit e02d59a
Show file tree
Hide file tree
Showing 14 changed files with 236 additions and 104 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
82 changes: 0 additions & 82 deletions src/ActiveQuery.php

This file was deleted.

21 changes: 0 additions & 21 deletions src/ActiveRecord.php

This file was deleted.

33 changes: 33 additions & 0 deletions src/Command/ClientList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* User: Pavle Lee <[email protected]>
* Date: 2017/8/26
* Time: 16:29
*/

namespace pavle\yii\redis\Command;


class ClientList extends \Predis\Command\ServerClient
{
/**
* @inheritDoc
*/
public function getArguments()
{
return ['LIST'];
}


/**
* Parses the response to CLIENT LIST and returns a structured list.
*
* @param string $data Response buffer.
*
* @return string
*/
protected function parseClientList($data)
{
return $data;
}
}
33 changes: 33 additions & 0 deletions src/Command/ClientSetName.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* User: Pavle Lee <[email protected]>
* Date: 2017/8/26
* Time: 16:29
*/

namespace pavle\yii\redis\Command;


class ClientSetName extends \Predis\Command\ServerClient
{
/**
* @inheritDoc
*/
public function getArguments()
{
return array_merge(['SETNAME'], parent::getArguments());
}


/**
* Parses the response to CLIENT LIST and returns a structured list.
*
* @param string $data Response buffer.
*
* @return string
*/
protected function parseClientList($data)
{
return $data;
}
}
30 changes: 30 additions & 0 deletions src/Command/HashGetAll.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* User: Pavle Lee <[email protected]>
* Date: 2017/8/26
* Time: 16:11
*/

namespace pavle\yii\redis\Command;


use Predis\Command\Command;

class HashGetAll extends Command
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'HGETALL';
}

/**
* {@inheritdoc}
*/
public function parseResponse($data)
{
return $data;
}
}
28 changes: 27 additions & 1 deletion src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@

namespace pavle\yii\redis;

use pavle\yii\redis\Profile\RedisVersion200;
use pavle\yii\redis\Profile\RedisVersion220;
use pavle\yii\redis\Profile\RedisVersion240;
use pavle\yii\redis\Profile\RedisVersion260;
use pavle\yii\redis\Profile\RedisVersion280;
use pavle\yii\redis\Profile\RedisVersion300;
use pavle\yii\redis\Profile\RedisVersion320;
use Predis\Client;
use Predis\Profile\Factory;
use yii\db\Exception;
use yii\helpers\VarDumper;

Expand All @@ -28,6 +36,24 @@ class Connection extends \yii\redis\Connection
*/
private $_socket = false;

/**
* @inheritDoc
*/
public function init()
{
parent::init();

Factory::define('2.0', RedisVersion200::class);
Factory::define('2.2', RedisVersion220::class);
Factory::define('2.4', RedisVersion240::class);
Factory::define('2.6', RedisVersion260::class);
Factory::define('2.8', RedisVersion280::class);
Factory::define('3.0', RedisVersion300::class);
Factory::define('3.2', RedisVersion320::class);
Factory::define('dev', 'Predis\Profile\RedisUnstable');
Factory::define('default', RedisVersion320::class);
}

/**
* Returns a value indicating whether the DB connection is established.
* @return bool whether the DB connection is established
Expand Down Expand Up @@ -113,7 +139,7 @@ public function executeCommand($name, $params = [])
{
$this->open();

\Yii::trace("Executing Redis Command: {$name}", __METHOD__);
\Yii::trace("Executing Redis Command: {$name} " . join(' ', $params), __METHOD__);

return $this->_socket->executeCommand(
$this->_socket->createCommand($name, $params)
Expand Down
16 changes: 16 additions & 0 deletions src/Profile/RedisVersion200.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace pavle\yii\redis\Profile;


class RedisVersion200 extends \Predis\Profile\RedisVersion200
{
public function getSupportedCommands()
{
return array_merge(parent::getSupportedCommands(), [
'HGETALL' => 'pavle\yii\redis\Command\HashGetAll',
'CLIENT LIST' => 'pavle\yii\redis\Command\ClientList',
'CLIENT SETNAME' => 'pavle\yii\redis\Command\ClientSetName',
]);
}
}
16 changes: 16 additions & 0 deletions src/Profile/RedisVersion220.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace pavle\yii\redis\Profile;


class RedisVersion220 extends \Predis\Profile\RedisVersion220
{
public function getSupportedCommands()
{
return array_merge(parent::getSupportedCommands(), [
'HGETALL' => 'pavle\yii\redis\Command\HashGetAll',
'CLIENT LIST' => 'pavle\yii\redis\Command\ClientList',
'CLIENT SETNAME' => 'pavle\yii\redis\Command\ClientSetName',
]);
}
}
16 changes: 16 additions & 0 deletions src/Profile/RedisVersion240.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace pavle\yii\redis\Profile;


class RedisVersion240 extends \Predis\Profile\RedisVersion240
{
public function getSupportedCommands()
{
return array_merge(parent::getSupportedCommands(), [
'HGETALL' => 'pavle\yii\redis\Command\HashGetAll',
'CLIENT LIST' => 'pavle\yii\redis\Command\ClientList',
'CLIENT SETNAME' => 'pavle\yii\redis\Command\ClientSetName',
]);
}
}
16 changes: 16 additions & 0 deletions src/Profile/RedisVersion260.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace pavle\yii\redis\Profile;


class RedisVersion260 extends \Predis\Profile\RedisVersion260
{
public function getSupportedCommands()
{
return array_merge(parent::getSupportedCommands(), [
'HGETALL' => 'pavle\yii\redis\Command\HashGetAll',
'CLIENT LIST' => 'pavle\yii\redis\Command\ClientList',
'CLIENT SETNAME' => 'pavle\yii\redis\Command\ClientSetName',
]);
}
}
16 changes: 16 additions & 0 deletions src/Profile/RedisVersion280.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace pavle\yii\redis\Profile;


class RedisVersion280 extends \Predis\Profile\RedisVersion280
{
public function getSupportedCommands()
{
return array_merge(parent::getSupportedCommands(), [
'HGETALL' => 'pavle\yii\redis\Command\HashGetAll',
'CLIENT LIST' => 'pavle\yii\redis\Command\ClientList',
'CLIENT SETNAME' => 'pavle\yii\redis\Command\ClientSetName',
]);
}
}
16 changes: 16 additions & 0 deletions src/Profile/RedisVersion300.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace pavle\yii\redis\Profile;


class RedisVersion300 extends \Predis\Profile\RedisVersion300
{
public function getSupportedCommands()
{
return array_merge(parent::getSupportedCommands(), [
'HGETALL' => 'pavle\yii\redis\Command\HashGetAll',
'CLIENT LIST' => 'pavle\yii\redis\Command\ClientList',
'CLIENT SETNAME' => 'pavle\yii\redis\Command\ClientSetName',
]);
}
}
16 changes: 16 additions & 0 deletions src/Profile/RedisVersion320.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace pavle\yii\redis\Profile;


class RedisVersion320 extends \Predis\Profile\RedisVersion320
{
public function getSupportedCommands()
{
return array_merge(parent::getSupportedCommands(), [
'HGETALL' => 'pavle\yii\redis\Command\HashGetAll',
'CLIENT LIST' => 'pavle\yii\redis\Command\ClientList',
'CLIENT SETNAME' => 'pavle\yii\redis\Command\ClientSetName',
]);
}
}

0 comments on commit e02d59a

Please sign in to comment.