protected function setUp()
 {
     parent::setUp();
     $fixter = new RedisFixts();
     $fixter->createFixtures();
     $this->module = \Yii::$app->getModule('redisman');
     $this->module->setConnection('localnat', 1);
 }
 /**
  * @return \yii\web\Response
  * @throws \yii\base\ErrorException
  */
 public function actionSwitch()
 {
     $model = new ConnectionForm();
     if ($model->load(\Yii::$app->request->post()) && $model->validate()) {
         \Yii::info(VarDumper::dumpAsString($model->getAttributes()));
         $this->module->setConnection($model->connection, $model->db);
         RedisModel::resetFilter();
         \Yii::$app->session->setFlash('success', Redisman::t('redisman', 'Switched to') . $this->module->getCurrentName());
     } else {
         \Yii::$app->session->setFlash('error', Html::errorSummary($model));
     }
     return $this->redirect(['index']);
 }
 public function testSearchId()
 {
     $this->module->greedySearch = false;
     $this->module->setConnection('local', 1);
     $model = new RedisModel();
     $model->setAttributes(['pattern' => 'testfxt:*', 'type' => ['string', 'list'], 'perpage' => 30]);
     $model->validate();
     $func = $this->getProtected('getSearchId');
     $searchId = $func->invoke($model);
     Debug::debug($searchId);
     $expect = 'testfxt:*:stringlist:30:local:1:';
     $this->assertEquals($expect, $searchId);
     $this->module->greedySearch = true;
     $model->setAttributes(['pattern' => '*:*', 'type' => ['set', 'zset'], 'perpage' => 20]);
     $model->validate();
     $searchId = $func->invoke($model);
     Debug::debug($searchId);
     $expect = '*:*:setzset:20:local:1:1';
     $this->assertEquals($expect, $searchId);
     $this->module->setConnection('remote1', 0);
     $model = new RedisModel();
     $model->setAttributes(['pattern' => '*fxt*', 'perpage' => 30]);
     $model->validate();
     $func = $this->getProtected('getSearchId');
     $searchId = $func->invoke($model);
     Debug::debug($searchId);
     $expect = '*fxt*:stringsetlistzsethash:30:remote1:0:1';
     $this->assertEquals($expect, $searchId);
 }
Esempio n. 4
0
 /**
  * @depends testEscapeQuotes
  **/
 public function testInfoScript()
 {
     $start = microtime(false);
     $conn = $this->module->setConnection('remote1', 1);
     $res = $conn->executeCommand('EVAL', [$this->buildInfoScript('Queue:YProxy'), 0]);
     $end = microtime(false) - $start;
     Debug::debug($res);
     Debug::debug('time - ' . $end);
 }
Esempio n. 5
0
 public function testFixturizer()
 {
     $fixter = new RedisFixts();
     $fixter->createFixtures();
     $this->module->setConnection('local', 1);
     $this->assertEquals(1, $this->module->executeCommand('EXISTS', ['tfx_string']));
     $this->assertEquals(1, $this->module->executeCommand('EXISTS', ['tfx_hash']));
     $this->assertEquals(1, $this->module->executeCommand('EXISTS', ['tfx_list']));
     $this->assertEquals(1, $this->module->executeCommand('EXISTS', ['tfx_set']));
     $this->assertEquals(1, $this->module->executeCommand('EXISTS', ['tfx_zset']));
     $this->assertEquals(-1, $this->module->executeCommand('TTL', ['tfx_hash']));
     $this->assertNotEquals(-1, $this->module->executeCommand('TTL', ['tfx_stringexp']));
     $this->assertNotEquals(-1, $this->module->executeCommand('TTL', ['tfx_listexp']));
     $fixter->deleteFixtures();
     $this->assertEquals(0, $this->module->executeCommand('EXISTS', ['tfx_string']));
     $this->assertEquals(0, $this->module->executeCommand('EXISTS', ['tfx_hash']));
     $this->assertEquals(0, $this->module->executeCommand('EXISTS', ['tfx_list']));
     $this->assertEquals(0, $this->module->executeCommand('EXISTS', ['tfx_set']));
     $this->assertEquals(0, $this->module->executeCommand('EXISTS', ['tfx_zset']));
 }
 public function testUpdate()
 {
     $this->module->setConnection('local', 1);
     $keys = $this->module->executeCommand('KEYS', ['*']);
     foreach ($keys as $key) {
         $model = RedisItem::find($key)->findValue();
         $model->scenario = 'update';
         if ($model->type == 'string') {
             $model->setAttributes(['formatvalue' => $model->formatvalue . ' and new appendix']);
             $this->assertTrue($model->validate());
             $model->update();
             $val = $this->module->executeCommand('GET', [$model->key]);
             $this->assertContains('new appendix', $val);
             Debug::debug($val);
         } elseif ($model->type == 'list' || $model->type == 'set') {
             $model->setAttributes(['formatvalue' => $model->formatvalue . "\r\n newitem1\r\n Other new Item \r\n AbyrValg"]);
             $this->assertTrue($model->validate());
             $model->update();
             $val = $model->getValue();
             $this->assertTrue(in_array('newitem1', $val));
             $this->assertTrue(in_array('AbyrValg', $val));
             $this->assertTrue(in_array('Other new Item', $val));
             Debug::debug($val);
         } elseif ($model->type == 'hash') {
             $change = [];
             foreach ($model->value as $k => $v) {
                 $change[] = ['field' => $k, 'value' => strrev($v) . '_upd'];
             }
             $model->setAttributes(['formatvalue' => $change]);
             $this->assertTrue($model->validate());
             $model->update();
             $model->findValue();
             foreach ($model->value as $k => $v) {
                 $this->assertTrue(strpos($v, '_upd') !== 0);
             }
         } elseif ($model->type == 'zset') {
             $change = [];
             foreach ($model->value as $k => $v) {
                 $change[] = ['field' => $k, 'score' => 4];
             }
             $model->setAttributes(['formatvalue' => $change]);
             $this->assertTrue($model->validate());
             $model->update();
             $model->findValue();
             foreach ($model->value as $k => $v) {
                 $this->assertTrue($v == 4);
             }
         }
     }
 }
Esempio n. 7
0
 public function init()
 {
     $this->module = \Yii::$app->getModule('redisman');
     $this->module->setConnection('local', 1);
 }