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
660fa461
Commit
660fa461
authored
Sep 07, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed storing and loading null-values in Redis
parent
9885aac0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
9 deletions
+53
-9
ActiveQuery.php
extensions/redis/ActiveQuery.php
+17
-0
ActiveRecord.php
extensions/redis/ActiveRecord.php
+36
-9
No files found.
extensions/redis/ActiveQuery.php
View file @
660fa461
...
...
@@ -123,6 +123,15 @@ class ActiveQuery extends Component implements ActiveQueryInterface
for
(
$i
=
0
;
$i
<
$c
;)
{
$row
[
$dataRow
[
$i
++
]]
=
$dataRow
[
$i
++
];
}
$class
=
$this
->
modelClass
;
$modelInstance
=
$class
::
instantiate
(
$row
);
foreach
(
$modelInstance
->
attributes
()
as
$attribute
)
{
if
(
!
isset
(
$row
[
$attribute
]))
{
$row
[
$attribute
]
=
null
;
}
}
$rows
[]
=
$row
;
}
if
(
!
empty
(
$rows
))
{
...
...
@@ -164,6 +173,14 @@ class ActiveQuery extends Component implements ActiveQueryInterface
}
if
(
$this
->
asArray
)
{
$model
=
$row
;
$class
=
$this
->
modelClass
;
$modelInstance
=
$class
::
instantiate
(
$row
);
foreach
(
$modelInstance
->
attributes
()
as
$attribute
)
{
if
(
!
isset
(
$model
[
$attribute
]))
{
$model
[
$attribute
]
=
null
;
}
}
}
else
{
/* @var $class ActiveRecord */
$class
=
$this
->
modelClass
;
...
...
extensions/redis/ActiveRecord.php
View file @
660fa461
...
...
@@ -119,12 +119,24 @@ class ActiveRecord extends BaseActiveRecord
$key
=
static
::
keyPrefix
()
.
':a:'
.
static
::
buildKey
(
$pk
);
// save attributes
$args
=
[
$key
];
$setArgs
=
[
$key
];
$delArgs
=
[
$key
];
foreach
(
$values
as
$attribute
=>
$value
)
{
$args
[]
=
$attribute
;
$args
[]
=
$value
;
if
(
$value
!==
null
)
{
$setArgs
[]
=
$attribute
;
$setArgs
[]
=
$value
;
}
else
{
$delArgs
[]
=
$attribute
;
}
}
if
(
count
(
$setArgs
)
>
1
)
{
$db
->
executeCommand
(
'HMSET'
,
$setArgs
);
}
if
(
count
(
$delArgs
)
>
1
)
{
$db
->
executeCommand
(
'HDEL'
,
$delArgs
);
}
$db
->
executeCommand
(
'HMSET'
,
$args
);
$changedAttributes
=
array_fill_keys
(
array_keys
(
$values
),
null
);
$this
->
setOldAttributes
(
$values
);
...
...
@@ -158,26 +170,41 @@ class ActiveRecord extends BaseActiveRecord
$pk
=
static
::
buildKey
(
$pk
);
$key
=
static
::
keyPrefix
()
.
':a:'
.
$pk
;
// save attributes
$args
=
[
$key
];
$delArgs
=
[
$key
];
$setArgs
=
[
$key
];
foreach
(
$attributes
as
$attribute
=>
$value
)
{
if
(
isset
(
$newPk
[
$attribute
]))
{
$newPk
[
$attribute
]
=
$value
;
}
$args
[]
=
$attribute
;
$args
[]
=
$value
;
if
(
$value
!==
null
)
{
$setArgs
[]
=
$attribute
;
$setArgs
[]
=
$value
;
}
else
{
$delArgs
[]
=
$attribute
;
}
}
$newPk
=
static
::
buildKey
(
$newPk
);
$newKey
=
static
::
keyPrefix
()
.
':a:'
.
$newPk
;
// rename index if pk changed
if
(
$newPk
!=
$pk
)
{
$db
->
executeCommand
(
'MULTI'
);
$db
->
executeCommand
(
'HMSET'
,
$args
);
if
(
count
(
$setArgs
)
>
1
)
{
$db
->
executeCommand
(
'HMSET'
,
$setArgs
);
}
if
(
count
(
$delArgs
)
>
1
)
{
$db
->
executeCommand
(
'HDEL'
,
$delArgs
);
}
$db
->
executeCommand
(
'LINSERT'
,
[
static
::
keyPrefix
(),
'AFTER'
,
$pk
,
$newPk
]);
$db
->
executeCommand
(
'LREM'
,
[
static
::
keyPrefix
(),
0
,
$pk
]);
$db
->
executeCommand
(
'RENAME'
,
[
$key
,
$newKey
]);
$db
->
executeCommand
(
'EXEC'
);
}
else
{
$db
->
executeCommand
(
'HMSET'
,
$args
);
if
(
count
(
$setArgs
)
>
1
)
{
$db
->
executeCommand
(
'HMSET'
,
$setArgs
);
}
if
(
count
(
$delArgs
)
>
1
)
{
$db
->
executeCommand
(
'HDEL'
,
$delArgs
);
}
}
$n
++
;
}
...
...
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