From 6b494d1eefb705ae0b4bc61a4681da50b7d2d2a8 Mon Sep 17 00:00:00 2001
From: Zhao vistart <i@vistart.me>
Date: Sun, 24 Jul 2022 14:03:26 +0800
Subject: [PATCH 01/24] try Binary for pk.

---
 tests/ActiveRecordTest.php | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php
index 2013a8fd..e7606aaa 100644
--- a/tests/ActiveRecordTest.php
+++ b/tests/ActiveRecordTest.php
@@ -164,6 +164,16 @@ public function setUp()
         $orderItem->setAttributes(['order_id' => 3, 'item_id' => 2, 'quantity' => 1, 'subtotal' => 40.0], false);
         $orderItem->save(false);
 
+        $customer = new Customer();
+        $customer->setAttributes(['id' => hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fa-e77bbf73845f')), 'email' => 'user1@example.com', 'name' => 'user1', 'address' => 'address1', 'status' => 1, 'profile_id' => 1], false);
+        $customer->save(false);
+        $customer = new Customer();
+        $customer->setAttributes(['id' => hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fa-e77bbf73845f')), 'email' => 'user2@example.com', 'name' => 'user2', 'address' => 'address2', 'status' => 1, 'profile_id' => null], false);
+        $customer->save(false);
+        $customer = new Customer();
+        $customer->setAttributes(['id' => hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fa-e77bbf73845f')), 'email' => 'user3@example.com', 'name' => 'user3', 'address' => 'address3', 'status' => 2, 'profile_id' => 2], false);
+        $customer->save(false);
+
     }
 
     /**
@@ -705,4 +715,20 @@ public function testFind()
         $this->assertCount(2, $customerClass::find()->active()->all());
         $this->assertEquals(2, $customerClass::find()->active()->count());
     }
+
+    /**
+     * @group binary
+     */
+    public function testFindBinaryPk()
+    {
+        /* @var $customerClass \yii\db\ActiveRecordInterface */
+        $customerClass = $this->getCustomerClass();
+
+        // find one
+        /* @var $this TestCase|ActiveRecordTestTrait */
+        $result = $customerClass::find();
+        $this->assertInstanceOf('\\yii\\db\\ActiveQueryInterface', $result);
+        $customer = $result->one();
+        $this->assertInstanceOf($customerClass, $customer);
+    }
 }

From ecd78eba0381167e8150b0821d070ba30a698531 Mon Sep 17 00:00:00 2001
From: Zhao vistart <i@vistart.me>
Date: Sun, 24 Jul 2022 14:06:28 +0800
Subject: [PATCH 02/24] Update ActiveRecordTest.php

---
 tests/ActiveRecordTest.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php
index e7606aaa..a8cf2a45 100644
--- a/tests/ActiveRecordTest.php
+++ b/tests/ActiveRecordTest.php
@@ -728,7 +728,7 @@ public function testFindBinaryPk()
         /* @var $this TestCase|ActiveRecordTestTrait */
         $result = $customerClass::find();
         $this->assertInstanceOf('\\yii\\db\\ActiveQueryInterface', $result);
-        $customer = $result->one();
+        $customer = $result->where(['id' => hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fa-e77bbf73845f'))])->one();
         $this->assertInstanceOf($customerClass, $customer);
     }
 }

From de332f072c891999c50a613128746ea208ee57d1 Mon Sep 17 00:00:00 2001
From: Zhao vistart <i@vistart.me>
Date: Sun, 24 Jul 2022 14:13:05 +0800
Subject: [PATCH 03/24] try CustomerBinary test data active record.

---
 tests/ActiveRecordTest.php       | 14 ++++++---
 tests/data/ar/CustomerBinary.php | 51 ++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 4 deletions(-)
 create mode 100644 tests/data/ar/CustomerBinary.php

diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php
index a8cf2a45..59a18ac6 100644
--- a/tests/ActiveRecordTest.php
+++ b/tests/ActiveRecordTest.php
@@ -6,6 +6,7 @@
 use yii\redis\LuaScriptBuilder;
 use yiiunit\extensions\redis\data\ar\ActiveRecord;
 use yiiunit\extensions\redis\data\ar\Customer;
+use yiiunit\extensions\redis\data\ar\CustomerBinary;
 use yiiunit\extensions\redis\data\ar\OrderItem;
 use yiiunit\extensions\redis\data\ar\Order;
 use yiiunit\extensions\redis\data\ar\Item;
@@ -28,6 +29,11 @@ public function getCustomerClass()
         return Customer::className();
     }
 
+    public function getCustomerBinaryClass()
+    {
+        return CustomerBinary::className();
+    }
+
     /**
      * @return string
      */
@@ -164,13 +170,13 @@ public function setUp()
         $orderItem->setAttributes(['order_id' => 3, 'item_id' => 2, 'quantity' => 1, 'subtotal' => 40.0], false);
         $orderItem->save(false);
 
-        $customer = new Customer();
+        $customer = new CustomerBnary();
         $customer->setAttributes(['id' => hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fa-e77bbf73845f')), 'email' => 'user1@example.com', 'name' => 'user1', 'address' => 'address1', 'status' => 1, 'profile_id' => 1], false);
         $customer->save(false);
-        $customer = new Customer();
+        $customer = new CustomerBnary();
         $customer->setAttributes(['id' => hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fa-e77bbf73845f')), 'email' => 'user2@example.com', 'name' => 'user2', 'address' => 'address2', 'status' => 1, 'profile_id' => null], false);
         $customer->save(false);
-        $customer = new Customer();
+        $customer = new CustomerBnary();
         $customer->setAttributes(['id' => hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fa-e77bbf73845f')), 'email' => 'user3@example.com', 'name' => 'user3', 'address' => 'address3', 'status' => 2, 'profile_id' => 2], false);
         $customer->save(false);
 
@@ -722,7 +728,7 @@ public function testFind()
     public function testFindBinaryPk()
     {
         /* @var $customerClass \yii\db\ActiveRecordInterface */
-        $customerClass = $this->getCustomerClass();
+        $customerClass = $this->getCustomerBinaryClass();
 
         // find one
         /* @var $this TestCase|ActiveRecordTestTrait */
diff --git a/tests/data/ar/CustomerBinary.php b/tests/data/ar/CustomerBinary.php
new file mode 100644
index 00000000..80e0eb91
--- /dev/null
+++ b/tests/data/ar/CustomerBinary.php
@@ -0,0 +1,51 @@
+<?php
+
+namespace yiiunit\extensions\redis\data\ar;
+
+use yiiunit\extensions\redis\ActiveRecordTest;
+
+/**
+ * Customer
+ *
+ * @property int $id
+ * @property string $name
+ * @property string $email
+ * @property string $address
+ * @property int $status
+ *
+ * @method CustomerQuery findBySql($sql, $params = []) static
+ */
+class CustomerBinary extends ActiveRecord
+{
+    const STATUS_ACTIVE = 1;
+    const STATUS_INACTIVE = 2;
+
+    public $status2;
+
+    /**
+     * @inheritdoc
+     */
+    public function attributes()
+    {
+        return ['id', 'email', 'name', 'address', 'status', 'profile_id'];
+    }
+
+    /**
+     * @inheritdoc
+     */
+    public function afterSave($insert, $changedAttributes)
+    {
+        ActiveRecordTest::$afterSaveInsert = $insert;
+        ActiveRecordTest::$afterSaveNewRecord = $this->isNewRecord;
+        parent::afterSave($insert, $changedAttributes);
+    }
+
+    /**
+     * @inheritdoc
+     * @return CustomerQuery
+     */
+    public static function find()
+    {
+        return new CustomerQuery(get_called_class());
+    }
+}

From e253216536d6fcbc8dc6055d4cbe476a43d51797 Mon Sep 17 00:00:00 2001
From: Zhao vistart <i@vistart.me>
Date: Sun, 24 Jul 2022 14:15:38 +0800
Subject: [PATCH 04/24] fix typo.

---
 tests/ActiveRecordTest.php | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php
index 59a18ac6..d23bf2f7 100644
--- a/tests/ActiveRecordTest.php
+++ b/tests/ActiveRecordTest.php
@@ -170,13 +170,13 @@ public function setUp()
         $orderItem->setAttributes(['order_id' => 3, 'item_id' => 2, 'quantity' => 1, 'subtotal' => 40.0], false);
         $orderItem->save(false);
 
-        $customer = new CustomerBnary();
+        $customer = new CustomerBinary();
         $customer->setAttributes(['id' => hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fa-e77bbf73845f')), 'email' => 'user1@example.com', 'name' => 'user1', 'address' => 'address1', 'status' => 1, 'profile_id' => 1], false);
         $customer->save(false);
-        $customer = new CustomerBnary();
+        $customer = new CustomerBinary();
         $customer->setAttributes(['id' => hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fa-e77bbf73845f')), 'email' => 'user2@example.com', 'name' => 'user2', 'address' => 'address2', 'status' => 1, 'profile_id' => null], false);
         $customer->save(false);
-        $customer = new CustomerBnary();
+        $customer = new CustomerBinary();
         $customer->setAttributes(['id' => hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fa-e77bbf73845f')), 'email' => 'user3@example.com', 'name' => 'user3', 'address' => 'address3', 'status' => 2, 'profile_id' => 2], false);
         $customer->save(false);
 

From 8219cefae3b93ce9248ed347ce3e917ee3b193e6 Mon Sep 17 00:00:00 2001
From: Zhao vistart <i@vistart.me>
Date: Sun, 24 Jul 2022 14:23:25 +0800
Subject: [PATCH 05/24] try CustomerBinaryQuery.

---
 tests/data/ar/CustomerBinary.php      |  6 +++---
 tests/data/ar/CustomerBinaryQuery.php | 21 +++++++++++++++++++++
 2 files changed, 24 insertions(+), 3 deletions(-)
 create mode 100644 tests/data/ar/CustomerBinaryQuery.php

diff --git a/tests/data/ar/CustomerBinary.php b/tests/data/ar/CustomerBinary.php
index 80e0eb91..c65438ff 100644
--- a/tests/data/ar/CustomerBinary.php
+++ b/tests/data/ar/CustomerBinary.php
@@ -5,7 +5,7 @@
 use yiiunit\extensions\redis\ActiveRecordTest;
 
 /**
- * Customer
+ * CustomerBinary
  *
  * @property int $id
  * @property string $name
@@ -42,10 +42,10 @@ public function afterSave($insert, $changedAttributes)
 
     /**
      * @inheritdoc
-     * @return CustomerQuery
+     * @return CustomerBinaryQuery
      */
     public static function find()
     {
-        return new CustomerQuery(get_called_class());
+        return new CustomerBinaryQuery(get_called_class());
     }
 }
diff --git a/tests/data/ar/CustomerBinaryQuery.php b/tests/data/ar/CustomerBinaryQuery.php
new file mode 100644
index 00000000..f2526fbf
--- /dev/null
+++ b/tests/data/ar/CustomerBinaryQuery.php
@@ -0,0 +1,21 @@
+<?php
+
+namespace yiiunit\extensions\redis\data\ar;
+
+use yii\redis\ActiveQuery;
+
+/**
+ * CustomerBinaryQuery
+ */
+class CustomerBinaryQuery extends ActiveQuery
+{
+    /**
+     * @return $this
+     */
+    public function active()
+    {
+        $this->andWhere(['status' => 1]);
+
+        return $this;
+    }
+}

From 1e733165c1f98c7189d9eb576f1fb7a90a9a1635 Mon Sep 17 00:00:00 2001
From: Zhao vistart <i@vistart.me>
Date: Sun, 24 Jul 2022 14:32:52 +0800
Subject: [PATCH 06/24] use three binary fks.

---
 src/LuaScriptBuilder.php   |  4 ++--
 tests/ActiveRecordTest.php | 20 ++++++++++++++++----
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/src/LuaScriptBuilder.php b/src/LuaScriptBuilder.php
index 17b76cc1..59e195fe 100644
--- a/src/LuaScriptBuilder.php
+++ b/src/LuaScriptBuilder.php
@@ -304,8 +304,8 @@ private function buildHashCondition($condition, &$columns)
                     $column = $this->addColumn($column, $columns);
                     $parts[] = "$column==" . $value->expression;
                 } else {
-                    $column = $this->addColumn($column, $columns);
-                    $value = $this->quoteValue($value);
+                    $column = $this->addColumn($column, $columns);var_dump($value);
+                    $value = $this->quoteValue($value);var_dump($value);
                     $parts[] = "$column==$value";
                 }
             }
diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php
index d23bf2f7..d789d780 100644
--- a/tests/ActiveRecordTest.php
+++ b/tests/ActiveRecordTest.php
@@ -20,6 +20,11 @@
 class ActiveRecordTest extends TestCase
 {
     use ActiveRecordTestTrait;
+    static $fkBinary = [
+        hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fa-e77bbf73845f')),
+        hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fb-e77bbf73845f')),
+        hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fc-e77bbf73845f')),
+    ];
 
     /**
      * @return string
@@ -171,13 +176,13 @@ public function setUp()
         $orderItem->save(false);
 
         $customer = new CustomerBinary();
-        $customer->setAttributes(['id' => hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fa-e77bbf73845f')), 'email' => 'user1@example.com', 'name' => 'user1', 'address' => 'address1', 'status' => 1, 'profile_id' => 1], false);
+        $customer->setAttributes(['id' => static::$fkBinary[0], 'email' => 'user1@example.com', 'name' => 'user1', 'address' => 'address1', 'status' => 1, 'profile_id' => 1], false);
         $customer->save(false);
         $customer = new CustomerBinary();
-        $customer->setAttributes(['id' => hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fa-e77bbf73845f')), 'email' => 'user2@example.com', 'name' => 'user2', 'address' => 'address2', 'status' => 1, 'profile_id' => null], false);
+        $customer->setAttributes(['id' => static::$fkBinary[1], 'email' => 'user2@example.com', 'name' => 'user2', 'address' => 'address2', 'status' => 1, 'profile_id' => null], false);
         $customer->save(false);
         $customer = new CustomerBinary();
-        $customer->setAttributes(['id' => hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fa-e77bbf73845f')), 'email' => 'user3@example.com', 'name' => 'user3', 'address' => 'address3', 'status' => 2, 'profile_id' => 2], false);
+        $customer->setAttributes(['id' => static::$fkBinary[2], 'email' => 'user3@example.com', 'name' => 'user3', 'address' => 'address3', 'status' => 2, 'profile_id' => 2], false);
         $customer->save(false);
 
     }
@@ -734,7 +739,14 @@ public function testFindBinaryPk()
         /* @var $this TestCase|ActiveRecordTestTrait */
         $result = $customerClass::find();
         $this->assertInstanceOf('\\yii\\db\\ActiveQueryInterface', $result);
-        $customer = $result->where(['id' => hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fa-e77bbf73845f'))])->one();
+        $customer = $result->one();
         $this->assertInstanceOf($customerClass, $customer);
+
+        // find all
+        $customers = $customerClass::find()->all();
+        $this->assertCount(3, $customers);
+        $this->assertInstanceOf($customerClass, $customers[0]);
+        $this->assertInstanceOf($customerClass, $customers[1]);
+        $this->assertInstanceOf($customerClass, $customers[2]);
     }
 }

From f0a58e44e22a6e79644f0ffc70d82ac8a3ed3ccd Mon Sep 17 00:00:00 2001
From: Zhao vistart <i@vistart.me>
Date: Sun, 24 Jul 2022 14:35:35 +0800
Subject: [PATCH 07/24] fix illegal syntax.

---
 tests/ActiveRecordTest.php | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php
index d789d780..449b656e 100644
--- a/tests/ActiveRecordTest.php
+++ b/tests/ActiveRecordTest.php
@@ -20,11 +20,9 @@
 class ActiveRecordTest extends TestCase
 {
     use ActiveRecordTestTrait;
-    static $fkBinary = [
-        hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fa-e77bbf73845f')),
-        hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fb-e77bbf73845f')),
-        hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fc-e77bbf73845f')),
-    ];
+    static $fkBinary1 = hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fa-e77bbf73845f'));
+    static $fkBinary2 = hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fb-e77bbf73845f'));
+    static $fkBinary3 = hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fc-e77bbf73845f'));
 
     /**
      * @return string
@@ -176,13 +174,13 @@ public function setUp()
         $orderItem->save(false);
 
         $customer = new CustomerBinary();
-        $customer->setAttributes(['id' => static::$fkBinary[0], 'email' => 'user1@example.com', 'name' => 'user1', 'address' => 'address1', 'status' => 1, 'profile_id' => 1], false);
+        $customer->setAttributes(['id' => static::$fkBinary1, 'email' => 'user1@example.com', 'name' => 'user1', 'address' => 'address1', 'status' => 1, 'profile_id' => 1], false);
         $customer->save(false);
         $customer = new CustomerBinary();
-        $customer->setAttributes(['id' => static::$fkBinary[1], 'email' => 'user2@example.com', 'name' => 'user2', 'address' => 'address2', 'status' => 1, 'profile_id' => null], false);
+        $customer->setAttributes(['id' => static::$fkBinary2, 'email' => 'user2@example.com', 'name' => 'user2', 'address' => 'address2', 'status' => 1, 'profile_id' => null], false);
         $customer->save(false);
         $customer = new CustomerBinary();
-        $customer->setAttributes(['id' => static::$fkBinary[2], 'email' => 'user3@example.com', 'name' => 'user3', 'address' => 'address3', 'status' => 2, 'profile_id' => 2], false);
+        $customer->setAttributes(['id' => static::$fkBinary3, 'email' => 'user3@example.com', 'name' => 'user3', 'address' => 'address3', 'status' => 2, 'profile_id' => 2], false);
         $customer->save(false);
 
     }

From af6526629f763566e82faa9a3d5b13cd1c662abd Mon Sep 17 00:00:00 2001
From: Zhao vistart <i@vistart.me>
Date: Sun, 24 Jul 2022 14:39:16 +0800
Subject: [PATCH 08/24] fix illegal syntax.

---
 tests/ActiveRecordTest.php | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php
index 449b656e..7b3ee020 100644
--- a/tests/ActiveRecordTest.php
+++ b/tests/ActiveRecordTest.php
@@ -20,9 +20,9 @@
 class ActiveRecordTest extends TestCase
 {
     use ActiveRecordTestTrait;
-    static $fkBinary1 = hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fa-e77bbf73845f'));
-    static $fkBinary2 = hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fb-e77bbf73845f'));
-    static $fkBinary3 = hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fc-e77bbf73845f'));
+    public $fkBinary1;
+    public $fkBinary2;
+    public $fkBinary3;
 
     /**
      * @return string
@@ -173,14 +173,17 @@ public function setUp()
         $orderItem->setAttributes(['order_id' => 3, 'item_id' => 2, 'quantity' => 1, 'subtotal' => 40.0], false);
         $orderItem->save(false);
 
+        $this->fkBinary1 = hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fa-e77bbf73845f'));
+        $this->fkBinary2 = hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fb-e77bbf73845f'));
+        $this->fkBinary3 = hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fc-e77bbf73845f'));
         $customer = new CustomerBinary();
-        $customer->setAttributes(['id' => static::$fkBinary1, 'email' => 'user1@example.com', 'name' => 'user1', 'address' => 'address1', 'status' => 1, 'profile_id' => 1], false);
+        $customer->setAttributes(['id' => $this->fkBinary1, 'email' => 'user1@example.com', 'name' => 'user1', 'address' => 'address1', 'status' => 1, 'profile_id' => 1], false);
         $customer->save(false);
         $customer = new CustomerBinary();
-        $customer->setAttributes(['id' => static::$fkBinary2, 'email' => 'user2@example.com', 'name' => 'user2', 'address' => 'address2', 'status' => 1, 'profile_id' => null], false);
+        $customer->setAttributes(['id' => $this->fkBinary2, 'email' => 'user2@example.com', 'name' => 'user2', 'address' => 'address2', 'status' => 1, 'profile_id' => null], false);
         $customer->save(false);
         $customer = new CustomerBinary();
-        $customer->setAttributes(['id' => static::$fkBinary3, 'email' => 'user3@example.com', 'name' => 'user3', 'address' => 'address3', 'status' => 2, 'profile_id' => 2], false);
+        $customer->setAttributes(['id' => $this->fkBinary3, 'email' => 'user3@example.com', 'name' => 'user3', 'address' => 'address3', 'status' => 2, 'profile_id' => 2], false);
         $customer->save(false);
 
     }

From 699bc2e2e5a831bd228b587ddd79ca4dc9d4a62b Mon Sep 17 00:00:00 2001
From: Zhao vistart <i@vistart.me>
Date: Sun, 24 Jul 2022 14:43:52 +0800
Subject: [PATCH 09/24] try new primaryKey guid.

---
 tests/ActiveRecordTest.php       | 6 +++---
 tests/data/ar/CustomerBinary.php | 7 ++++++-
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php
index 7b3ee020..079b1c9c 100644
--- a/tests/ActiveRecordTest.php
+++ b/tests/ActiveRecordTest.php
@@ -177,13 +177,13 @@ public function setUp()
         $this->fkBinary2 = hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fb-e77bbf73845f'));
         $this->fkBinary3 = hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fc-e77bbf73845f'));
         $customer = new CustomerBinary();
-        $customer->setAttributes(['id' => $this->fkBinary1, 'email' => 'user1@example.com', 'name' => 'user1', 'address' => 'address1', 'status' => 1, 'profile_id' => 1], false);
+        $customer->setAttributes(['guid' => $this->fkBinary1, 'email' => 'user1@example.com', 'name' => 'user1', 'address' => 'address1', 'status' => 1, 'profile_id' => 1], false);
         $customer->save(false);
         $customer = new CustomerBinary();
-        $customer->setAttributes(['id' => $this->fkBinary2, 'email' => 'user2@example.com', 'name' => 'user2', 'address' => 'address2', 'status' => 1, 'profile_id' => null], false);
+        $customer->setAttributes(['guid' => $this->fkBinary2, 'email' => 'user2@example.com', 'name' => 'user2', 'address' => 'address2', 'status' => 1, 'profile_id' => null], false);
         $customer->save(false);
         $customer = new CustomerBinary();
-        $customer->setAttributes(['id' => $this->fkBinary3, 'email' => 'user3@example.com', 'name' => 'user3', 'address' => 'address3', 'status' => 2, 'profile_id' => 2], false);
+        $customer->setAttributes(['guid' => $this->fkBinary3, 'email' => 'user3@example.com', 'name' => 'user3', 'address' => 'address3', 'status' => 2, 'profile_id' => 2], false);
         $customer->save(false);
 
     }
diff --git a/tests/data/ar/CustomerBinary.php b/tests/data/ar/CustomerBinary.php
index c65438ff..7781f4ba 100644
--- a/tests/data/ar/CustomerBinary.php
+++ b/tests/data/ar/CustomerBinary.php
@@ -27,7 +27,12 @@ class CustomerBinary extends ActiveRecord
      */
     public function attributes()
     {
-        return ['id', 'email', 'name', 'address', 'status', 'profile_id'];
+        return ['id', 'guid', 'email', 'name', 'address', 'status', 'profile_id'];
+    }
+
+    public static function primaryKey()
+    {
+        return 'guid';
     }
 
     /**

From 0f4b935f87af4f06bc8d9f00920f812c36660052 Mon Sep 17 00:00:00 2001
From: Zhao vistart <i@vistart.me>
Date: Sun, 24 Jul 2022 14:45:48 +0800
Subject: [PATCH 10/24] fix illegal usage for primaryKey().

---
 tests/data/ar/CustomerBinary.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/data/ar/CustomerBinary.php b/tests/data/ar/CustomerBinary.php
index 7781f4ba..5df91ff2 100644
--- a/tests/data/ar/CustomerBinary.php
+++ b/tests/data/ar/CustomerBinary.php
@@ -32,7 +32,7 @@ public function attributes()
 
     public static function primaryKey()
     {
-        return 'guid';
+        return ['guid'];
     }
 
     /**

From d8068fe4ea69e3c1da91ecc8c2b6c029ed42060d Mon Sep 17 00:00:00 2001
From: Zhao vistart <i@vistart.me>
Date: Sun, 24 Jul 2022 15:07:50 +0800
Subject: [PATCH 11/24] switch to use guid.

---
 tests/ActiveRecordTest.php       | 4 ++--
 tests/data/ar/CustomerBinary.php | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php
index 079b1c9c..b73f904c 100644
--- a/tests/ActiveRecordTest.php
+++ b/tests/ActiveRecordTest.php
@@ -176,8 +176,8 @@ public function setUp()
         $this->fkBinary1 = hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fa-e77bbf73845f'));
         $this->fkBinary2 = hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fb-e77bbf73845f'));
         $this->fkBinary3 = hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fc-e77bbf73845f'));
-        $customer = new CustomerBinary();
-        $customer->setAttributes(['guid' => $this->fkBinary1, 'email' => 'user1@example.com', 'name' => 'user1', 'address' => 'address1', 'status' => 1, 'profile_id' => 1], false);
+        $customer = new CustomerBinary();var_dump($customer->attributes);
+        $customer->setAttributes(['guid' => $this->fkBinary1, 'email' => 'user1@example.com', 'name' => 'user1', 'address' => 'address1', 'status' => 1, 'profile_id' => 1], false);var_dump($customer->attributes);
         $customer->save(false);
         $customer = new CustomerBinary();
         $customer->setAttributes(['guid' => $this->fkBinary2, 'email' => 'user2@example.com', 'name' => 'user2', 'address' => 'address2', 'status' => 1, 'profile_id' => null], false);
diff --git a/tests/data/ar/CustomerBinary.php b/tests/data/ar/CustomerBinary.php
index 5df91ff2..34a1b143 100644
--- a/tests/data/ar/CustomerBinary.php
+++ b/tests/data/ar/CustomerBinary.php
@@ -27,7 +27,7 @@ class CustomerBinary extends ActiveRecord
      */
     public function attributes()
     {
-        return ['id', 'guid', 'email', 'name', 'address', 'status', 'profile_id'];
+        return ['guid', 'email', 'name', 'address', 'status', 'profile_id'];
     }
 
     public static function primaryKey()

From a0bb87d0decf45afd6de32339537abea3d6a28b6 Mon Sep 17 00:00:00 2001
From: Zhao vistart <i@vistart.me>
Date: Sun, 24 Jul 2022 15:12:33 +0800
Subject: [PATCH 12/24] only test binary.

---
 .github/workflows/build.yml    | 2 +-
 .github/workflows/ci-redis.yml | 4 ++--
 src/LuaScriptBuilder.php       | 4 ++--
 tests/ActiveRecordTest.php     | 4 ++--
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 81bb8a45..658712a1 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -57,4 +57,4 @@ jobs:
         run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader
 
       - name: Run Redis tests with PhpUnit
-        run: vendor/bin/phpunit --coverage-clover=coverage.clover
+        run: vendor/bin/phpunit --group binary --coverage-clover=coverage.clover
diff --git a/.github/workflows/ci-redis.yml b/.github/workflows/ci-redis.yml
index 7517670c..b7c1c047 100644
--- a/.github/workflows/ci-redis.yml
+++ b/.github/workflows/ci-redis.yml
@@ -56,11 +56,11 @@ jobs:
 
       - name: Run Redis 5 tests with PhpUnit
         if: matrix.redis == '5'
-        run: vendor/bin/phpunit
+        run: vendor/bin/phpunit --group binary 
 
       - name: Run Redis 6 tests with PhpUnit and coverage
         if: matrix.redis == '6'
-        run: vendor/bin/phpunit --coverage-clover=coverage.clover
+        run: vendor/bin/phpunit --group binary  --coverage-clover=coverage.clover
 
       - name: Code coverage
         if: matrix.redis == '6'
diff --git a/src/LuaScriptBuilder.php b/src/LuaScriptBuilder.php
index 59e195fe..17b76cc1 100644
--- a/src/LuaScriptBuilder.php
+++ b/src/LuaScriptBuilder.php
@@ -304,8 +304,8 @@ private function buildHashCondition($condition, &$columns)
                     $column = $this->addColumn($column, $columns);
                     $parts[] = "$column==" . $value->expression;
                 } else {
-                    $column = $this->addColumn($column, $columns);var_dump($value);
-                    $value = $this->quoteValue($value);var_dump($value);
+                    $column = $this->addColumn($column, $columns);
+                    $value = $this->quoteValue($value);
                     $parts[] = "$column==$value";
                 }
             }
diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php
index b73f904c..079b1c9c 100644
--- a/tests/ActiveRecordTest.php
+++ b/tests/ActiveRecordTest.php
@@ -176,8 +176,8 @@ public function setUp()
         $this->fkBinary1 = hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fa-e77bbf73845f'));
         $this->fkBinary2 = hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fb-e77bbf73845f'));
         $this->fkBinary3 = hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fc-e77bbf73845f'));
-        $customer = new CustomerBinary();var_dump($customer->attributes);
-        $customer->setAttributes(['guid' => $this->fkBinary1, 'email' => 'user1@example.com', 'name' => 'user1', 'address' => 'address1', 'status' => 1, 'profile_id' => 1], false);var_dump($customer->attributes);
+        $customer = new CustomerBinary();
+        $customer->setAttributes(['guid' => $this->fkBinary1, 'email' => 'user1@example.com', 'name' => 'user1', 'address' => 'address1', 'status' => 1, 'profile_id' => 1], false);
         $customer->save(false);
         $customer = new CustomerBinary();
         $customer->setAttributes(['guid' => $this->fkBinary2, 'email' => 'user2@example.com', 'name' => 'user2', 'address' => 'address2', 'status' => 1, 'profile_id' => null], false);

From 953abe45891e7f79c4f96b61a666a2ad3ac883f0 Mon Sep 17 00:00:00 2001
From: Zhao vistart <i@vistart.me>
Date: Sun, 24 Jul 2022 15:29:46 +0800
Subject: [PATCH 13/24] change bad case guid.

---
 tests/ActiveRecordTest.php | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php
index 079b1c9c..1560fa4b 100644
--- a/tests/ActiveRecordTest.php
+++ b/tests/ActiveRecordTest.php
@@ -173,9 +173,9 @@ public function setUp()
         $orderItem->setAttributes(['order_id' => 3, 'item_id' => 2, 'quantity' => 1, 'subtotal' => 40.0], false);
         $orderItem->save(false);
 
-        $this->fkBinary1 = hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fa-e77bbf73845f'));
-        $this->fkBinary2 = hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fb-e77bbf73845f'));
-        $this->fkBinary3 = hex2bin(str_replace([' ', '-'], '', 'febf943f-15f9-cf2d-88fc-e77bbf73845f'));
+        $this->fkBinary1 = hex2bin(str_replace([' ', '-'], '', '51a4e62e-1b1a-56c9-e9e5-9efe21f55276'));
+        $this->fkBinary2 = hex2bin(str_replace([' ', '-'], '', '51a4e62e-1b1a-56c9-e9e6-9efe21f55276'));
+        $this->fkBinary3 = hex2bin(str_replace([' ', '-'], '', '51a4e62e-1b1a-56c9-e9e7-9efe21f55276'));
         $customer = new CustomerBinary();
         $customer->setAttributes(['guid' => $this->fkBinary1, 'email' => 'user1@example.com', 'name' => 'user1', 'address' => 'address1', 'status' => 1, 'profile_id' => 1], false);
         $customer->save(false);

From de1fa47811ff245739145ff0e8fa13e188e71f60 Mon Sep 17 00:00:00 2001
From: Zhao vistart <i@vistart.me>
Date: Sun, 24 Jul 2022 16:32:14 +0800
Subject: [PATCH 14/24] try findOne().

---
 tests/ActiveRecordTest.php | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php
index 1560fa4b..e5636e63 100644
--- a/tests/ActiveRecordTest.php
+++ b/tests/ActiveRecordTest.php
@@ -749,5 +749,10 @@ public function testFindBinaryPk()
         $this->assertInstanceOf($customerClass, $customers[0]);
         $this->assertInstanceOf($customerClass, $customers[1]);
         $this->assertInstanceOf($customerClass, $customers[2]);
+
+        // find by a single primary key
+        $customer = $customerClass::findOne($this->fkBinary2);
+        $this->assertInstanceOf($customerClass, $customer);
+        $this->assertEquals('user2', $customer->name);
     }
 }

From 91aae567e03d937358d1a0276262fe0ead27980d Mon Sep 17 00:00:00 2001
From: Zhao vistart <i@vistart.me>
Date: Sun, 24 Jul 2022 16:35:26 +0800
Subject: [PATCH 15/24] show quoteValue detail.

---
 src/LuaScriptBuilder.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/LuaScriptBuilder.php b/src/LuaScriptBuilder.php
index 17b76cc1..59d50b93 100644
--- a/src/LuaScriptBuilder.php
+++ b/src/LuaScriptBuilder.php
@@ -304,8 +304,8 @@ private function buildHashCondition($condition, &$columns)
                     $column = $this->addColumn($column, $columns);
                     $parts[] = "$column==" . $value->expression;
                 } else {
-                    $column = $this->addColumn($column, $columns);
-                    $value = $this->quoteValue($value);
+                    $column = $this->addColumn($column, $columns);var_dump(bin2hex($value));
+                    $value = $this->quoteValue($value);var_dump(bin2head($value));
                     $parts[] = "$column==$value";
                 }
             }

From 11fb264941b89d851843b166c84c4afef67ced7a Mon Sep 17 00:00:00 2001
From: Zhao vistart <i@vistart.me>
Date: Sun, 24 Jul 2022 16:37:20 +0800
Subject: [PATCH 16/24] show quoteValue detail.

---
 src/LuaScriptBuilder.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/LuaScriptBuilder.php b/src/LuaScriptBuilder.php
index 59d50b93..e519bbbe 100644
--- a/src/LuaScriptBuilder.php
+++ b/src/LuaScriptBuilder.php
@@ -291,7 +291,7 @@ public function buildCondition($condition, &$columns)
     private function buildHashCondition($condition, &$columns)
     {
         $parts = [];
-        foreach ($condition as $column => $value) {
+        foreach ($condition as $column => $value) {var_dump($value);
             if (is_array($value)) { // IN condition
                 $parts[] = $this->buildInCondition('in', [$column, $value], $columns);
             } else {

From a919fb6ab5994e8f1eac971fec4087e6c0465960 Mon Sep 17 00:00:00 2001
From: Zhao vistart <i@vistart.me>
Date: Sun, 24 Jul 2022 16:51:21 +0800
Subject: [PATCH 17/24] try find()->andWhere().

---
 src/LuaScriptBuilder.php   | 2 +-
 tests/ActiveRecordTest.php | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/LuaScriptBuilder.php b/src/LuaScriptBuilder.php
index e519bbbe..59d50b93 100644
--- a/src/LuaScriptBuilder.php
+++ b/src/LuaScriptBuilder.php
@@ -291,7 +291,7 @@ public function buildCondition($condition, &$columns)
     private function buildHashCondition($condition, &$columns)
     {
         $parts = [];
-        foreach ($condition as $column => $value) {var_dump($value);
+        foreach ($condition as $column => $value) {
             if (is_array($value)) { // IN condition
                 $parts[] = $this->buildInCondition('in', [$column, $value], $columns);
             } else {
diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php
index e5636e63..f2fb827c 100644
--- a/tests/ActiveRecordTest.php
+++ b/tests/ActiveRecordTest.php
@@ -754,5 +754,9 @@ public function testFindBinaryPk()
         $customer = $customerClass::findOne($this->fkBinary2);
         $this->assertInstanceOf($customerClass, $customer);
         $this->assertEquals('user2', $customer->name);
+
+        $customer = $customerClass::find()->andWhere(['guid' => $this->fkBinary1])->one();
+        $this->assertInstanceOf($customerClass, $customer);
+        $this->assertEquals('user1', $customer->name);
     }
 }

From 44bdb5cf794120c8a0180a7cb41a94b84ffff0cb Mon Sep 17 00:00:00 2001
From: Zhao vistart <i@vistart.me>
Date: Sun, 24 Jul 2022 18:21:19 +0800
Subject: [PATCH 18/24] Update LuaScriptBuilder.php

---
 src/LuaScriptBuilder.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/LuaScriptBuilder.php b/src/LuaScriptBuilder.php
index 59d50b93..88515aa3 100644
--- a/src/LuaScriptBuilder.php
+++ b/src/LuaScriptBuilder.php
@@ -250,7 +250,7 @@ private function quoteValue($str)
      * @throws \yii\base\NotSupportedException if the condition is not an array
      */
     public function buildCondition($condition, &$columns)
-    {
+    {var_dump($condition, $columns);
         static $builders = [
             'not' => 'buildNotCondition',
             'and' => 'buildAndCondition',
@@ -305,7 +305,7 @@ private function buildHashCondition($condition, &$columns)
                     $parts[] = "$column==" . $value->expression;
                 } else {
                     $column = $this->addColumn($column, $columns);var_dump(bin2hex($value));
-                    $value = $this->quoteValue($value);var_dump(bin2head($value));
+                    $value = $this->quoteValue($value);var_dump(bin2hex($value));
                     $parts[] = "$column==$value";
                 }
             }

From 0c26145c3e3d19ef6ffcf093f4c396edc84ac6a0 Mon Sep 17 00:00:00 2001
From: Zhao vistart <i@vistart.me>
Date: Sun, 24 Jul 2022 18:24:21 +0800
Subject: [PATCH 19/24] try show executeScript().

---
 src/ActiveQuery.php      | 2 +-
 src/LuaScriptBuilder.php | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/ActiveQuery.php b/src/ActiveQuery.php
index a580538c..74c1c6b4 100644
--- a/src/ActiveQuery.php
+++ b/src/ActiveQuery.php
@@ -364,7 +364,7 @@ public function scalar($attribute, $db = null)
      * @return array|bool|null|string
      */
     protected function executeScript($db, $type, $columnName = null)
-    {
+    {var_dump($db, $type, $columnName);
         if ($this->primaryModel !== null) {
             // lazy loading
             if ($this->via instanceof self) {
diff --git a/src/LuaScriptBuilder.php b/src/LuaScriptBuilder.php
index 88515aa3..788ceb15 100644
--- a/src/LuaScriptBuilder.php
+++ b/src/LuaScriptBuilder.php
@@ -250,7 +250,7 @@ private function quoteValue($str)
      * @throws \yii\base\NotSupportedException if the condition is not an array
      */
     public function buildCondition($condition, &$columns)
-    {var_dump($condition, $columns);
+    {
         static $builders = [
             'not' => 'buildNotCondition',
             'and' => 'buildAndCondition',

From a1e2b15d6095e6c9a91cbd56839de7e16965f052 Mon Sep 17 00:00:00 2001
From: Zhao vistart <i@vistart.me>
Date: Mon, 25 Jul 2022 13:21:53 +0800
Subject: [PATCH 20/24] show bad case.

---
 src/ActiveQuery.php              |  2 +-
 tests/ActiveRecordTest.php       | 24 ++++++++++++------------
 tests/data/ar/CustomerBinary.php |  7 +------
 3 files changed, 14 insertions(+), 19 deletions(-)

diff --git a/src/ActiveQuery.php b/src/ActiveQuery.php
index 74c1c6b4..a580538c 100644
--- a/src/ActiveQuery.php
+++ b/src/ActiveQuery.php
@@ -364,7 +364,7 @@ public function scalar($attribute, $db = null)
      * @return array|bool|null|string
      */
     protected function executeScript($db, $type, $columnName = null)
-    {var_dump($db, $type, $columnName);
+    {
         if ($this->primaryModel !== null) {
             // lazy loading
             if ($this->via instanceof self) {
diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php
index f2fb827c..8928984d 100644
--- a/tests/ActiveRecordTest.php
+++ b/tests/ActiveRecordTest.php
@@ -738,22 +738,22 @@ public function testFindBinaryPk()
 
         // find one
         /* @var $this TestCase|ActiveRecordTestTrait */
-        $result = $customerClass::find();
-        $this->assertInstanceOf('\\yii\\db\\ActiveQueryInterface', $result);
-        $customer = $result->one();
-        $this->assertInstanceOf($customerClass, $customer);
+        //$result = $customerClass::find();
+        //$this->assertInstanceOf('\\yii\\db\\ActiveQueryInterface', $result);
+        //$customer = $result->one();
+        //$this->assertInstanceOf($customerClass, $customer);
 
         // find all
-        $customers = $customerClass::find()->all();
-        $this->assertCount(3, $customers);
-        $this->assertInstanceOf($customerClass, $customers[0]);
-        $this->assertInstanceOf($customerClass, $customers[1]);
-        $this->assertInstanceOf($customerClass, $customers[2]);
+        //$customers = $customerClass::find()->all();
+        //$this->assertCount(3, $customers);
+        //$this->assertInstanceOf($customerClass, $customers[0]);
+        //$this->assertInstanceOf($customerClass, $customers[1]);
+        //$this->assertInstanceOf($customerClass, $customers[2]);
 
         // find by a single primary key
-        $customer = $customerClass::findOne($this->fkBinary2);
-        $this->assertInstanceOf($customerClass, $customer);
-        $this->assertEquals('user2', $customer->name);
+        //$customer = $customerClass::findOne($this->fkBinary2);
+        //$this->assertInstanceOf($customerClass, $customer);
+        //$this->assertEquals('user2', $customer->name);
 
         $customer = $customerClass::find()->andWhere(['guid' => $this->fkBinary1])->one();
         $this->assertInstanceOf($customerClass, $customer);
diff --git a/tests/data/ar/CustomerBinary.php b/tests/data/ar/CustomerBinary.php
index 34a1b143..c6b5f09d 100644
--- a/tests/data/ar/CustomerBinary.php
+++ b/tests/data/ar/CustomerBinary.php
@@ -27,12 +27,7 @@ class CustomerBinary extends ActiveRecord
      */
     public function attributes()
     {
-        return ['guid', 'email', 'name', 'address', 'status', 'profile_id'];
-    }
-
-    public static function primaryKey()
-    {
-        return ['guid'];
+        return ['id', 'guid', 'email', 'name', 'address', 'status', 'profile_id'];
     }
 
     /**

From 2974951fe9cc678542415e8f3d84cce5db824ac6 Mon Sep 17 00:00:00 2001
From: Zhao vistart <i@vistart.me>
Date: Mon, 25 Jul 2022 16:25:15 +0800
Subject: [PATCH 21/24] try to solve #291.

---
 .github/workflows/build.yml      |  2 +-
 .github/workflows/ci-redis.yml   |  4 +-
 src/LuaScriptBuilder.php         |  6 +--
 tests/ActiveRecordTest.php       | 66 ++++++++++++++++++++++++--------
 tests/data/ar/CustomerBinary.php |  7 +++-
 5 files changed, 61 insertions(+), 24 deletions(-)

diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 658712a1..81bb8a45 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -57,4 +57,4 @@ jobs:
         run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader
 
       - name: Run Redis tests with PhpUnit
-        run: vendor/bin/phpunit --group binary --coverage-clover=coverage.clover
+        run: vendor/bin/phpunit --coverage-clover=coverage.clover
diff --git a/.github/workflows/ci-redis.yml b/.github/workflows/ci-redis.yml
index b7c1c047..7517670c 100644
--- a/.github/workflows/ci-redis.yml
+++ b/.github/workflows/ci-redis.yml
@@ -56,11 +56,11 @@ jobs:
 
       - name: Run Redis 5 tests with PhpUnit
         if: matrix.redis == '5'
-        run: vendor/bin/phpunit --group binary 
+        run: vendor/bin/phpunit
 
       - name: Run Redis 6 tests with PhpUnit and coverage
         if: matrix.redis == '6'
-        run: vendor/bin/phpunit --group binary  --coverage-clover=coverage.clover
+        run: vendor/bin/phpunit --coverage-clover=coverage.clover
 
       - name: Code coverage
         if: matrix.redis == '6'
diff --git a/src/LuaScriptBuilder.php b/src/LuaScriptBuilder.php
index 788ceb15..1f92d2f2 100644
--- a/src/LuaScriptBuilder.php
+++ b/src/LuaScriptBuilder.php
@@ -237,7 +237,7 @@ private function quoteValue($str)
             return $str;
         }
 
-        return "'" . addcslashes($str, "\000\n\r\\\032\047") . "'";
+        return "'" . addcslashes($str, "\000\n\r\\\047") . "'";
     }
 
     /**
@@ -304,8 +304,8 @@ private function buildHashCondition($condition, &$columns)
                     $column = $this->addColumn($column, $columns);
                     $parts[] = "$column==" . $value->expression;
                 } else {
-                    $column = $this->addColumn($column, $columns);var_dump(bin2hex($value));
-                    $value = $this->quoteValue($value);var_dump(bin2hex($value));
+                    $column = $this->addColumn($column, $columns);
+                    $value = $this->quoteValue($value);
                     $parts[] = "$column==$value";
                 }
             }
diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php
index 8928984d..de22c3f7 100644
--- a/tests/ActiveRecordTest.php
+++ b/tests/ActiveRecordTest.php
@@ -23,6 +23,8 @@ class ActiveRecordTest extends TestCase
     public $fkBinary1;
     public $fkBinary2;
     public $fkBinary3;
+    public $userBinary;
+    public $fkBinaryNonExist;
 
     /**
      * @return string
@@ -176,14 +178,16 @@ public function setUp()
         $this->fkBinary1 = hex2bin(str_replace([' ', '-'], '', '51a4e62e-1b1a-56c9-e9e5-9efe21f55276'));
         $this->fkBinary2 = hex2bin(str_replace([' ', '-'], '', '51a4e62e-1b1a-56c9-e9e6-9efe21f55276'));
         $this->fkBinary3 = hex2bin(str_replace([' ', '-'], '', '51a4e62e-1b1a-56c9-e9e7-9efe21f55276'));
+        $this->userBinary = hex2bin(str_replace([' ', '-'], '', '51a4e62e-1b1a-56c9-e9e5-9efe21f55277'));
+        $this->fkBinaryNonExist = hex2bin(str_replace([' ', '-'], '', '51a4e62e-1b1a-56c9-e9e5-9efe21f55278'));
         $customer = new CustomerBinary();
-        $customer->setAttributes(['guid' => $this->fkBinary1, 'email' => 'user1@example.com', 'name' => 'user1', 'address' => 'address1', 'status' => 1, 'profile_id' => 1], false);
+        $customer->setAttributes(['guid' => $this->fkBinary1, 'user_guid' => $this->userBinary, 'email' => 'user1@example.com', 'name' => 'user1', 'address' => 'address1', 'status' => 1, 'profile_id' => 1], false);
         $customer->save(false);
         $customer = new CustomerBinary();
-        $customer->setAttributes(['guid' => $this->fkBinary2, 'email' => 'user2@example.com', 'name' => 'user2', 'address' => 'address2', 'status' => 1, 'profile_id' => null], false);
+        $customer->setAttributes(['guid' => $this->fkBinary2, 'user_guid' => $this->userBinary, 'email' => 'user2@example.com', 'name' => 'user2', 'address' => 'address2', 'status' => 1, 'profile_id' => null], false);
         $customer->save(false);
         $customer = new CustomerBinary();
-        $customer->setAttributes(['guid' => $this->fkBinary3, 'email' => 'user3@example.com', 'name' => 'user3', 'address' => 'address3', 'status' => 2, 'profile_id' => 2], false);
+        $customer->setAttributes(['guid' => $this->fkBinary3, 'user_guid' => $this->userBinary, 'email' => 'user3@example.com', 'name' => 'user3', 'address' => 'address3', 'status' => 2, 'profile_id' => 2], false);
         $customer->save(false);
 
     }
@@ -738,25 +742,53 @@ public function testFindBinaryPk()
 
         // find one
         /* @var $this TestCase|ActiveRecordTestTrait */
-        //$result = $customerClass::find();
-        //$this->assertInstanceOf('\\yii\\db\\ActiveQueryInterface', $result);
-        //$customer = $result->one();
-        //$this->assertInstanceOf($customerClass, $customer);
+        $result = $customerClass::find();
+        $this->assertInstanceOf('\\yii\\db\\ActiveQueryInterface', $result);
+        $customer = $result->one();
+        $this->assertInstanceOf($customerClass, $customer);
 
         // find all
-        //$customers = $customerClass::find()->all();
-        //$this->assertCount(3, $customers);
-        //$this->assertInstanceOf($customerClass, $customers[0]);
-        //$this->assertInstanceOf($customerClass, $customers[1]);
-        //$this->assertInstanceOf($customerClass, $customers[2]);
+        $customers = $customerClass::find()->all();
+        $this->assertCount(3, $customers);
+        $this->assertInstanceOf($customerClass, $customers[0]);
+        $this->assertInstanceOf($customerClass, $customers[1]);
+        $this->assertInstanceOf($customerClass, $customers[2]);
 
         // find by a single primary key
-        //$customer = $customerClass::findOne($this->fkBinary2);
-        //$this->assertInstanceOf($customerClass, $customer);
-        //$this->assertEquals('user2', $customer->name);
-
-        $customer = $customerClass::find()->andWhere(['guid' => $this->fkBinary1])->one();
+        $customer = $customerClass::findOne($this->fkBinary1);
         $this->assertInstanceOf($customerClass, $customer);
         $this->assertEquals('user1', $customer->name);
+        $customer = $customerClass::findOne($this->fkBinaryNonExist);
+        $this->assertNull($customer);
+        $customer = $customerClass::findOne(['guid' => [$this->fkBinary1, $this->fkBinaryNonExist]]);
+        $this->assertInstanceOf($customerClass, $customer);
+        $customer = $customerClass::find()->where(['guid' => [$this->fkBinary1, $this->fkBinaryNonExist]])->one();
+        $this->assertNotNull($customer);
+
+        // find by column values
+        $customer = $customerClass::findOne(['guid' => $this->fkBinary2, 'name' => 'user2']);
+        $this->assertInstanceOf($customerClass, $customer);
+        $this->assertEquals('user2', $customer->name);
+        $customer = $customerClass::findOne(['guid' => $this->fkBinary2, 'name' => 'user1']);
+        $this->assertNull($customer);
+        $customer = $customerClass::findOne(['guid' => $this->fkBinaryNonExist]);
+        $this->assertNull($customer);
+        $customer = $customerClass::findOne(['name' => 'user5']);
+        $this->assertNull($customer);
+        $customer = $customerClass::findOne(['user_guid' => $this->userBinary]);
+        $this->assertInstanceOf($customerClass, $customer);
+
+        // find by attributes
+        $customer = $customerClass::find()->where(['name' => 'user2'])->one();
+        $this->assertInstanceOf($customerClass, $customer);
+        $this->assertEquals($this->fkBinary2, $customer->guid);
+        $customer = $customerClass::find()->where(['user_guid' => $this->userBinary])->one();
+        $this->assertInstanceOf($customerClass, $customer);
+
+        // scope
+        $this->assertCount(2, $customerClass::find()->active()->all());
+        $this->assertEquals(2, $customerClass::find()->active()->count());
+        $this->assertCount(3, $customerClass::find()->where(['user_guid' => $this->userBinary])->all());
+        $this->assertEquals(3, $customerClass::find()->where(['user_guid' => $this->userBinary])->count());
     }
 }
diff --git a/tests/data/ar/CustomerBinary.php b/tests/data/ar/CustomerBinary.php
index c6b5f09d..8afb1c61 100644
--- a/tests/data/ar/CustomerBinary.php
+++ b/tests/data/ar/CustomerBinary.php
@@ -27,7 +27,12 @@ class CustomerBinary extends ActiveRecord
      */
     public function attributes()
     {
-        return ['id', 'guid', 'email', 'name', 'address', 'status', 'profile_id'];
+        return ['guid', 'user_guid', 'email', 'name', 'address', 'status', 'profile_id'];
+    }
+
+    public static function primaryKey()
+    {
+        return ['guid'];
     }
 
     /**

From e577c2a115feccfe97a62763825c8c092e0618c2 Mon Sep 17 00:00:00 2001
From: Zhao vistart <i@vistart.me>
Date: Mon, 25 Jul 2022 16:29:19 +0800
Subject: [PATCH 22/24] try to solve #251 and fix typo.

---
 tests/data/ar/CustomerBinary.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/data/ar/CustomerBinary.php b/tests/data/ar/CustomerBinary.php
index 8afb1c61..d4900c4b 100644
--- a/tests/data/ar/CustomerBinary.php
+++ b/tests/data/ar/CustomerBinary.php
@@ -13,7 +13,7 @@
  * @property string $address
  * @property int $status
  *
- * @method CustomerQuery findBySql($sql, $params = []) static
+ * @method CustomerBinaryQuery findBySql($sql, $params = []) static
  */
 class CustomerBinary extends ActiveRecord
 {

From e8c73ad1d92fe122a43d45327e01d013b7a40fd1 Mon Sep 17 00:00:00 2001
From: Zhao vistart <i@vistart.me>
Date: Mon, 25 Jul 2022 17:14:24 +0800
Subject: [PATCH 23/24] Improve annotations and attributes.

---
 tests/data/ar/CustomerBinary.php | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tests/data/ar/CustomerBinary.php b/tests/data/ar/CustomerBinary.php
index d4900c4b..78f80582 100644
--- a/tests/data/ar/CustomerBinary.php
+++ b/tests/data/ar/CustomerBinary.php
@@ -7,9 +7,10 @@
 /**
  * CustomerBinary
  *
- * @property int $id
- * @property string $name
+ * @property string $guid
+ * @property string $user_guid
  * @property string $email
+ * @property string $name
  * @property string $address
  * @property int $status
  *
@@ -27,7 +28,7 @@ class CustomerBinary extends ActiveRecord
      */
     public function attributes()
     {
-        return ['guid', 'user_guid', 'email', 'name', 'address', 'status', 'profile_id'];
+        return ['guid', 'user_guid', 'email', 'name', 'address', 'status'];
     }
 
     public static function primaryKey()

From 6c68afbd9234a90529dba841b5e5450c22571afa Mon Sep 17 00:00:00 2001
From: Zhao vistart <i@vistart.me>
Date: Sun, 5 Feb 2023 11:50:03 +0800
Subject: [PATCH 24/24] add  a line for CHANGELOG.

---
 CHANGELOG.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index b8931a78..5503b0a9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,7 +4,7 @@ Yii Framework 2 redis extension Change Log
 2.0.19 under development
 ------------------------
 
-- no changes in this release.
+- Bug #251: Fixed string escaping issue of `\032` in LuaScriptBuilder (vistart)
 
 
 2.0.18 September 04, 2022