diff options
author | Erik Dubbelboer <erik@dubbelboer.com> | 2011-07-14 17:13:44 +0400 |
---|---|---|
committer | Erik Dubbelboer <erik@dubbelboer.com> | 2011-07-14 17:13:44 +0400 |
commit | b6617ab280d0e9ea5c714424b75917779420b3e7 (patch) | |
tree | d8afb9cd19c5528ca07d75de97a6c334f30b3c03 /view.php | |
parent | 1c994bd0829325fa16316ded260dc8a0f782ae5d (diff) |
- multi server support
- fixed some bug
- code cleanup
Diffstat (limited to 'view.php')
-rw-r--r-- | view.php | 331 |
1 files changed, 179 insertions, 152 deletions
@@ -1,6 +1,6 @@ <? -require 'common.inc.php'; +require_once 'common.inc.php'; @@ -16,162 +16,189 @@ if (!isset($_GET['key'])) { ?> Invalid key <? -} else { - $type = $redis->type($_GET['key']); - $exists = $redis->exists($_GET['key']); + require 'footer.inc.php'; + die; +} + + + +$type = $redis->type($_GET['key']); +$exists = $redis->exists($_GET['key']); + + +?> +<h2><?=format_html($_GET['key'])?> +<? if ($exists) { ?> + <a href="rename.php?s=<?=$server['id']?>&key=<?=urlencode($_GET['key'])?>"><img src="images/edit.png" width="16" height="16" title="Rename" alt="[R]"></a> + <a href="delete.php?s=<?=$server['id']?>&key=<?=urlencode($_GET['key'])?>" class="delkey"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a> + <a href="export.php?s=<?=$server['id']?>&key=<?=urlencode($_GET['key'])?>"><img src="images/export.png" width="16" height="16" title="Export" alt="[E]"></a> +<? } ?> +</h2> +<? + +if (!$exists) { ?> - <h2><?=format_html($_GET['key'])?> - <? - if ($exists) { - ?> - <a href="rename.php?key=<?=urlencode($_GET['key'])?>"><img src="images/edit.png" width="16" height="16" title="Rename" alt="[R]"></a> - <a href="delete.php?key=<?=urlencode($_GET['key'])?>" class="delkey"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a> - <a href="export.php?key=<?=urlencode($_GET['key'])?>"><img src="images/export.png" width="16" height="16" title="Export" alt="[E]"></a> - <? - } - ?> - </h2> + This key does not exist. <? - if (!$exists) { - ?> - This key does not exist. - <? - } else { - $alt = false; - - $type = $types[$type]; - $ttl = $redis->ttl($_GET['key']); - $encoding = $redis->object('encoding', $_GET['key']); - - if ($type == 'string') { - $value = $redis->get($_GET['key']); - $size = strlen($value); - } else if ($type == 'hash') { - $values = $redis->hGetAll($_GET['key']); - $size = count($values); - } else if ($type == 'list') { - $size = $redis->lSize($_GET['key']); - } else if ($type == 'set') { - $values = $redis->sMembers($_GET['key']); - $size = count($values); - } else if ($type == 'zset') { - $values = $redis->zRange($_GET['key'], 0, -1); - $size = count($values); - } - - - ?> - <table> - - <tr><td><div>Type:</div></td><td><div><?=format_html($type)?></div></td></tr> - - <tr><td><div><abbr title="Time To Live">TTL</abbr>:</div></td><td><div><?=($ttl == -1) ? 'does not expire' : $ttl?> <a href="ttl.php?key=<?=urlencode($_GET['key'])?>&ttl=<?=$ttl?>"><img src="images/edit.png" width="16" height="16" title="Edit TTL" alt="[E]" class="imgbut"></a></div></td></tr> - - <tr><td><div>Encoding:</div></td><td><div><?=format_html($encoding)?></div></td></tr> - - <tr><td><div>Size:</div></td><td><div><?=$size?> <?=($type == 'string') ? 'characters' : 'items'?></div></td></tr> - - </table> - - <p><h3>Value<?=$size ? 's' : ''?>:</h3> - <? - - if ($type == 'string') { - ?> - <table> - <tr><td><div><?=nl2br(format_html($value))?></div></td><td><div> - <a href="edit.php?type=string&key=<?=urlencode($_GET['key'])?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a> - </div></td><td><div> - <a href="delete.php?type=string&key=<?=urlencode($_GET['key'])?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a> - </div></td></tr> - </table> - <? - } else if ($type == 'hash') { - ?> - <table> - <tr><th><div>Key</div></th><th><div>Value</div></th><th><div> </div></th><th><div> </div></th></tr> - <? - - foreach ($values as $hkey => $value) { - ?> - <tr <?=$alt ? 'class="alt"' : ''?>><td><div><?=format_html($hkey)?></div></td><td><div><?=nl2br(format_html($value))?></div></td><td><div> - <a href="edit.php?type=hash&key=<?=urlencode($_GET['key'])?>&hkey=<?=urlencode($hkey)?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a> - </div></td><td><div> - <a href="delete.php?type=hash&key=<?=urlencode($_GET['key'])?>&hkey=<?=urlencode($hkey)?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a> - </div></td></tr> - <? - - $alt = !$alt; - } - } else if ($type == 'list') { - ?> - <table> - <tr><th><div>Index</div></th><th><div>Value</div></th><th><div> </div></th><th><div> </div></th></tr> - <? - - for ($i = 0; $i < $size; ++$i) { - $value = $redis->lGet($_GET['key'], $i); - - ?> - <tr <?=$alt ? 'class="alt"' : ''?>><td><div><?=$i?></div></td><td><div><?=nl2br(format_html($value))?></div></td><td><div> - <a href="edit.php?type=list&key=<?=urlencode($_GET['key'])?>&index=<?=$i?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a> - </div></td><td><div> - <a href="delete.php?type=list&key=<?=urlencode($_GET['key'])?>&index=<?=$i?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a> - </div></td></tr> - <? - - $alt = !$alt; - } - } else if ($type == 'set') { - ?> - <table> - <tr><th><div>Value</div></th><th><div> </div></th><th><div> </div></th></tr> - <? - - foreach ($values as $value) { - ?> - <tr <?=$alt ? 'class="alt"' : ''?>><td><div><?=nl2br(format_html($value))?></div></td><td><div> - <a href="edit.php?type=set&key=<?=urlencode($_GET['key'])?>&value=<?=urlencode($value)?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a> - </div></td><td><div> - <a href="delete.php?type=set&key=<?=urlencode($_GET['key'])?>&value=<?=urlencode($value)?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a> - </div></td></tr> - <? - - $alt = !$alt; - } - } else if ($type == 'zset') { - ?> - <table> - <tr><th><div>Score</div></th><th><div>Value</div></th><th><div> </div></th><th><div> </div></th></tr> - <? - - foreach ($values as $value) { - $score = $redis->zScore($_GET['key'], $value); - - ?> - <tr <?=$alt ? 'class="alt"' : ''?>><td><div><?=$score?></div></td><td><div><?=nl2br(format_html($value))?></div></td><td><div> - <a href="edit.php?type=zset&key=<?=urlencode($_GET['key'])?>&score=<?=$score?>&value=<?=urlencode($value)?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a> - <a href="delete.php?type=zset&key=<?=urlencode($_GET['key'])?>&value=<?=urlencode($value)?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a> - </div></td></tr> - <? - - $alt = !$alt; - } - } - - if ($type != 'string') { - ?> - </table> - - <p> - <a href="edit.php?type=<?=$type?>&key=<?=urlencode($_GET['key'])?>" class="add">Add another value</a> - </p> - <? - } - } + require 'footer.inc.php'; + die; +} + + + +$alt = false; +$type = $redistypes[$type]; +$ttl = $redis->ttl($_GET['key']); +$encoding = $redis->object('encoding', $_GET['key']); + + +switch ($type) { + case 'string': + $value = $redis->get($_GET['key']); + $size = strlen($value); + break; + + case 'hash': + $values = $redis->hGetAll($_GET['key']); + $size = count($values); + break; + + case 'list': + $size = $redis->lSize($_GET['key']); + break; + + case 'set': + $values = $redis->sMembers($_GET['key']); + $size = count($values); + break; + + case 'zset': + $values = $redis->zRange($_GET['key'], 0, -1); + $size = count($values); + break; } + +?> +<table> + +<tr><td><div>Type:</div></td><td><div><?=format_html($type)?></div></td></tr> + +<tr><td><div><abbr title="Time To Live">TTL</abbr>:</div></td><td><div><?=($ttl == -1) ? 'does not expire' : $ttl?> <a href="ttl.php?s=<?=$server['id']?>&key=<?=urlencode($_GET['key'])?>&ttl=<?=$ttl?>"><img src="images/edit.png" width="16" height="16" title="Edit TTL" alt="[E]" class="imgbut"></a></div></td></tr> + +<tr><td><div>Encoding:</div></td><td><div><?=format_html($encoding)?></div></td></tr> + +<tr><td><div>Size:</div></td><td><div><?=$size?> <?=($type == 'string') ? 'characters' : 'items'?></div></td></tr> + +</table> + +<p> +<? + + + +// String +if ($type == 'string') { ?> + +<table> +<tr><td><div><?=nl2br(format_html($value))?></div></td><td><div> + <a href="edit.php?s=<?=$server['id']?>&type=string&key=<?=urlencode($_GET['key'])?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a> +</div></td><td><div> + <a href="delete.php?s=<?=$server['id']?>&type=string&key=<?=urlencode($_GET['key'])?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a> +</div></td></tr> +</table> + +<? } + + + +// Hash +else if ($type == 'hash') { ?> + +<table> +<tr><th><div>Key</div></th><th><div>Value</div></th><th><div> </div></th><th><div> </div></th></tr> + +<? foreach ($values as $hkey => $value) { ?> + <tr <?=$alt ? 'class="alt"' : ''?>><td><div><?=format_html($hkey)?></div></td><td><div><?=nl2br(format_html($value))?></div></td><td><div> + <a href="edit.php?s=<?=$server['id']?>&type=hash&key=<?=urlencode($_GET['key'])?>&hkey=<?=urlencode($hkey)?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a> + </div></td><td><div> + <a href="delete.php?s=<?=$server['id']?>&type=hash&key=<?=urlencode($_GET['key'])?>&hkey=<?=urlencode($hkey)?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a> + </div></td></tr> +<? $alt = !$alt; } ?> + +<? } + + + +// List +else if ($type == 'list') { ?> + +<table> +<tr><th><div>Index</div></th><th><div>Value</div></th><th><div> </div></th><th><div> </div></th></tr> + +<? for ($i = 0; $i < $size; ++$i) { + $value = $redis->lGet($_GET['key'], $i); +?> + <tr <?=$alt ? 'class="alt"' : ''?>><td><div><?=$i?></div></td><td><div><?=nl2br(format_html($value))?></div></td><td><div> + <a href="edit.php?s=<?=$server['id']?>&type=list&key=<?=urlencode($_GET['key'])?>&index=<?=$i?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a> + </div></td><td><div> + <a href="delete.php?s=<?=$server['id']?>&type=list&key=<?=urlencode($_GET['key'])?>&index=<?=$i?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a> + </div></td></tr> +<? $alt = !$alt; } ?> + +<? } + + + +// Set +else if ($type == 'set') { + +?> +<table> +<tr><th><div>Value</div></th><th><div> </div></th><th><div> </div></th></tr> + +<? foreach ($values as $value) { ?> + <tr <?=$alt ? 'class="alt"' : ''?>><td><div><?=nl2br(format_html($value))?></div></td><td><div> + <a href="edit.php?s=<?=$server['id']?>&type=set&key=<?=urlencode($_GET['key'])?>&value=<?=urlencode($value)?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a> + </div></td><td><div> + <a href="delete.php?s=<?=$server['id']?>&type=set&key=<?=urlencode($_GET['key'])?>&value=<?=urlencode($value)?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a> + </div></td></tr> +<? $alt = !$alt; } ?> + +<? } + + + +// ZSet +else if ($type == 'zset') { ?> + +<table> +<tr><th><div>Score</div></th><th><div>Value</div></th><th><div> </div></th><th><div> </div></th></tr> + +<? foreach ($values as $value) { + $score = $redis->zScore($_GET['key'], $value); +?> + <tr <?=$alt ? 'class="alt"' : ''?>><td><div><?=$score?></div></td><td><div><?=nl2br(format_html($value))?></div></td><td><div> + <a href="edit.php?s=<?=$server['id']?>&type=zset&key=<?=urlencode($_GET['key'])?>&score=<?=$score?>&value=<?=urlencode($value)?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a> + <a href="delete.php?s=<?=$server['id']?>&type=zset&key=<?=urlencode($_GET['key'])?>&value=<?=urlencode($value)?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a> + </div></td></tr> +<? $alt = !$alt; } ?> + +<? } + + + + +if ($type != 'string') { ?> + </table> + + <p> + <a href="edit.php?s=<?=$server['id']?>&type=<?=$type?>&key=<?=urlencode($_GET['key'])?>" class="add">Add another value</a> + </p> +<? } + + require 'footer.inc.php'; |