/**
  * Constructor.
  * @return void
  */
 public function init()
 {
     $req = $this;
     $job = $this->job = new ComplexJob(function () use($req) {
         // called when job is done
         $req->wakeup();
         // wake up the request immediately
     });
     $redis = RedisClient::getInstance();
     $redis->lpush('mylist', microtime(true));
     // just pushing something
     $job('testquery', function ($name, $job) use($redis) {
         // registering job named 'testquery'
         $redis->lrange('mylist', 0, 10, function ($redis) use($name, $job) {
             // calling lrange Redis command
             $job->setResult($name, $redis->result);
             // setting job result
         });
     });
     $job();
     // let the fun begin
     $this->sleep(1, true);
     // setting timeout
 }
 public static function getPaths($id, $fromCache = false)
 {
     if ($fromCache) {
         $redis = RedisClient::getInstance(RedisConfig::$SERVER_COMMON);
         if (!is_array($id)) {
             $key = RedisKeys::ROOT_PATH_SET_ . $id;
             $set = $redis->sMembers($key);
             return empty($set) ? array() : $set;
         } else {
             $retHash = array();
             foreach ($id as $mId) {
                 $key = RedisKeys::ROOT_PATH_SET_ . $mId;
                 $set = $redis->sMembers($key);
                 $retHash[$mId] = empty($set) ? array() : $set;
             }
             return $retHash;
         }
     } else {
         RootRelationInterface::syncToRedis(array('manager_id' => $id));
         return self::getPaths($id, true);
     }
 }
 public static function syncAllToRedis()
 {
     $managerList = RootManagerInterface::getList(array('field' => 'id'));
     if (empty($managerList)) {
         return;
     }
     $managerIds = array_column($managerList, 'id');
     $retList = self::getList();
     $hash = array();
     foreach ($retList as $row) {
         $hash[$row['manager_id']][] = $row['path'];
     }
     // 对每个权限组进行排序
     foreach ($hash as $mId => $val) {
         sort($hash[$mId], SORT_STRING);
     }
     $redis = RedisClient::getInstance(RedisConfig::$SERVER_COMMON);
     $keys = $redis->keys(RedisKeys::ROOT_PATH_SET_ . '*');
     $redis->delete($keys);
     // 保存到redis
     foreach ($managerIds as $mId) {
         $pathSet = Arr::get($mId, $hash, array());
         $key = RedisKeys::ROOT_PATH_SET_ . $mId;
         foreach ($pathSet as $val) {
             $redis->sAdd($key, $val);
         }
     }
 }
Beispiel #4
0
 /**
  * @brief Insert time need to monitor into redis 
  * @param $value Value of time. e.g.The response time when call an interface 
  * @return false or string
  */
 public function insert($value)
 {
     if (empty($this->_itemName) || !is_numeric($value) || $this->_ratio <= 0) {
         return 'PARAM_ERROR';
     }
     try {
         $redis = RedisClient::getInstance('finance');
         $time = date('Y-m-d H:i', time() + 60);
         $key = $time . '#' . $this->_itemName;
         if ($redis->rpush($key, $value)) {
             $redis->expire($key, 2 * 60);
         }
     } catch (Exception $e) {
         return 'REDIS_ERROR';
     }
     return false;
 }