Example #1
0
 /**
  * Returns the number of keys in the database
  *
  * @return array
  */
 public static function getCountKeysInDb()
 {
     $dbkeys = array();
     foreach (R::factory()->info() as $key => $value) {
         if (substr($key, 0, 2) == 'db' && ctype_digit(substr($key, 2))) {
             $str = explode(',', $value);
             $str = explode('=', $str[0]);
             $dbkeys[(int) substr($key, 2)] = $str[1];
         }
     }
     return $dbkeys;
 }
Example #2
0
 public static function getLast($user)
 {
     $key = Config::get('re_prefix') . 'log:' . sha1($user);
     $history = array();
     $uniq = array();
     foreach (R::factory()->lRange($key, -100, -1) as $h) {
         if (!in_array($h, $uniq)) {
             $uniq[] = $h;
             $history[] = array('value' => $h, 'desc' => '');
         }
     }
     return $history;
 }
Example #3
0
 public static function hDel($key, $field)
 {
     return R::factory()->hDel($key, $field);
 }
Example #4
0
 public static function smembers($key)
 {
     $value = R::factory()->sMembers($key);
     $data = array('key' => $key, 'value' => $value);
     return View::factory('tables/smembers', $data);
 }
Example #5
0
 public function ping()
 {
     $ping = R::factory()->ping();
     $this->notice = View::factory('tables/ping', array('ping' => $ping));
 }
Example #6
0
 public static function lRem($key, $count, $value)
 {
     // @XXX WARNING, please note the order of arguments
     return R::factory()->lRem($key, $value, (int) $count);
 }
Example #7
0
 */
error_reporting(E_ALL);
define('APPPATH', dirname(__DIR__) . '/application');
require_once APPPATH . '/classes/Exceptions.php';
/**
 * @TODO SPL::__autoload
 * @param $className
 */
function __autoload($className)
{
    $path = str_replace('_', '/', $className) . '.php';
    if (file_exists(APPPATH . '/classes/' . $path)) {
        require_once APPPATH . '/classes/' . $path;
    }
}
set_exception_handler('exception_handler');
$uri = parse_url(Request::factory()->getUrl(), PHP_URL_PATH);
$uri = substr($uri, 1);
Helper_Auth::auth();
if (!R::factory()->ping()) {
    throw new RedisException('Redis has not connect ' . Config::get('host') . ':' . Config::get('port'));
}
$controller = ucfirst(strstr($uri, '/', true));
$controller = 'Controller_' . ($controller ? $controller : 'Index');
$method = str_replace('/', '', substr(strstr($uri, '/', false), 1));
$method = 'action_' . ($method ? $method : 'index');
if (method_exists($controller, $method)) {
    call_user_func_array(array(new $controller(), $method), array());
} else {
    throw new ExceptionRouter('Not a valid URL : ' . $uri);
}
Example #8
0
 public static function zRank($key, $member)
 {
     return R::factory()->zRank($key, $member);
 }
Example #9
0
 public static function randomKey()
 {
     return View::factory('tables/randomkey', array('key' => R::factory()->randomKey()));
 }
Example #10
0
 public static function getValue($key, $type)
 {
     $size = 0;
     $value = ' ';
     $max = 120;
     if ($type == 'string') {
         $size = R::factory()->strlen($key);
         $value = R::factory()->getRange($key, 0, $max);
         if (strlen($value) > $size) {
             $value .= '..';
         }
     } elseif ($type == 'set') {
         $size = R::factory()->sCard($key);
         $value = '';
         foreach (R::factory()->sMembers($key) as $member) {
             if (strlen($value) < $max - 5) {
                 if (!empty($value)) {
                     $value .= ', ';
                 }
                 $value .= $member;
             } else {
                 $value .= ', ..';
                 break;
             }
         }
         $value = '[ ' . $value . ' ]';
     } elseif ($type == 'zset') {
         $size = R::factory()->zCard($key);
         $value = '';
         foreach (R::factory()->zRange($key, 0, 100, true) as $score => $item) {
             if (strlen($value) < $max - 5) {
                 if (!empty($value)) {
                     $value .= ', ';
                 }
                 $value .= $score . ':' . $item;
             } else {
                 $value .= ', ..';
                 break;
             }
         }
         $value = '[ ' . $value . ' ]';
     } elseif ($type == 'list') {
         $size = R::factory()->lSize($key);
         $value = '';
         foreach (R::factory()->lRange($key, 0, 100) as $item) {
             if (strlen($value) < $max - 5) {
                 if (!empty($value)) {
                     $value .= ', ';
                 }
                 $value .= $item;
             } else {
                 $value = substr($value, 0, $max - 5) . '..';
                 break;
             }
         }
         $value = '[ ' . $value . ' ]';
     } elseif ($type == 'hash') {
         $size = R::factory()->hLen($key);
         $value = '';
         foreach (R::factory()->hKeys($key) as $item) {
             if (strlen($value) < $max - 5) {
                 if (!empty($value)) {
                     $value .= ', ';
                 }
                 $value .= $item;
             } else {
                 $value .= ', ..';
                 break;
             }
         }
         $value = '[ ' . $value . ' ]';
     }
     return array($size, $value);
 }
Example #11
0
 public function get($key)
 {
     $data = array('key' => $key, 'value' => R::factory()->get($key), 'cmd' => 'GET ' . $key);
     return View::factory('tables/get', $data);
 }