Laravel Queues

&

High Availability 

Moving Away From Sync

Letting someone else manage your data

Managing your own data

Beanstalkd

Moving Away From Sync

Beanstalkd

  • Simple queueing service

  • In-memeory container for your jobs

  • It just holds your jobs

Redis

So what is redis?

  • Remote Dictionary Server
  • Advanced key-value cache and store
  • In-memeory service but not just for queues
  • Transactions, Pub/Sub, Keys with Limited-Time-To-Live, and Automatic Failover
  • Multiple redis instances that are interconnected 
  • Redis Cluster is still in beta
  • Automatically split your dataset across nodes
  • Continue operations when some of the nodes are failing

Redis Cluster

For More checkout redis.io

Redis Cluster

  • Monitoring
  • Notification

  • Automatic failover
  • Configuration provider

Redis & High Availability

Redis 

& Sentinel

Laravel & Redis


   Redis::set('foo', 'Foo Value');
 
   $foo = Redis::get('foo');

   Redis::del('foo');

You have the full range of redis commands

http://redis.io/commands


   $redis->set('foo', $value);

   
   
   $redis = Redis::connection(); // default connection

   $redis = Redis::connection('other-connection');
   
   $redis->command('del', $key);

Laravel & Redis

That's not all

Laravel Redis Drivers

Cacheing

Queueing

What about working with a redis cluster?

Sessions

What about High Availability  with Sentinel?

Indatus/Laravel-PSRedis

Laravel, PHP, Sentinel, and Redis

The Solution

  • Install it
  • Configure it
  • Add the Service Provider

Setting it up

The Redis Service Provider

Laravel's Redis Queue

   <?php namespace Illuminate\Queue;  
 
   class RedisQueue extends Queue implements QueueInterface {

	/**
	 * Create a new Redis queue instance.
	 *
	 * @param  \Illuminate\Redis\Database  $redis
	 * @param  string  $default
	 * @param  string  $connection
	 * @return void
	 */
	public function __construct(Database $redis, $default = 'default', $connection = null)
	{
		$this->redis = $redis;
		$this->default = $default;
		$this->connection = $connection;
	}

        ...
   }

HOw it works

Sparkcentral/PSRedis

Sentinel Wrapper for PHP Redis Clients

It talks to sentinel instead of redis

Replaces the Redis Service Provider

Damien Russell

Laravel Queues & High Availability

By Damien Russell

Laravel Queues & High Availability

Slides for my talk a Laravel Louisville ( March 2015 )

  • 2,985