本文整理汇总了PHP中Illuminate\Redis\Database类的典型用法代码示例。如果您正苦于以下问题:PHP Database类的具体用法?PHP Database怎么用?PHP Database使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Database类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createConnection
/**
* Create the given connection by name.
*
* @param string $name
* @return Illuminate\Redis\Database
*/
protected function createConnection($name)
{
$config = $this->getConfig($name);
$connection = new Database($config['host'], $config['port'], $config['database']);
$connection->connect();
return $connection;
}
示例2: __construct
public function __construct(SessionManager $manager, Database $db)
{
parent::__construct($manager);
$this->key = env('COMMON_SESSION');
$this->redis = $db->connection('common');
if ($this->redis === null) {
throw new ResourceNotFoundException('Redis Common Connection is not exists.');
}
}
示例3: command
/**
* Run a command against the Redis database.
*
* @param string $method
* @param array $parameters
* @return mixed
* @static
*/
public static function command($method, $parameters = array())
{
return \Illuminate\Redis\Database::command($method, $parameters);
}
示例4: psubscribe
/**
* Subscribe to a set of given channels with wildcards.
*
* @param array|string $channels
* @param \Closure $callback
* @param string $connection
* @return void
* @static
*/
public static function psubscribe($channels, $callback, $connection = null)
{
\Illuminate\Redis\Database::psubscribe($channels, $callback, $connection);
}
示例5:
function __construct(RedisDatabase $redis)
{
$this->redis = $redis->connection();
}
示例6: exists
/**
* @param Update $update
* @return bool
*/
public function exists(Update $update)
{
if (!$this->redis->exists($update->getMessage()->getChat()->getId())) {
return false;
}
return true;
}
示例7: deleteCacheGroup
/**
* @param $group
*/
protected function deleteCacheGroup($group)
{
$keys = $this->redis->keys($group . '*');
if (!empty($keys)) {
$this->redis->del($keys);
}
}
示例8: testDelete
public function testDelete()
{
$job = new RedisQueueIntegrationTestJob(30);
$this->queue->push($job);
/** @var RedisJob $redisJob */
$redisJob = $this->queue->pop();
$redisJob->delete();
$this->assertEquals(0, $this->redis->connection()->zcard('queues:default:delayed'));
$this->assertEquals(0, $this->redis->connection()->zcard('queues:default:reserved'));
$this->assertEquals(0, $this->redis->connection()->llen('queues:default'));
$this->assertNull($this->queue->pop());
}
示例9: command
/**
* Run a command against the Redis database.
*
* @param string $method
* @param array $args
* @return mixed
*/
public final function command($method, array $args = [])
{
if (in_array(strtolower($method), array_keys($this->storeEncoded))) {
$values = $this->storeEncoded[strtolower($method)];
$from = array_get($values, 'from', 0);
$to = array_get($values, 'to', max(0, count($args) - 1));
for ($i = $from; $i <= $to; $i++) {
$args[$i] = $this->encode($args[$i]);
}
}
if ($method == 'mset' || $method == 'msetnx') {
if (count($args) === 1 && is_array($args[0])) {
foreach ($args[0] as $k => $v) {
$args[0][$k] = $this->encode($v);
}
} else {
foreach ($args as $k => $v) {
if ($k % 2 != 0) {
$args[$k] = $this->encode($v);
}
}
}
}
if ($method == 'zadd') {
if (is_array(end($args))) {
foreach (array_pop($args) as $k => $v) {
$args[][$k] = $this->encode($v);
}
} else {
foreach ($arguments as $k => $v) {
if ($k !== 0 && $k % 2 == 0) {
$arguments[$k] = $this->encode($v);
}
}
}
}
if (in_array(strtolower($method), $this->returnDecoded)) {
$result = parent::command($method, $args);
if (is_array($result)) {
return array_map(function ($value) {
return $this->decode($value);
}, $result);
}
return $this->decode($result);
}
return parent::command($method, $args);
}
示例10: migrateExpiredJobs
/**
* Migrate the delayed jobs that are ready to the regular queue.
*
* @param string $from
* @param string $to
* @return void
*/
public function migrateExpiredJobs($from, $to)
{
$options = ['cas' => true, 'watch' => $from, 'retry' => 10];
$this->redis->transaction($options, function ($transaction) use($from, $to) {
// First we need to get all of jobs that have expired based on the current time
// so that we can push them onto the main queue. After we get them we simply
// remove them from this "delay" queues. All of this within a transaction.
$jobs = $this->getExpiredJobs($transaction, $from, $time = $this->getTime());
// If we actually found any jobs, we will remove them from the old queue and we
// will insert them onto the new (ready) "queue". This means they will stand
// ready to be processed by the queue worker whenever their turn comes up.
if (count($jobs) > 0) {
$this->removeExpiredJobs($transaction, $from, $time);
$this->pushExpiredJobsOntoNewQueue($transaction, $to, $jobs);
}
});
}
示例11: remove
/**
* Remove an item with a given key, index or value.
*
* @param string $key
* @param string $value
* @param string $type
* @return bool
*/
public function remove($key, $value, $type = null)
{
if (is_null($type)) {
$type = $this->type($key);
}
switch ($type) {
case 'list':
$key = str_replace(':queued', '', $key);
$random = Str::quickRandom(64);
$this->database->lset($key, $value, $random);
return $this->database->lrem($key, 1, $random);
case 'zset':
return $this->database->zrem($key, $value);
default:
throw new UnexpectedValueException("Unable to delete {$value} from {$key}. List type {$type} not supported.");
}
}
示例12: connection
/**
* Get the Redis connection instance.
*
* @return \Predis\ClientInterface
*/
public function connection()
{
return $this->redis->connection($this->connection);
}
示例13: getConnection
/**
* Get the connection for the queue.
*
* @return \Predis\ClientInterface
*/
protected function getConnection()
{
return $this->redis->connection($this->connection);
}
示例14: flush
/**
* Remove all items from the cache.
*
* @return void
*/
public function flush()
{
$this->redis->flushdb();
}
示例15: removeExpiredJobs
/**
* Remove the delayed jobs that are ready for processing.
*
* @param string $queue
* @param int $time
* @return void
*/
protected function removeExpiredJobs($queue, $time)
{
$this->redis->zremrangebyscore($queue, '-inf', $time);
}