コード例 #1
0
 /**
  * @return \yii\web\Response
  */
 public function actionRemfield()
 {
     $model = new RedisItem();
     $model->scenario = 'remfield';
     if ($model->load(\Yii::$app->request->get()) && $model->validate()) {
         $model->remfield();
     }
     $model->findValue();
     return $model->type ? $this->renderAjax('form_' . $model->type, compact('model')) : $this->redirect(['view', 'key' => urldecode($model->key)]);
 }
コード例 #2
0
 public function testRemfield()
 {
     $model = new RedisItem();
     $model->scenario = 'remfield';
     $model->setAttributes(['key' => 'tfx_hashlong']);
     $this->assertFalse($model->validate());
     $model = new RedisItem();
     $model->setAttributes(['key' => 'tfx_abyrvalg', 'field' => 'pararam']);
     $this->assertFalse($model->validate());
     $model = new RedisItem();
     $model->scenario = 'remfield';
     $model->setAttributes(['key' => 'tfx_hashlong', 'field' => 'pararam']);
     $this->assertTrue($model->validate());
     $model->remfield();
     $model = new RedisItem();
     $model->scenario = 'remfield';
     $model->setAttributes(['key' => urlencode('tfx_hashlong'), 'field' => Html::encode('pararam')]);
     $this->assertTrue($model->validate());
     $model->remfield();
     $model = new RedisItem();
     $model->scenario = 'remfield';
     $model->setAttributes(['key' => 'tfx_hashlong', 'field' => 'hashfield3']);
     $this->assertTrue($model->validate());
     $model->remfield();
     $this->assertEquals(0, $this->module->executeCommand('HEXISTS', ['tfx_hashlong', 'hashfield3']));
     $stress = $this->module->executeCommand('HKEYS', ['stress:hash']);
     Debug::debug($this->module->executeCommand('HGETALL', ['stress:hash']));
     foreach ($stress as $sfield) {
         Debug::debug($sfield);
         $model = new RedisItem();
         $model->scenario = 'remfield';
         $model->setAttributes(['key' => urlencode('stress:hash'), 'field' => Html::encode($sfield)]);
         $this->assertTrue($model->validate());
         $model->remfield();
         $this->assertEquals(0, $this->module->executeCommand('HEXISTS', ['stress:hash', $sfield]));
     }
     Debug::debug($this->module->executeCommand('HGETALL', ['stress:hash']));
     $this->assertEquals(3, $this->module->executeCommand('ZCARD', ['tfx_zset']));
     $model = new RedisItem();
     $model->scenario = 'remfield';
     $model->setAttributes(['key' => urlencode('tfx_zset'), 'field' => Html::encode('someval2')]);
     $this->assertTrue($model->validate());
     $model->remfield();
     $this->assertEquals(2, $this->module->executeCommand('ZCARD', ['tfx_zset']));
 }