/** * @param $attribute * @param $params * * @return bool */ public function validateDb($attribute, $params) { if (!$this->hasErrors('connection')) { $totalDbCount = $this->module->totalDbCount(); if ($this->{$attribute} >= $totalDbCount[$this->connection]) { $this->addError($attribute, Redisman::t('redisman', 'Database with current number not allowed for this connection')); return false; } return true; } else { return false; } }
<i class="icon options"></i> <?php echo Redisman::t('redisman', 'Connection Settings'); ?> </div> <div class="text item"> <?php echo $this->render('_connectform'); ?> </div> <div class="header item"> <i class="icon search"></i><?php echo Redisman::t('redisman', 'Search Key'); ?> </div> <div class="text item"> <?php echo $this->render('_searchform'); ?> </div> <div class="header item"> <i class="icon database"></i> <?php echo Redisman::t('redisman', 'Db Operations'); ?> </div> <?php echo Html::a('<i class="icon save"></i> ' . Redisman::t('redisman', 'Save database'), ['/redisman/default/savedb'], ['class' => 'active green item']); ?> <?php echo Html::a('<i class="icon trash outline"></i> ' . Redisman::t('redisman', 'Flush database'), ['/redisman/default/flushdb'], ['data-method' => 'post', 'data-confirm' => Redisman::t('redisman', 'You really want to do it?'), 'class' => 'active red item']); ?> </div>
/** * @return \yii\web\Response */ public function actionMove() { $model = new RedisItem(); $model->scenario = 'move'; if ($model->load(\Yii::$app->request->post()) && $model->validate()) { $model->move(); \Yii::$app->session->setFlash('success', Redisman::t('redisman', 'Key moved from Db№ {from} to {to}', ['from' => $this->module->getCurrentDb(), 'to' => $model->db])); } else { \Yii::$app->session->setFlash('error', Html::errorSummary($model, ['encode' => true])); } return $this->redirect(Url::to(['/redisman/default/show'])); }
<div class="one"> <button class="ui blue icon button submit"><i class="save icon"></i><?php echo Yii::t('app', 'Save'); ?> </button> </div> <?php \Zelenin\yii\SemanticUI\widgets\ActiveForm::end(); ?> </div> </div> <div class="column"> <div class="ui segment"> <a class="ui right ribbon blue label"><?php echo Redisman::t('redisman', 'Operations log'); ?> </a> <div style="min-height: 250px;max-height: 600px" class="ui bulleted divided list"> <?php foreach ($lastlog as $log) { ?> <?php echo \yii\helpers\Html::tag('div', $log, ['class' => 'item']); ?> <?php } ?> </div> </div> </div>
*/ $module = $this->context->module; $model = new \insolita\redisman\models\RedisModel(); $model->restoreFilter(); $form = \Zelenin\yii\SemanticUI\widgets\ActiveForm::begin(['id' => 'login-form', 'options' => ['class' => 'ui form attached fluid'], 'enableClientValidation' => true, 'method' => 'post', 'action' => \yii\helpers\Url::to(['/redisman/default/search'])]); echo $form->errorSummary($model); ?> <div class="one"> <?php echo $form->field($model, 'pattern')->textInput()->hint(Redisman::t('redisman', 'support redis patterns (*,?,[var])')); ?> </div> <div class="one"> <?php echo $form->field($model, 'type')->checkboxList([Redisman::REDIS_STRING => Redisman::t('redisman', 'string'), Redisman::REDIS_HASH => Redisman::t('redisman', 'hash'), Redisman::REDIS_LIST => Redisman::t('redisman', 'list'), Redisman::REDIS_SET => Redisman::t('redisman', 'set'), Redisman::REDIS_ZSET => Redisman::t('redisman', 'zset')]); ?> </div> <div class="one"> <?php echo $form->field($model, 'perpage')->dropDownList([20 => 20, 30 => 30, 50 => 50, 100 => 100, 200 => 200, 500 => 500]); ?> </div> <div class="one"> <?php echo $form->field($model, 'encache')->checkbox([]); ?> </div><br/> <div class="one right aligned"> <?php echo Elements::button('<i class="find icon"></i>' . Yii::t('app', 'Search'), ['class' => 'teal circular right ui aligned', 'type' => 'submit', 'tag' => 'button']);
/** * @inherit * @return array */ public function attributeLabels() { return ['pattern' => Redisman::t('redisman', 'Search pattern'), 'type' => Redisman::t('redisman', 'Type'), 'perpage' => Redisman::t('redisman', 'Page Size'), 'encache' => Redisman::t('redisman', 'Enable query caching?')]; }
<div class="ui centered padded stackable grid"> <?php echo \Zelenin\yii\SemanticUI\collections\Menu::widget(['topAttached' => true, 'fluid' => true, 'inverted' => true, 'options' => ['class' => 'centered '], 'items' => [['url' => ['/'], 'label' => \insolita\redisman\Redisman::t('redisman', 'Main')], ['url' => ['/site/about'], 'label' => \insolita\redisman\Redisman::t('redisman', 'About')], ['url' => ['/site/logout'], 'options' => ['data-method' => 'post'], 'label' => \insolita\redisman\Redisman::t('redisman', 'Logout'), 'visible' => !Yii::$app->user->isGuest]]]); ?> </div>
echo $form->errorSummary($model); ?> <div class="one"> <?php echo $form->field($model, 'connection')->dropDownList($module->connectionList(), ['id' => 'currentcon']); ?> </div> <div class="one"> <?php echo $form->field($model, 'db')->dropDownList($module->dbList(), ['id' => 'currentdb']); ?> </div><br/> <div class="one right ui aligned"> <?php echo Elements::button('<i class="plug icon"></i>' . \insolita\redisman\Redisman::t('redisman', 'Connect'), ['class' => 'green circular right aligned', 'type' => 'submit', 'tag' => 'button']); ?> </div> <?php ActiveForm::end(); $js = new \yii\web\JsExpression('var url="' . \yii\helpers\Url::to(['/redisman/default/dbload']) . '"; var cur=$("#connectionform-connection").val(); $("#currentcon").dropdown ({ onChange: function(value, text, $selectedItem) { console.log(value + "|"+ cur); if(value && value!=cur) { cur=value;
<?php use insolita\redisman\Redisman; use yii\helpers\Html; use Zelenin\yii\SemanticUI\widgets\DetailView; /** * @var \yii\web\View $this * @var \insolita\redisman\controllers\DefaultController $context * @var \insolita\redisman\Redisman $module * @var \insolita\redisman\models\RedisItem $model */ $module = $this->context->module; $this->title = $module->getCurrentName(); ?> <div class="ui raised segment"> <a class="ui ribbon teal label"><?php echo Redisman::keyTyper($model->type); ?> </a> <span><i class="icon privacy"></i><?php echo Html::encode($model->key); ?> </span> <?php echo DetailView::widget(['model' => $model, 'attributes' => ['size', 'ttl', 'refcount', 'idletime', 'db', 'encoding', ['label' => Redisman::t('redisman', 'Value'), 'format' => 'raw', 'value' => is_array($model->value) ? Html::encode(\yii\helpers\VarDumper::dumpAsString($model->value, 10, false)) : Html::encode($model->formatvalue)]]]); ?> </div>
/** * @param string $name * @param array $params * * @return mixed * @throws Exception */ public function executeCommand($name, $params = []) { $this->open(); if (!isset($this->redisCommands[$name])) { throw new Exception(Redisman::t('redisman', 'Method ' . $name . ' not supported by ' . get_class($this) . ' yet')); } $name = $this->redisCommands[$name]; $i = 0; while ($i < 15) { try { return call_user_func_array(array($this->_socket, $name), $params); } catch (\RedisException $e) { if ($i < 5) { $this->handle_exception($e, $name, $params); usleep(100); $i++; } elseif ($i < 15) { $this->handle_exception($e, $name, $params); usleep(500); $i++; } else { $this->handle_exception($e, $name, $params, false); break; } } catch (Exception $e) { $this->handle_exception($e, $name, $params, false); break; } } }
?> <?php } elseif ($model->type == Redisman::REDIS_HASH) { ?> <?php echo $this->render('form_hash', ['model' => $model]); ?> <?php } else { ?> <?php echo $this->render('form_zset', ['model' => $model]); ?> <?php } ?> </div> </div> </div> <?php if (\yii\helpers\Url::previous('show')) { ?> <?php echo Html::a('<i class="icon backward"></i>' . Redisman::t('redisman', 'Go back'), \yii\helpers\Url::previous('show'), ['class' => 'ui icon blue button']); ?> <?php } ?> </div> <?php $this->registerJs("\$('.tabular.menu .item').tab();");
<div class="ui centered padded stackable grid"> <?php echo \Zelenin\yii\SemanticUI\collections\Menu::widget(['topAttached' => true, 'fluid' => true, 'inverted' => true, 'options' => ['class' => 'centered '], 'items' => [['url' => ['/'], 'label' => \insolita\redisman\Redisman::t('redisman', 'Main')], ['url' => ['/site/about'], 'label' => \insolita\redisman\Redisman::t('redisman', 'About')], ['url' => ['/log/index'], 'label' => Yii::t('app', 'Actions Log')], ['label' => Yii::t('app', 'Language'), 'items' => [['url' => ['/redisman/default/index', 'lang' => 'ru'], 'label' => Yii::t('app', 'Russian')], ['url' => ['/redisman/default/index', 'lang' => 'en'], 'label' => Yii::t('app', 'English')]]], ['url' => ['/site/logout'], 'options' => ['data-method' => 'post'], 'label' => \insolita\redisman\Redisman::t('redisman', 'Logout'), 'visible' => !Yii::$app->user->isGuest]]]); ?> </div>
/** * @return \yii\web\Response */ public function actionFlushdb() { if ($this->module->dbFlush()) { \Yii::$app->session->setFlash('success', Redisman::t('redisman', 'Database is clear')); } else { \Yii::$app->session->setFlash('error', Redisman::t('redisman', 'Flushing this DB not allowed'), false); } return $this->redirect(['index']); }
/** * @param $name * @param $db * * @return \yii\redis\Connection * @throws ErrorException */ public function setConnection($name, $db = null) { if (!isset($this->connections[$name])) { throw new ErrorException(self::t('redisman', 'Wrong redis connection name')); } else { $oldcon = $this->_conCurrent; $olddb = $this->_dbCurrent; try { $this->_conCurrent = $name; $this->_connect = $this->getConnection(true, $db); } catch (Exception $e) { \Yii::$app->session->setFlash('error', Redisman::t('redisman', 'Can`t set connection with ' . $name) . "\n" . $e->getMessage()); $this->_conCurrent = $oldcon; $this->_connect = $this->getConnection(true, $olddb); } \Yii::$app->session->set('RedisManager_conCurrent', $this->_conCurrent); \Yii::$app->session->set('RedisManager_dbCurrent', $this->_dbCurrent); return $this->_connect; } }
<?php use insolita\redisman\Redisman; use Zelenin\yii\SemanticUI\modules\Accordion; use yii\helpers\Html; /** * @var \yii\web\View $this * @var \insolita\redisman\controllers\DefaultController $context * @var \insolita\redisman\Redisman $module * @var array $info */ $module = $this->context->module; $this->title = $module->getCurrentName(); $infoformat = []; foreach ($info as $section => $data) { $content = ''; foreach ($data as $key => $val) { if ($key == 'rdb_last_save_time') { $val = date('d.m.Y H:i:s', $val); } $content .= Html::tag('tr', Html::tag('td', Redisman::t('redisman', $key)) . Html::tag('td', $val)); } $infoformat[] = ['title' => Redisman::t('redisman', $section), 'content' => Html::tag('table', $content, ['class' => "ui definition table"])]; } ?> <div class="ui blue segment"> <?php echo Accordion::widget(['styled' => true, 'fluid' => true, 'contentOptions' => ['encode' => false], 'items' => $infoformat]); ?> </div>
<div class="ui orange segment"> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => '\\Zelenin\\yii\\SemanticUI\\widgets\\CheckboxColumn'], 'key', 'type', 'size', 'ttl', ['class' => '\\yii\\grid\\ActionColumn', 'template' => '{quick} {view} {delete}', 'buttons' => ['quick' => function ($url, $model) { return Html::a('<i class="icon circular large eye green"></i>', \yii\helpers\Url::to(['/redisman/item/quick', 'key' => urlencode($model['key'])]), ['data-pjax' => 0, 'class' => 'modalink', 'title' => Yii::t('app', 'Quick View')]); }, 'view' => function ($url, $model) { return Html::a('<i class="icon circular inverted eye green"></i>', \yii\helpers\Url::to(['/redisman/item/view', 'key' => urlencode($model['key'])]), ['data-pjax' => 0, 'title' => Yii::t('app', 'View')]); }, 'delete' => function ($url, $model) { return Html::a('<i class="icon circular small trash red"></i>', \yii\helpers\Url::to(['/redisman/item/delete']), ['data-pjax' => 0, 'data-params' => ['RedisItem[key]' => urlencode($model['key'])], 'data-confirm' => 'Подтвердите действие', 'data-method' => 'post', 'title' => Yii::t('app', 'Delete')]); }]]]]); ?> </div> <?php $modal = \Zelenin\yii\SemanticUI\modules\Modal::begin(['id' => 'quickmodal', 'size' => \Zelenin\yii\SemanticUI\modules\Modal::SIZE_LARGE, 'header' => \insolita\redisman\Redisman::t('redisman', 'Key Information'), 'actions' => \Zelenin\yii\SemanticUI\Elements::button(\insolita\redisman\Redisman::t('redisman', 'Close'), ['class' => 'black'])]); ?> <div class="content"></div> <?php $modal::end(); $this->registerJs(' $(document).on("click",".modalink",function(e){ e.preventDefault(); var url=$(this).attr("href"); $.get(url,function(data){ $("#quickmodal .content").html(data); $("#quickmodal").modal({onHide:function(){ $("#quickmodal .content").html("");}}).modal("show"); }); }); ');
/** * @param $key * * @return RedisItem * @throws NotFoundHttpException */ public static function find($key) { $ex = Redisman::getInstance()->executeCommand('EXISTS', [$key]); if (!$ex) { throw new NotFoundHttpException(Redisman::t('redisman', 'key not found')); } else { list($type, $size, $ttl, $refcount, $idletype, $encoding) = Redisman::getInstance()->executeCommand('EVAL', [self::infoScript($key), 0]); $model = new static(); $model->setAttributes(ArrayHelper::merge(['class' => 'insolita\\redisman\\models\\RedisItem', 'key' => $key, 'db' => Redisman::getInstance()->getCurrentDb(), 'storage' => Redisman::getInstance()->getCurrentConn()], compact('type', 'size', 'ttl', 'refcount', 'idletime', 'encoding')), false); $event = new Event(); $event->data = $model->getAttributes(); $model->onAfterFind($event); return $model; } }
?> </button> </div> <?php \Zelenin\yii\SemanticUI\widgets\ActiveForm::end(); ?> </div> <div class="ui bottom attached tab segment" data-tab="tabappend"> <?php $form = \Zelenin\yii\SemanticUI\widgets\ActiveForm::begin(['action' => ['/redisman/item/append', 'key' => urlencode($model->key)]]); ?> <div class="one"> <?php $model->formatvalue = ''; echo $form->field($model, 'formatvalue')->widget(\lav45\aceEditor\AceEditorWidget::className(), ['mode' => 'text', 'fontSize' => 15, 'height' => 200, 'options' => ['id' => 'appendfield']]); ?> </div> <br/> <div class="one"> <button class="ui blue icon button submit"><i class="save icon"></i><?php echo Redisman::t('redisman', 'Append'); ?> </button> </div> <?php \Zelenin\yii\SemanticUI\widgets\ActiveForm::end(); ?> </div>
<div class="content"> <?php echo $module->getCurrentName(); ?> <div class="sub header"><?php echo Redisman::t('redisman', 'Current Connection'); ?> </div> </div> </h1> <?php echo Menu::widget(['pointing' => true, 'encodeLabels' => false, 'items' => [['label' => '<i class="info circle icon blue"></i>' . Redisman::t('redisman', 'Info'), 'url' => ['/redisman/default/index'], 'options' => ['class' => 'blue item']], ['label' => '<i class="privacy circle icon orange"></i>' . Redisman::t('redisman', 'List Keys'), 'url' => ['/redisman/default/show'], 'options' => ['class' => 'orange item']], ['label' => '<i class="add circle icon green"></i>' . Redisman::t('redisman', 'Add'), 'options' => ['class' => 'green item'], 'items' => [['label' => Redisman::keyTyper(Redisman::REDIS_STRING), 'url' => ['/redisman/item/create', 'type' => Redisman::REDIS_STRING]], ['label' => Redisman::keyTyper(Redisman::REDIS_LIST), 'url' => ['/redisman/item/create', 'type' => Redisman::REDIS_LIST]], ['label' => Redisman::keyTyper(Redisman::REDIS_HASH), 'url' => ['/redisman/item/create', 'type' => Redisman::REDIS_HASH]], ['label' => Redisman::keyTyper(Redisman::REDIS_SET), 'url' => ['/redisman/item/create', 'type' => Redisman::REDIS_SET]], ['label' => Redisman::keyTyper(Redisman::REDIS_ZSET), 'url' => ['/redisman/item/create', 'type' => Redisman::REDIS_ZSET]]]]]]); ?> <?php echo \insolita\redisman\widgets\Alert::widget(['encode' => false, 'successTitle' => Redisman::t('redisman', 'Success!'), 'errorTitle' => Redisman::t('redisman', 'Error!'), 'warningTitle' => Redisman::t('redisman', 'Warning!'), 'infoTitle' => Redisman::t('redisman', 'Attention!!')]); ?> <?php echo $content; ?> </div> </div> </div> <?php $this->endBody(); ?> </body> </html> <?php $this->endPage();