Exemplo n.º 1
1
function srvc_redis_dump_info()
{
    // https://github.com/phpredis/phpredis#close
    $redis = new Redis();
    $redis->connect('127.0.0.1');
    $redis_info = $redis->info();
    $redis->close();
    $json = json_encode($redis_info);
    echo "{$json}";
}
Exemplo n.º 2
0
 /**
  * Отключение от Redis.
  * 
  * @return void
  * @access public
  * @static
  */
 public static function close()
 {
     if (static::$redis) {
         static::$redis->close();
         static::$redis = null;
     }
 }
Exemplo n.º 3
0
 public function tearDown()
 {
     if ($this->redis) {
         $this->redis->close();
     }
     //     unset($this->redis);
 }
Exemplo n.º 4
0
Arquivo: Redis.php Projeto: ovr/cacher
 public function __destruct()
 {
     if ($this->instance) {
         $this->instance->close();
         unset($this->instance);
     }
 }
Exemplo n.º 5
0
 public static function tearDownAfterClass()
 {
     parent::tearDownAfterClass();
     self::clear(self::$conn);
     self::$conn->close();
     self::$conn = null;
 }
 /**
  * connect to redis server
  * 
  * @param string $host
  * @param integer $port
  * @param integer $timeout
  * @throws Tinebase_Exception_Backend
  */
 public function connect($host = null, $port = null, $timeout = null)
 {
     if ($this->_redis instanceof Redis) {
         $this->_redis->close();
     }
     $host = $host ? $host : $this->_options['host'];
     $port = $port ? $port : $this->_options['port'];
     $timeout = $timeout ? $timeout : $this->_options['timeout'];
     $this->_redis = new Redis();
     if (!$this->_redis->connect($host, $port, $timeout)) {
         throw new Tinebase_Exception_Backend('Could not connect to redis server at ' . $host);
     }
 }
Exemplo n.º 7
0
function initModules($application)
{
    $redis = new Redis();
    $redis->connect(CACHE_HOSTNAME, CACHE_PORT);
    $redis->select(CACHE_DB);
    $modulesKey = $application . '-modules';
    $modules = $redis->get($modulesKey);
    if (empty($modules)) {
        $modules = [];
        $dir = __DIR__ . '/../../' . $application . '/modules';
        $dirpath = realpath($dir);
        $filenames = scandir($dir);
        foreach ($filenames as $filename) {
            if ($filename == '.' || $filename == '..') {
                continue;
            }
            if (is_file($dirpath . DIRECTORY_SEPARATOR . $filename . '/Module.php')) {
                $modules[strtolower($filename)] = ['class' => $application . '\\modules\\' . $filename . '\\Module'];
            }
        }
        $redis->set($modulesKey, serialize([$modules, null]));
    } else {
        $modules = unserialize($modules);
        if (!empty($modules[0])) {
            $modules = $modules[0];
        }
    }
    $redis->close();
    return $modules;
}
Exemplo n.º 8
0
 /**
  * {@inheritDoc}
  * @see \Mcustiel\SimpleCache\Interfaces\CacheInterface::finish()
  */
 public function finish()
 {
     if ($this->connection !== null) {
         $this->connection->close();
         $this->connection = null;
     }
 }
Exemplo n.º 9
0
	public function __destruct() {
		try {
			if ($this->_redis) {
				$this->_redis->close();
			}
		} catch (Exception $e) {}
	}
Exemplo n.º 10
0
 /**
  *
  */
 public function close()
 {
     if ($this->_socket) {
         $this->_socket->close();
         $this->_socket = null;
     }
 }
 public function process()
 {
     $this->params['output'] = 'json';
     $context = \CADB\Model\Context::instance();
     if (!($rdb = $context->getProperty('service.redis'))) {
         $this->result = array('found' => false, 'error' => "자동완성 기능이 활성화되어 있지 않습니다.");
     } else {
         if (!$this->params['q']) {
             $this->result = array('found' => false, 'error' => "자동완성할 키워드를 입력하세요.");
         } else {
             $redis = new \Redis();
             try {
                 $redis->connect('127.0.0.1', '6379', 2.5, NULL, 150);
                 if ($redis->select($rdb) == false) {
                     $this->result = array('found' => false, 'error' => "index 1 database 에 연결할 수 없습니다.");
                 } else {
                     $this->recommand = $redis->zRange($this->params['q'], 0, -1);
                     if (@count($this->recommand)) {
                         $this->result = array('found' => true, 'total_cnt' => @count($this->recommand));
                     } else {
                         $this->result = array('found' => true, 'total_cnt' => 0);
                     }
                 }
             } catch (RedisException $e) {
                 var_dump($e);
             }
             $redis->close();
         }
     }
 }
Exemplo n.º 12
0
 /**
  * Class destructor
  *
  * Closes the connection to Redis if present.
  *
  * @return	void
  */
 public function __destruct()
 {
     //        if ($this->_redis && $this->is_supported())
     if ($this->_redis) {
         $this->_redis->close();
     }
 }
Exemplo n.º 13
0
 /**
  * Closes a connection.
  *
  * @return bool Always true
  */
 public function close()
 {
     if ($this->isConnected()) {
         $this->_connection->close();
     }
     $this->connected = false;
     $this->_connection = null;
     return true;
 }
Exemplo n.º 14
0
 public function close()
 {
     if ($this->_connected) {
         try {
             $this->_redis->close();
         } catch (Exception $e) {
         }
         $this->_connected = false;
     }
 }
Exemplo n.º 15
0
 public function __construct()
 {
     $redis = new Redis();
     try {
         $redis->connect('127.0.0.1', 6379);
         $this->data = array('count' => $redis->get('cobbler:count'), 'speed' => $redis->get('cobbler:speed'));
         $redis->close();
     } catch (Exception $e) {
         $this->error(500, $e->getMessage());
     }
 }
