function print_namespace($item, $name, $fullkey, $islast) { global $config, $redistypes, $server, $redis; // Is this also a key and not just a namespace? if (isset($item['__phpredisadmin__'])) { // Unset it so we won't loop over it when printing this namespace. unset($item['__phpredisadmin__']); $type = $redis->type($fullkey); if (!isset($redistypes[$type])) { return; } $type = $redistypes[$type]; $class = array(); $len = false; if (isset($_GET['key']) && ($fullkey == $_GET['key'])) { $class[] = 'current'; } if ($islast) { $class[] = 'last'; } // Get the number of items in the key. if (!isset($config['faster']) || !$config['faster']) { switch ($type) { case 'hash': $len = $redis->hLen($fullkey); break; case 'list': $len = $redis->lSize($fullkey); break; case 'set': // This is currently the only way to do this, this can be slow since we need to retrieve all keys $len = count($redis->sMembers($fullkey)); break; case 'zset': // This is currently the only way to do this, this can be slow since we need to retrieve all keys $len = count($redis->zRange($fullkey, 0, -1)); break; } } ?> <li<?php echo empty($class) ? '' : ' class="'.implode(' ', $class).'"'?>> <a href="?view&s=<?php echo $server['id']?>&key=<?php echo urlencode($fullkey)?>"><?php echo format_html($name)?><?php if ($len !== false) { ?><span class="info">(<?php echo $len?>)</span><?php } ?></a> </li> <?php } // Does this namespace also contain subkeys? if (count($item) > 0) { ?> <li class="folder<?php echo empty($fullkey) ? '' : ' collapsed'?><?php echo $islast ? ' last' : ''?>"><div class="icon"><?php echo format_html($name)?> <span class="info">(<?php echo count($item)?>)</span></div> <ul> <?php $l = count($item); foreach ($item as $childname => $childitem) { // $fullkey will be empty on the first call. if (empty($fullkey)) { $childfullkey = $childname; } else { $childfullkey = $fullkey.$config['seperator'].$childname; } print_namespace($childitem, $childname, $childfullkey, (--$l == 0)); } ?> </ul> </li> <?php } }
function print_namespace($item, $name, $fullkey, $islast) { global $config, $server, $redis; // Is this also a key and not just a namespace? if (isset($item['__phpredisadmin__'])) { // Unset it so we won't loop over it when printing this namespace. unset($item['__phpredisadmin__']); $class = array(); $len = false; if (isset($_GET['key']) && $fullkey == $_GET['key']) { $class[] = 'current'; } if ($islast) { $class[] = 'last'; } // Get the number of items in the key. if (!isset($config['faster']) || !$config['faster']) { switch ($redis->type($fullkey)) { case 'hash': $len = $redis->hLen($fullkey); break; case 'list': $len = $redis->lLen($fullkey); break; case 'set': $len = $redis->sCard($fullkey); break; case 'zset': $len = $redis->zCard($fullkey); break; } } ?> <li<?php echo empty($class) ? '' : ' class="' . implode(' ', $class) . '"'; ?> > <a href="?view&s=<?php echo $server['id']; ?> &d=<?php echo $server['db']; ?> &key=<?php echo urlencode($fullkey); ?> "><?php echo format_html($name); if ($len !== false) { ?> <span class="info">(<?php echo $len; ?> )</span><?php } ?> </a> </li> <?php } // Does this namespace also contain subkeys? if (count($item) > 0) { ?> <li class="folder<?php echo $fullkey === '' ? '' : ' collapsed'; echo $islast ? ' last' : ''; ?> "> <div class="icon"><?php echo format_html($name); ?> <span class="info">(<?php echo count($item); ?> )</span> <?php if ($fullkey !== '') { ?> <a href="delete.php?s=<?php echo $server['id']; ?> &d=<?php echo $server['db']; ?> &tree=<?php echo urlencode($fullkey); ?> :" class="deltree"><img src="images/delete.png" width="10" height="10" title="Delete tree" alt="[X]"></a><?php } ?> </div><ul> <?php $l = count($item); foreach ($item as $childname => $childitem) { // $fullkey will be empty on the first call. if ($fullkey === '') { $childfullkey = $childname; } else { $childfullkey = $fullkey . $server['seperator'] . $childname; } print_namespace($childitem, $childname, $childfullkey, --$l == 0); } ?> </ul> </li> <?php } }