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
f3aa807d
Commit
f3aa807d
authored
Sep 25, 2013
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ensure atomicity of operations
parent
c6c164dc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
8 deletions
+13
-8
ActiveRecord.php
framework/yii/redis/ActiveRecord.php
+13
-8
No files found.
framework/yii/redis/ActiveRecord.php
View file @
f3aa807d
...
...
@@ -7,7 +7,6 @@
namespace
yii\redis
;
use
yii\base\InvalidCallException
;
use
yii\base\InvalidConfigException
;
use
yii\base\NotSupportedException
;
use
yii\db\TableSchema
;
...
...
@@ -19,7 +18,7 @@ use yii\helpers\StringHelper;
* @author Carsten Brandt <mail@cebe.cc>
* @since 2.0
*/
abstract
class
ActiveRecord
extends
\yii\db\ActiveRecord
class
ActiveRecord
extends
\yii\db\ActiveRecord
{
/**
* @var array cache for TableSchema instances
...
...
@@ -81,17 +80,19 @@ abstract class ActiveRecord extends \yii\db\ActiveRecord
}
$newPk
=
static
::
buildKey
(
$newPk
);
$newKey
=
static
::
tableName
()
.
':a:'
.
$newPk
;
$db
->
executeCommand
(
'HMSET'
,
$args
);
// rename index
// rename index if pk changed
if
(
$newPk
!=
$pk
)
{
// TODO make this atomic
$db
->
executeCommand
(
'MULTI'
);
$db
->
executeCommand
(
'HMSET'
,
$args
);
$db
->
executeCommand
(
'LINSERT'
,
array
(
static
::
tableName
(),
'AFTER'
,
$pk
,
$newPk
));
$db
->
executeCommand
(
'LREM'
,
array
(
static
::
tableName
(),
0
,
$pk
));
$db
->
executeCommand
(
'RENAME'
,
array
(
$key
,
$newKey
));
$db
->
executeCommand
(
'EXEC'
);
}
else
{
$db
->
executeCommand
(
'HMSET'
,
$args
);
}
$n
++
;
}
return
$n
;
}
...
...
@@ -143,7 +144,9 @@ abstract class ActiveRecord extends \yii\db\ActiveRecord
{
$db
=
static
::
getDb
();
$attributeKeys
=
array
();
foreach
(
static
::
fetchPks
(
$condition
)
as
$pk
)
{
$pks
=
static
::
fetchPks
(
$condition
);
$db
->
executeCommand
(
'MULTI'
);
foreach
(
$pks
as
$pk
)
{
$pk
=
static
::
buildKey
(
$pk
);
$db
->
executeCommand
(
'LREM'
,
array
(
static
::
tableName
(),
0
,
$pk
));
$attributeKeys
[]
=
static
::
tableName
()
.
':a:'
.
$pk
;
...
...
@@ -151,7 +154,9 @@ abstract class ActiveRecord extends \yii\db\ActiveRecord
if
(
empty
(
$attributeKeys
))
{
return
0
;
}
return
$db
->
executeCommand
(
'DEL'
,
$attributeKeys
);
// TODO make this atomic or document as NOT
$db
->
executeCommand
(
'DEL'
,
$attributeKeys
);
$result
=
$db
->
executeCommand
(
'EXEC'
);
return
end
(
$result
);
}
private
static
function
fetchPks
(
$condition
)
...
...
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