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

Commit

Permalink
💩 (Admin) empty the redis default search pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhilip committed Jan 31, 2019
1 parent 9da50e0 commit 2c571ed
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 22 deletions.
6 changes: 4 additions & 2 deletions apps/controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private function infoRedis()
}
$offset = app()->request->get('offset') ?? null;
$perpage = app()->request->get('perpage') ?? 50;
$pattern = app()->request->get('pattern') ?? '*';
$pattern = app()->request->get('pattern') ?? '';

$keys = app()->redis->keys($pattern);
sort($keys);
Expand All @@ -59,13 +59,15 @@ private function infoRedis()
$types[$key] = app()->redis->typeof($key);
}

$dbsize = app()->redis->dbSize();
return $this->render('admin/redis_keys.html.twig', [
'offset' => $offset,
'perpage' => $perpage,
'pattern' => $pattern,
'keys' => $limited_keys,
'types' => $types,
'num_keys' => count($keys)
'num_keys' => count($keys),
'dbsize' => $dbsize
]);
} elseif ($panel === 'key') {
$key = app()->request->get('key');
Expand Down
64 changes: 44 additions & 20 deletions apps/views/admin/redis_keys.html.twig
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
{% extends "admin/layout.html.twig" %}

{% macro pattern_builder(pat) %}
<span class="bg-success"><a href="javascript:void(0);" data-pat="{{ pat }}"> {{ pat }} </a></span>&nbsp;&nbsp;
{% endmacro %}

{% from _self import pattern_builder %}

{% block panel %}
{% if pattern != "*" %}
<h1>Keys matching <code>{{ pattern }}</code></h1>
<p><strong>{{ num_keys }} out of <strong>{{ dbsize }}</strong> matched</strong></p>
{% else %}
<h1>All Keys</h1>
<p><strong>{{ num_keys }} Keys available</strong></p>
{% endif %}
<h1>Redis Keys Status</h1>
<p>Please input the search pattern of keys, or your can use the search suggest</p>

<nav class="navbar navbar-default" role="navigation">
<div class="thumbnail">
<div>
<form id="search_redis" class="form-inline" method="get" action="/admin/service">
<div class="form-group">
<input name="provider" type="text" class="form-control" value="redis" style="display: none">
<input name="panel" type="text" class="form-control" value="keys" style="display: none">
<input name="pattern" type="text" class="form-control" placeholder="{{ pattern }}" value="{{ pattern }}">
<button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> Search </button>
<button type="reset" class="btn btn-default"><span class="glyphicon glyphicon-remove"></span> Reset </button>
</div>
</form>
</div>
<div id="suggest_pattern">Suggest Pattern :
{{ pattern_builder('*') }}
{{ pattern_builder('SESSION:*') }}
{{ pattern_builder('TORRENT:*') }}
{{ pattern_builder('TRACKER:*') }}
{{ pattern_builder('USER:*') }}
</div>
</div>

<form class="navbar-form navbar-left" role="search" method="GET" action="/admin/service">
<div class="form-group">
<input name="provider" type="text" class="form-control" value="redis" style="display: none">
<input name="panel" type="text" class="form-control" value="keys" style="display: none">
<input name="pattern" type="text" class="form-control" placeholder="{{ pattern }}"
value="{{ pattern }}">
</div>
<button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> Search
</button>
<button type="reset" class="btn btn-default"><span class="glyphicon glyphicon-remove"></span> Reset</button>
</form>
</nav>
{% if pattern != "" %}
<div>
<div class="pull-left">Keys matching <code>{{ pattern }}</code></div>
<div class="pull-right">(<strong>{{ num_keys }}</strong> out of <strong>{{ dbsize }}</strong> matched)</div>
</div>
{% endif %}

<table class="table table-hover">
<thead>
Expand Down Expand Up @@ -67,3 +81,13 @@
{% endif %}

{% endblock %}

{% block script %}
<script>
$('#suggest_pattern a').click(function () {
let pat = $(this).attr('data-pat');
$('input[name="pattern"]').val(pat);
$('#search_redis').submit();
})
</script>
{% endblock %}

0 comments on commit 2c571ed

Please sign in to comment.