/** * Finds a single redis record with the specified primary key. * @param mixed $pk primary key value(s). Use array for multiple primary keys. For composite key, each key value must be an array (column name=>column value). * @return ARedisRecord the record found. Null if none is found. */ public function findByPk($pk) { Yii::trace(get_class($this) . '.findByPk()', 'packages.redis.ARedisRecord'); $this->beforeFind(); $hash = new ARedisHash($this->getRedisKey($pk), $this->getRedisConnection()); if ($hash->getCount() == 0) { return null; } return $this->populateRecord($hash->toArray(), true); }
/** * Tests the basic functionality */ public function testBasics() { $redis = $this->getConnection(); $set = new ARedisHash("TestHash:" . uniqid(), $redis); $this->assertTrue($set->add("oranges", 2.4)); $this->assertTrue($set->add("apples", 1.4)); $this->assertTrue($set->add("strawberries", 3)); $this->assertEquals(3, $set->getCount()); $this->assertTrue($set->add("carrots", 0.4)); $this->assertEquals(4, $set->getCount()); $this->assertTrue($set->remove("carrots")); $this->assertFalse($set->remove("carrots")); $this->assertEquals(3, $set->getCount()); $set->clear(); $this->assertEquals(0, $set->getCount()); }