From 7e0c6353f761f11f9e11e46583e733763ee63ccd Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Mon, 22 Sep 2014 18:57:21 +0200 Subject: [PATCH] optimized redis AR insert --- extensions/redis/ActiveRecord.php | 8 +------- extensions/redis/CHANGELOG.md | 1 + 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/extensions/redis/ActiveRecord.php b/extensions/redis/ActiveRecord.php index 734e5a6..3a4129d 100644 --- a/extensions/redis/ActiveRecord.php +++ b/extensions/redis/ActiveRecord.php @@ -120,16 +120,14 @@ class ActiveRecord extends BaseActiveRecord $key = static::keyPrefix() . ':a:' . static::buildKey($pk); // save attributes $setArgs = [$key]; - $delArgs = [$key]; foreach ($values as $attribute => $value) { + // only insert attributes that are not null if ($value !== null) { if (is_bool($value)) { $value = (int)$value; } $setArgs[] = $attribute; $setArgs[] = $value; - } else { - $delArgs[] = $attribute; } } @@ -137,10 +135,6 @@ class ActiveRecord extends BaseActiveRecord $db->executeCommand('HMSET', $setArgs); } - if (count($delArgs) > 1) { - $db->executeCommand('HDEL', $delArgs); - } - $changedAttributes = array_fill_keys(array_keys($values), null); $this->setOldAttributes($values); $this->afterSave(true, $changedAttributes); diff --git a/extensions/redis/CHANGELOG.md b/extensions/redis/CHANGELOG.md index 77df7bb..da24e92 100644 --- a/extensions/redis/CHANGELOG.md +++ b/extensions/redis/CHANGELOG.md @@ -4,6 +4,7 @@ Yii Framework 2 redis extension Change Log 2.0.0-rc under development -------------------------- +- Bug #1311: Fixed storage and finding of `null` and boolean values (samdark, cebe) - Enh #3520: Added `unlinkAll()`-method to active record to remove all records of a model relation (NmDimas, samdark, cebe) - Enh #4048: Added `init` event to `ActiveQuery` classes (qiangxue) - Enh #4086: changedAttributes of afterSave Event now contain old values (dizews)