Exemplo n.º 16
0
 /**
  * Destroy the connections.
  */
 public function __destruct()
 {
     switch (NN_CACHE_TYPE) {
         case self::TYPE_REDIS:
             $this->server->close();
             break;
         case self::TYPE_MEMCACHED:
             $this->server->quit();
             break;
     }
 }
Exemplo n.º 17
0
 /**
  * Properly close the connection.
  */
 public function __destruct()
 {
     if ($this->redis instanceof Redis) {
         try {
             $this->redis->close();
         } catch (RedisException $e) {
             /*
              * \Redis::close will throw a \RedisException("Redis server went away") exception if
              * we haven't previously been able to connect to Redis or the connection has severed.
              */
         }
     }
 }
Exemplo n.º 18
0
 /**
  * @return void
  */
 public function __destruct()
 {
     // clean all messages sent and not parsed to skip unexpected errors
     // on next run...
     // Note: all keys have full name, trim keys until getting them without prefix
     $prefixOffset = strlen($this->prefix);
     $keys = array_map(function ($key) use($prefixOffset) {
         return substr($key, $prefixOffset);
     }, array_filter($this->client->keys("*"), function ($key) {
         return preg_match(sprintf("/^(%s)/", preg_quote($this->prefix, "/")), $key);
     }));
     $this->client->delete($keys);
     $this->client->close();
 }
Exemplo n.º 19
0
/**
 * Queue a task to be run by Celery.
 *
 * @param task Celery task name.
 * @param args (Optional) array of arguments.
 * @param kwargs (Optional) hash of keyword arguments.
 */
function queue_task($task, $args = null, $kwargs = null)
{
    // assemble Celery-ready messages
    $body = array("id" => uniqid(CELERY_ID_PREFIX), "task" => $task);
    if (!empty($args)) {
        $body["args"] = $args;
    }
    if (!empty($kwargs)) {
        $body["kwargs"] = $kwargs;
    }
    $envelope = array("content-encoding" => "utf-8", "content-type" => "application/json", "body" => base64_encode(json_encode($body)), "properties" => array("body_encoding" => "base64", "delivery_tag" => uniqid(CELERY_ID_PREFIX), "delivery_mode" => 2, "delivery_info" => array("exchange" => CELERY_REDIS_KEY, "routing_key" => CELERY_REDIS_KEY, "priority" => 0)));
    $redis = new Redis();
    $redis->connect(REDIS_HOST);
    $redis->lPush(CELERY_REDIS_KEY, json_encode($envelope));
    $redis->close();
}
Exemplo n.º 20
0
function redis_user_logged($uid)
{
    if (!class_exists('Redis') || !REDIS_MODE) {
        return FALSE;
    }
    $redis = new Redis();
    $is_success = $redis->pconnect(REDIS_SERVER_HOST, REDIS_SERVER_PORT);
    if (!$is_success) {
        $redis->connect(REDIS_SERVER_HOST, REDIS_SERVER_PORT);
    }
    $is_logged = $redis->get('uid_' . $uid . '_login');
    $redis->close();
    if (intval($is_logged) == 1) {
        return TRUE;
    }
    return FALSE;
}
Exemplo n.º 21
0
 /**
  * Destructor
  */
 public function __destruct()
 {
     if (null !== $this->redis) {
         $this->redis->close();
     }
 }
Exemplo n.º 22
0
 /**
  * Class destructor
  *
  * Closes the connection to Redis if present.
  *
  * @return	void
  */
 public function __destruct()
 {
     if ($this->_redis) {
         $this->_redis->close();
     }
 }
Exemplo n.º 23
0
 /**
  * 关闭Redis
  *
  * @return void
  */
 public function close()
 {
     return $this->redis->close();
 }
Exemplo n.º 24
0
 /**
  * @return bool
  */
 public function close()
 {
     $result = TRUE;
     if ($this->connected && !$this->persistent) {
         try {
             $result = $this->standalone ? fclose($this->redis) : $this->redis->close();
             $this->connected = FALSE;
         } catch (Exception $e) {
             // Ignore exceptions on close
         }
     }
     return $result;
 }
Exemplo n.º 25
0
 /**
  * @return bool
  */
 public function close()
 {
     return parent::close();
 }
Exemplo n.º 26
0
 /**
  * @return bool
  */
 public function close()
 {
     $result = TRUE;
     if ($this->connected) {
         if ($this->standalone) {
             $result = fclose($this->redis);
         } else {
             $result = $this->redis->close();
         }
         $this->connected = FALSE;
     }
     return $result;
 }
Exemplo n.º 27
0
 public function op_redis($IP_Port, $key, $type)
 {
     $redis = new Redis();
     $redis->connect($IP_Port);
     if ($type == "str") {
         $res = $redis->get($key);
     }
     $redis->close();
     return "{\"" . $key . "\":\"" . $res . "\"}";
 }
Exemplo n.º 28
0
<?php

$redis = new Redis();
$r = $redis->connect('10.240.0.2', 6379, 1);
if ($r) {
    $key = $redis->incr('key');
    $redis->close();
    var_dump($key);
} else {
    header("HTTP/1.0 502 sys busy");
}
Exemplo n.º 29
0
 /**
  * Disconnects from the redis server
  */
 public function __destruct()
 {
     if (!$this->settings['persistent']) {
         $this->_Redis->close();
     }
 }
Exemplo n.º 30
-1
 public function __destruct()
 {
     // TODO: Implement __destruct() method.
     if (isset($this->redis) && $this->redis instanceof Redis) {
         $this->redis->close();
     }
 }