diff options
author | Erik Dubbelboer <erik@dubbelboer.com> | 2011-07-06 17:04:48 +0400 |
---|---|---|
committer | Erik Dubbelboer <erik@dubbelboer.com> | 2011-07-06 17:04:48 +0400 |
commit | 05f5795362af5131f3dfb2381090e66de5e28018 (patch) | |
tree | 1ed66bb51051f143cc168c2b51f6346a1040e263 /view.php |
first commit
Diffstat (limited to 'view.php')
-rw-r--r-- | view.php | 177 |
1 files changed, 177 insertions, 0 deletions
diff --git a/view.php b/view.php new file mode 100644 index 0000000..63e6a1b --- /dev/null +++ b/view.php @@ -0,0 +1,177 @@ +<? + +require 'common.inc.php'; + + + + +$page['css'][] = 'frame'; +$page['js'][] = 'frame'; + +require 'header.inc.php'; + + + +if (!isset($_GET['key'])) { + ?> + Invalid key + <? +} else { + $type = $redis->type($_GET['key']); + $exists = $redis->exists($_GET['key']); + + ?> + <h2><?=format_html($_GET['key'])?> + <? + if ($exists) { + ?> + <a href="rename.php?key=<?=format_html($_GET['key'])?>"><img src="images/edit.png" width="16" height="16" title="Rename" alt="[R]"></a> + <a href="delete.php?key=<?=format_html($_GET['key'])?>" class="delkey"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a> + <a href="export.php?key=<?=format_html($_GET['key'])?>"><img src="images/export.png" width="16" height="16" title="Export" alt="[E]"></a> + <? + } + ?> + </h2> + <? + + 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=<?=format_html($_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?> <span class="info"><?=($type == 'string') ? 'characters' : 'items'?></span></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=<?=format_html($_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=<?=format_html($_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=<?=format_html($_GET['key'])?>&hkey=<?=format_html($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=<?=format_html($_GET['key'])?>&hkey=<?=format_html($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=<?=format_html($_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=<?=format_html($_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=<?=format_html($_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=<?=format_html($_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=<?=format_html($_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=<?=format_html($_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=<?=format_html($_GET['key'])?>" class="add">Add another value</a> + </p> + <? + } + } +} + +require 'footer.inc.php'; + |