Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
563171eb
Commit
563171eb
authored
Sep 18, 2013
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved redis out of yii\db namespace
parent
d8d6d1e3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
20 additions
and
155 deletions
+20
-155
Connection.php
framework/yii/db/redis/Connection.php
+0
-0
Transaction.php
framework/yii/db/redis/Transaction.php
+0
-91
schema.md
framework/yii/db/redis/schema.md
+0
-36
ActiveQuery.php
framework/yii/redis/ActiveQuery.php
+1
-1
ActiveRecord.php
framework/yii/redis/ActiveRecord.php
+2
-2
ActiveRelation.php
framework/yii/redis/ActiveRelation.php
+2
-4
RecordSchema.php
framework/yii/redis/RecordSchema.php
+1
-1
ActiveRecord.php
tests/unit/data/ar/redis/ActiveRecord.php
+2
-2
Customer.php
tests/unit/data/ar/redis/Customer.php
+2
-2
Item.php
tests/unit/data/ar/redis/Item.php
+1
-1
Order.php
tests/unit/data/ar/redis/Order.php
+1
-1
OrderItem.php
tests/unit/data/ar/redis/OrderItem.php
+1
-1
ActiveRecordTest.php
tests/unit/framework/redis/ActiveRecordTest.php
+2
-2
RedisConnectionTest.php
tests/unit/framework/redis/RedisConnectionTest.php
+2
-2
RedisTestCase.php
tests/unit/framework/redis/RedisTestCase.php
+3
-9
No files found.
framework/yii/db/redis/Connection.php
deleted
100644 → 0
View file @
d8d6d1e3
This diff is collapsed.
Click to expand it.
framework/yii/db/redis/Transaction.php
deleted
100644 → 0
View file @
d8d6d1e3
<?php
/**
* Transaction class file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright © 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.'
);
}
}
}
framework/yii/db/redis/schema.md
deleted
100644 → 0
View file @
d8d6d1e3
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
framework/yii/
db/
redis/ActiveQuery.php
→
framework/yii/redis/ActiveQuery.php
View file @
563171eb
...
...
@@ -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.
...
...
framework/yii/
db/
redis/ActiveRecord.php
→
framework/yii/redis/ActiveRecord.php
View file @
563171eb
...
...
@@ -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
}
/**
...
...
framework/yii/
db/
redis/ActiveRelation.php
→
framework/yii/redis/ActiveRelation.php
View file @
563171eb
...
...
@@ -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.
...
...
framework/yii/
db/
redis/RecordSchema.php
→
framework/yii/redis/RecordSchema.php
View file @
563171eb
...
...
@@ -5,7 +5,7 @@
* @author Carsten Brandt <mail@cebe.cc>
*/
namespace
yii\
db\
redis
;
namespace
yii\redis
;
use
yii\base\InvalidConfigException
;
...
...
tests/unit/data/ar/redis/ActiveRecord.php
View file @
563171eb
...
...
@@ -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
;
...
...
tests/unit/data/ar/redis/Customer.php
View file @
563171eb
...
...
@@ -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
()
{
...
...
tests/unit/data/ar/redis/Item.php
View file @
563171eb
...
...
@@ -2,7 +2,7 @@
namespace
yiiunit\data\ar\redis
;
use
yii\
db\
redis\RecordSchema
;
use
yii\redis\RecordSchema
;
class
Item
extends
ActiveRecord
{
...
...
tests/unit/data/ar/redis/Order.php
View file @
563171eb
...
...
@@ -2,7 +2,7 @@
namespace
yiiunit\data\ar\redis
;
use
yii\
db\
redis\RecordSchema
;
use
yii\redis\RecordSchema
;
class
Order
extends
ActiveRecord
{
...
...
tests/unit/data/ar/redis/OrderItem.php
View file @
563171eb
...
...
@@ -2,7 +2,7 @@
namespace
yiiunit\data\ar\redis
;
use
yii\
db\
redis\RecordSchema
;
use
yii\redis\RecordSchema
;
class
OrderItem
extends
ActiveRecord
{
...
...
tests/unit/framework/
db/
redis/ActiveRecordTest.php
→
tests/unit/framework/redis/ActiveRecordTest.php
View file @
563171eb
<?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
;
...
...
tests/unit/framework/
db/
redis/RedisConnectionTest.php
→
tests/unit/framework/redis/RedisConnectionTest.php
View file @
563171eb
<?php
namespace
yiiunit\framework\
db\
redis
;
namespace
yiiunit\framework\redis
;
use
yii\
db\
redis\Connection
;
use
yii\redis\Connection
;
class
RedisConnectionTest
extends
RedisTestCase
{
...
...
tests/unit/framework/
db/
redis/RedisTestCase.php
→
tests/unit/framework/redis/RedisTestCase.php
View file @
563171eb
<?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
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment