本文整理汇总了PHP中Redis::setOption方法的典型用法代码示例。如果您正苦于以下问题:PHP Redis::setOption方法的具体用法?PHP Redis::setOption怎么用?PHP Redis::setOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Redis
的用法示例。
在下文中一共展示了Redis::setOption方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: clear
public function clear($prefix = '')
{
$prefix = $this->getNamespace() . $prefix . '*';
$it = null;
self::$cache->setOption(\Redis::OPT_SCAN, \Redis::SCAN_RETRY);
while ($keys = self::$cache->scan($it, $prefix)) {
self::$cache->delete($keys);
}
return true;
}
示例2: initializeCAS
private function initializeCAS()
{
$casClient = new \CAS_Client(CAS_VERSION_2_0, true, Config::get('cas.hostname'), Config::get('cas.port'), Config::get('cas.context'));
$casClient->setNoCasServerValidation();
if (true === Config::get('pgtservice.enabled', false)) {
$casClient->setCallbackURL(Config::get('pgtservice.callback'));
$casClient->setPGTStorage(new ProxyTicketServiceStorage($casClient));
} else {
if (false !== Config::get('redis.hostname', false)) {
$casClient->setCallbackURL($this->url->getURL() . '/callback.php');
$redis = new \Redis();
$redis->connect(Config::get('redis.hostname'), Config::get('redis.port', 6379), 2, null, 100);
$redis->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_PHP);
$redis->setOption(\Redis::OPT_PREFIX, Config::get('application.project_name') . ':PHPCAS_TICKET_STORAGE:');
$redis->select((int) Config::get('redis.hostname', 2));
$casClient->setPGTStorage(new RedisTicketStorage($casClient, $redis));
} else {
$casClient->setCallbackURL($this->url->getURL() . '/callback.php');
$casClient->setPGTStorageFile(session_save_path());
// Handle logout requests but do not validate the server
$casClient->handleLogoutRequests(false);
}
}
// Accept all proxy chains
$casClient->getAllowedProxyChains()->allowProxyChain(new \CAS_ProxyChain_Any());
return $casClient;
}
示例3: __construct
/**
* Constructor.
*
* @param string $uniqId to be used to separate objects in addition to their key identifiers, for instance in a
* multi-user scenario.
*
* @return \iveeCrest\RedisWrapper
*/
public function __construct($uniqId)
{
$this->redis = new \Redis();
$this->redis->connect(Config::getCacheHost(), Config::getCachePort());
$this->redis->setOption(\Redis::OPT_PREFIX, Config::getCachePrefix());
$this->uniqId = $uniqId;
}
示例4: __construct
/**
* @param string $host redis server host
* @param int $port redis server port
* @param int $database redis server database num
* @param string $channel redis queue key
* @param string $prefix prefix of redis queue key
*/
public function __construct($host = '127.0.0.1', $port = 6379, $database = 0, $channel = 'cache', $prefix = 'simple-fork-')
{
$this->redis = new \Redis();
$connection_result = $this->redis->connect($host, $port);
if (!$connection_result) {
throw new \RuntimeException('can not connect to the redis server');
}
if ($database != 0) {
$select_result = $this->redis->select($database);
if (!$select_result) {
throw new \RuntimeException('can not select the database');
}
}
if (empty($channel)) {
throw new \InvalidArgumentException('channel can not be empty');
}
$this->channel = $channel;
if (empty($prefix)) {
return;
}
$set_option_result = $this->redis->setOption(\Redis::OPT_PREFIX, $prefix);
if (!$set_option_result) {
throw new \RuntimeException('can not set the \\Redis::OPT_PREFIX Option');
}
}
示例5: init
function init()
{
list($ip, $port) = explode(':', $this->_defaults['server']);
$this->_handler = new Redis();
$this->_handler->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_IGBINARY);
$this->_handler->connect($ip, $port);
}
示例6: init
/**
* @return void
*/
protected function init()
{
$this->prefix = sprintf("%s#", base64_encode($this->identifier));
$this->client = new \Redis();
call_user_func_array([$this->client, 'connect'], func_get_args());
$this->client->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_PHP);
$this->client->setOption(\Redis::OPT_PREFIX, $this->prefix);
}
示例7: autoInit
/**
* If you want to use your own instance of Redis then pass it to UaiCachePhpredis::$redis before calling UserAgentInfoPeer for the first time.
*/
public static function autoInit()
{
if (self::$redis instanceof Redis) {
return;
}
self::$redis = new Redis();
self::$redis->pconnect('127.0.0.1');
self::$redis->setOption(Redis::OPT_SERIALIZER, UserAgentInfoConfig::CACHE_USE_IGBINARY ? Redis::SERIALIZER_IGBINARY : Redis::SERIALIZER_PHP);
}
示例8: __construct
public function __construct($connectionOrHost, $port = 6379)
{
if ($connectionOrHost instanceof \Redis) {
$this->connection = $connectionOrHost;
} else {
$this->connection = new \Redis();
$this->connection->connect($connectionOrHost, $port);
$this->connection->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_PHP);
}
}
示例9: register
public function register(Container $pimple)
{
$pimple['redis'] = function () use($pimple) {
$redis = new \Redis();
$options = $pimple['redis.options'];
$redis->connect($options['host'], $options['port'], $options['timeout']);
$redis->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_NONE);
$redis->setOption(\Redis::OPT_PREFIX, $options['dbname'] . ':');
$redis->auth($options['password']);
return $redis;
};
}
示例10: _connect
protected function _connect()
{
$this->_redis = new \Redis();
if ($this->_config['persistent']) {
$this->_redis->pconnect($this->_config['host'], isset($this->_config['port']) ? $this->_config['port'] : null, isset($this->_config['timeout']) ? $this->_config['timeout'] : null);
} else {
$this->_redis->connect($this->_config['host'], isset($this->_config['port']) ? $this->_config['port'] : null, isset($this->_config['timeout']) ? $this->_config['timeout'] : null);
}
$this->_redis->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_NONE);
if ($this->_config['database'] > 0) {
$this->_redis->select($this->_config['database']);
}
}
示例11: getInstance
/**
* @return \Redis
*/
public function getInstance()
{
if (is_null($this->instance)) {
$this->instance = new \Redis();
$this->instance->connect('localhost');
/**
* Without it doesn't work with array type
*/
$serializer = defined('Redis::SERIALIZER_IGBINARY') ? \Redis::SERIALIZER_IGBINARY : \Redis::SERIALIZER_PHP;
$this->instance->setOption(\Redis::OPT_SERIALIZER, $serializer);
return $this->instance;
}
return $this->instance;
}
示例12: getRedis
/**
* @return \Redis
* @throws InvalidConfigException
*/
public function getRedis()
{
if (null === $this->instance) {
if (!extension_loaded('redis')) {
throw new InvalidConfigException(__CLASS__ . ' requires PHP `redis` extension to be loaded.');
}
$this->instance = new \Redis();
if (!empty($this->options)) {
foreach ($this->options as $key => $value) {
$this->instance->setOption($key, $value);
}
}
}
return $this->instance;
}
示例13: getClient
/**
* Gets the redis client
* @return Redis the redis client
*/
public function getClient()
{
if ($this->_client === null) {
$this->_client = new Redis();
$this->_client->connect($this->hostname, $this->port);
if (isset($this->password)) {
if ($this->_client->auth($this->password) === false) {
throw new CException('Redis authentication failed!');
}
}
$this->_client->setOption(Redis::OPT_PREFIX, $this->prefix);
$this->_client->select($this->database);
}
return $this->_client;
}
示例14: subscribe
/**
* @param string|string[] $channels
* @param Closure $callback
*/
public function subscribe($channels, Closure $callback)
{
$channels = (array) $channels;
$this->_subscribeCallback = $callback;
$this->_redis->setOption(Redis::OPT_READ_TIMEOUT, 86400 * 100);
$this->_redis->subscribe($channels, array($this, '_subscribeCallback'));
}
示例15: __construct
/**
* Constructs the redis Kohana_Cache object
*
* @param array configuration
* @throws Kohana_Cache_Exception
*/
protected function __construct(array $config)
{
if (!extension_loaded('redis')) {
throw new Cache_Exception('PHP redis extension is not available.');
}
parent::__construct($config);
$host = isset($config['host']) ? $config['host'] : $this->_default_config['host'];
$port = isset($config['port']) ? $config['port'] : $this->_default_config['port'];
$this->_redis = new Redis();
$this->_redis->connect($host, $port, 1);
if (@$config['igbinary_serialize'] === true) {
$this->_redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_IGBINARY);
}
$db_num = isset($config['db_num']) ? $config['db_num'] : $this->_default_config['db_num'];
$this->_redis->select($db_num);
}