Commit 563171eb by Carsten Brandt

moved redis out of yii\db namespace

parent d8d6d1e3
<?php
/**
* Transaction class file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\db\redis;
use yii\base\InvalidConfigException;
use yii\db\Exception;
/**
* Transaction represents a DB transaction.
*
* @property boolean $isActive Whether the transaction is active. This property is read-only.
*
* @since 2.0
*/
class Transaction extends \yii\base\Object
{
/**
* @var Connection the database connection that this transaction is associated with.
*/
public $db;
/**
* @var boolean whether this transaction is active. Only an active transaction
* can [[commit()]] or [[rollBack()]]. This property is set true when the transaction is started.
*/
private $_active = false;
/**
* Returns a value indicating whether this transaction is active.
* @return boolean whether this transaction is active. Only an active transaction
* can [[commit()]] or [[rollBack()]].
*/
public function getIsActive()
{
return $this->_active;
}
/**
* Begins a transaction.
* @throws InvalidConfigException if [[connection]] is null
*/
public function begin()
{
if (!$this->_active) {
if ($this->db === null) {
throw new InvalidConfigException('Transaction::db must be set.');
}
\Yii::trace('Starting transaction', __CLASS__);
$this->db->open();
$this->db->createCommand('MULTI')->execute();
$this->_active = true;
}
}
/**
* Commits a transaction.
* @throws Exception if the transaction or the DB connection is not active.
*/
public function commit()
{
if ($this->_active && $this->db && $this->db->isActive) {
\Yii::trace('Committing transaction', __CLASS__);
$this->db->createCommand('EXEC')->execute();
// TODO handle result of EXEC
$this->_active = false;
} else {
throw new Exception('Failed to commit transaction: transaction was inactive.');
}
}
/**
* Rolls back a transaction.
* @throws Exception if the transaction or the DB connection is not active.
*/
public function rollback()
{
if ($this->_active && $this->db && $this->db->isActive) {
\Yii::trace('Rolling back transaction', __CLASS__);
$this->db->pdo->commit();
$this->_active = false;
} else {
throw new Exception('Failed to roll back transaction: transaction was inactive.');
}
}
}
To allow AR to be stored in redis we need a special Schema for it.
HSET prefix:className:primaryKey
http://redis.io/commands
Current Redis connection:
https://github.com/jamm/Memory
# Queries
wrap all these in transactions MULTI
## insert
SET all attribute key-value pairs
SET all relation key-value pairs
make sure to create back-relations
## update
SET all attribute key-value pairs
SET all relation key-value pairs
## delete
DEL all attribute key-value pairs
DEL all relation key-value pairs
make sure to update back-relations
http://redis.io/commands/hmget sounds suiteable!
\ No newline at end of file
......@@ -8,7 +8,7 @@
* @license http://www.yiiframework.com/license/
*/
namespace yii\db\redis;
namespace yii\redis;
/**
* ActiveQuery represents a DB query associated with an Active Record class.
......
......@@ -8,7 +8,7 @@
* @license http://www.yiiframework.com/license/
*/
namespace yii\db\redis;
namespace yii\redis;
use yii\base\InvalidCallException;
use yii\base\InvalidConfigException;
......@@ -70,7 +70,7 @@ abstract class ActiveRecord extends \yii\db\ActiveRecord
public static function hashPk($pk)
{
return (is_array($pk) ? implode('-', $pk) : $pk); // TODO escape PK glue
return is_array($pk) ? implode('-', $pk) : $pk; // TODO escape PK glue
}
/**
......
......@@ -8,9 +8,7 @@
* @license http://www.yiiframework.com/license/
*/
namespace yii\db\redis;
use yii\base\NotSupportedException;
namespace yii\redis;
/**
* ActiveRecord is the base class for classes representing relational data in terms of objects.
......@@ -19,7 +17,7 @@ use yii\base\NotSupportedException;
* @author Carsten Brandt <mail@cebe.cc>
* @since 2.0
*/
class ActiveRelation extends \yii\db\redis\ActiveQuery
class ActiveRelation extends \yii\redis\ActiveQuery
{
/**
* @var boolean whether this relation should populate all query results into AR instances.
......
......@@ -5,7 +5,7 @@
* @author Carsten Brandt <mail@cebe.cc>
*/
namespace yii\db\redis;
namespace yii\redis;
use yii\base\InvalidConfigException;
......
......@@ -7,7 +7,7 @@
namespace yiiunit\data\ar\redis;
use yii\db\redis\Connection;
use yii\redis\Connection;
/**
* ActiveRecord is ...
......@@ -15,7 +15,7 @@ use yii\db\redis\Connection;
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class ActiveRecord extends \yii\db\redis\ActiveRecord
class ActiveRecord extends \yii\redis\ActiveRecord
{
public static $db;
......
......@@ -2,7 +2,7 @@
namespace yiiunit\data\ar\redis;
use yii\db\redis\RecordSchema;
use yii\redis\RecordSchema;
class Customer extends ActiveRecord
{
......@@ -12,7 +12,7 @@ class Customer extends ActiveRecord
public $status2;
/**
* @return \yii\db\redis\ActiveRelation
* @return \yii\redis\ActiveRelation
*/
public function getOrders()
{
......
......@@ -2,7 +2,7 @@
namespace yiiunit\data\ar\redis;
use yii\db\redis\RecordSchema;
use yii\redis\RecordSchema;
class Item extends ActiveRecord
{
......
......@@ -2,7 +2,7 @@
namespace yiiunit\data\ar\redis;
use yii\db\redis\RecordSchema;
use yii\redis\RecordSchema;
class Order extends ActiveRecord
{
......
......@@ -2,7 +2,7 @@
namespace yiiunit\data\ar\redis;
use yii\db\redis\RecordSchema;
use yii\redis\RecordSchema;
class OrderItem extends ActiveRecord
{
......
<?php
namespace yiiunit\framework\db\redis;
namespace yiiunit\framework\redis;
use yii\db\redis\ActiveQuery;
use yii\redis\ActiveQuery;
use yiiunit\data\ar\redis\ActiveRecord;
use yiiunit\data\ar\redis\Customer;
use yiiunit\data\ar\redis\OrderItem;
......
<?php
namespace yiiunit\framework\db\redis;
namespace yiiunit\framework\redis;
use yii\db\redis\Connection;
use yii\redis\Connection;
class RedisConnectionTest extends RedisTestCase
{
......
<?php
namespace yiiunit\framework\db\redis;
namespace yiiunit\framework\redis;
use yii\db\redis\Connection;
use yii\redis\Connection;
use yiiunit\TestCase;
/**
......@@ -39,18 +39,12 @@ class RedisTestCase extends TestCase
{
$databases = $this->getParam('databases');
$params = isset($databases['redis']) ? $databases['redis'] : array();
$db = new \yii\db\redis\Connection;
$db = new Connection;
$db->dsn = $params['dsn'];
$db->password = $params['password'];
if ($reset) {
$db->open();
$db->flushall();
/* $lines = explode(';', file_get_contents($params['fixture']));
foreach ($lines as $line) {
if (trim($line) !== '') {
$db->pdo->exec($line);
}
}*/
}
return $db;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment