Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
revert(Redis): Remove view in redis , use other software install
Browse files Browse the repository at this point in the history
Fail and unnecessary to build the keys view in redis, Please use `erikdubbelboer/phpRedisAdmin` instead.
The config of serialization like:
```
  'serialization' => array(
    '*' => array( // Match like KEYS
        // Function called when saving to redis.
        'save' => function($data) { return serialize($data); },
        // Function called when loading from redis.
        'load' => function($data) { return print_r(unserialize($data), true); },
    ),
```
  • Loading branch information
Rhilip committed Aug 12, 2019
1 parent e2a22a7 commit c5d3378
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 307 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- **Auth/Login:** Add full Advanced Options support (6009dc8)
- **Secret:** Check session and user_id match or not in jwt payload (358ba5d)
- **Secret:** Protect jwt key for env('APP_SECRET_KEY') (dfa67da)
- **Sessions/List:** Use SessionsListForm to show user sessions (9ecfb97)
- **ban_ips:** Store banned ip in components/Site (01084c9)

### Fix
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ Test Account Information:
- Swoole 4.2.12
- Redis 5.0.3 Stable
- Bower 1.8.4 (A package manager for the web)

- *Suggest*
- [phpmyadmin/phpmyadmin](<https://github.com/phpmyadmin/phpmyadmin>)
- [erikdubbelboer/phpRedisAdmin](<https://github.com/erikdubbelboer/phpRedisAdmin>)

2. After you prepare those base environment well

- run below command to clone this repo or you can download from our release.
Expand Down
1 change: 1 addition & 0 deletions apps/components/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ private function logSessionInfo()

// Update User access info by HyperLogLog
$grain_size = date('YmdH') ; // per hour
// $grain_size = date('YmdH') . floor(date('i') / 15); // per 15 minutes
$check = app()->redis->pfAdd('Site:access_log_' . $grain_size . ':hyperloglog', [$identify_key]);
if ($check == 1) {
// Update Table `users`
Expand Down
91 changes: 8 additions & 83 deletions apps/controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,91 +33,16 @@ public function actionService()

private function infoRedis()
{
$panel = app()->request->get('panel', 'status');
$info = app()->redis->info();
$dbsize = app()->redis->dbSize();
$cmdstat_raw = app()->redis->info('commandstats');

if ($panel === 'keys') {
$offset = app()->request->get('offset', 0);
$perpage = app()->request->get('perpage', 50);
$cmdstat = array_map(function ($v) {
preg_match('/calls=(?P<calls>\d+),usec=(?P<usec>\d+),usec_per_call=(?P<usec_per_call>[\d\.]+)/', $v, $m);
return $m;
}, $cmdstat_raw);

if (app()->request->isPost()) {
$action = app()->request->post('action');
if ($action == 'delkey') {
$delkey = app()->request->post('key');
app()->redis->del($delkey);
} elseif ($action == 'delkeys') {
$pattern = app()->request->post('keypattern');
app()->redis->del(app()->redis->keys($pattern));
}
}
$dbsize = app()->redis->dbSize();
$pattern = app()->request->get('pattern');

$render_data = [
'dbsize' => $dbsize,
'offset' => $offset,
'perpage' => $perpage,
];

if ($pattern) {
$keys = app()->redis->keys($pattern);
sort($keys);
$limited_keys = array_slice($keys, $offset * $perpage, $perpage);

$types = [];
foreach ($limited_keys as $key) {
$types[$key] = app()->redis->type($key);
}

$render_data = $render_data + [
'pattern' => $pattern,
'keys' => $limited_keys,
'types' => $types,
'num_keys' => count($keys),
];
}
return $this->render('admin/redis_keys', $render_data);
} elseif ($panel === 'key') {
$key = app()->request->get('key');
$dump = app()->redis->dump($key);
if ($dump === false) {
return app()->response->setStatusCode(404);
}
$size = strlen($dump);
$t = app()->redis->type($key);
$ttl = app()->redis->ttl($key);
if ($t == \Redis::REDIS_STRING) {
$val = app()->redis->get($key);
} elseif ($t == \Redis::REDIS_LIST) {
$val = app()->redis->lRange($key, 0, -1);
} elseif ($t == \Redis::REDIS_HASH) {
$val = app()->redis->hGetAll($key);
} elseif ($t == \Redis::REDIS_SET) {
$val = app()->redis->sMembers($key);
} elseif ($t == \Redis::REDIS_ZSET) {
$val = app()->redis->zRange($key, 0, -1, true);
} else {
$val = '';
}
return $this->render('admin/redis_key', [
'key' => $key,
'value' => $val,
'type' => $t,
'size' => $size,
'ttl' => $ttl,
'expiration' => time() + $ttl,
]);
} else { // &panel=status
$info = app()->redis->info();
$dbsize = app()->redis->dbSize();
$cmdstat_raw = app()->redis->info('commandstats');

$cmdstat = array_map(function ($v) {
preg_match('/calls=(?P<calls>\d+),usec=(?P<usec>\d+),usec_per_call=(?P<usec_per_call>[\d\.]+)/', $v, $m);
return $m;
}, $cmdstat_raw);

return $this->render('admin/redis_status', ['info' => $info, 'dbsize' => $dbsize, 'cmdstat' => $cmdstat]);
}
return $this->render('admin/redis_status', ['info' => $info, 'dbsize' => $dbsize, 'cmdstat' => $cmdstat]);
}

private function infoMysql()
Expand Down
1 change: 0 additions & 1 deletion apps/process/CronTabProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public function run()
} catch (\Exception $e) {
app()->pdo->rollback();
app()->log->critical('The run job throw Exception : ' . $e->getMessage());
if (env('APP_DEBUG')) throw $e;
}
} else {
if (!in_array($job, $this->_none_exist_job)) {
Expand Down
1 change: 0 additions & 1 deletion apps/views/admin/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
<ul>
<li><!--suppress HtmlUnknownTarget --><a href="/admin/service?provider=mysql"><cite>Mysql Status</cite></a></li>
<li><!--suppress HtmlUnknownTarget --><a href="/admin/service?provider=redis"><cite>Redis Service Status</cite></a></li>
<li><!--suppress HtmlUnknownTarget --><a href="/admin/service?provider=redis&panel=keys"><cite>Redis Keys Status</cite></a></li>
</ul>
</li>
</ul>
Expand Down
110 changes: 0 additions & 110 deletions apps/views/admin/redis_key.php

This file was deleted.

111 changes: 0 additions & 111 deletions apps/views/admin/redis_keys.php

This file was deleted.

0 comments on commit c5d3378

Please sign in to comment.