forked from php-enqueue/enqueue-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to pass password, add ability to pass redis instance.
- Loading branch information
Showing
5 changed files
with
94 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ Make sure you installed either of them | |
* [Consume message](#consume-message) | ||
* [Delete queue (purge messages)](#delete-queue-purge-messages) | ||
* [Delete topic (purge messages)](#delete-topic-purge-messages) | ||
* [Connect Heroku Redis](#connect-heroku-redis) | ||
|
||
## Installation | ||
|
||
|
@@ -61,6 +62,12 @@ $psrContext = $factory->createContext(); | |
|
||
// if you have enqueue/enqueue library installed you can use a function from there to create the context | ||
$psrContext = \Enqueue\dsn_to_context('redis:'); | ||
|
||
// pass redis instance directly | ||
$redis = new \Enqueue\Redis\PhpRedis([ /** redis connection options */ ]); | ||
$redis->connect(); | ||
|
||
$factory = new RedisConnectionFactory($redis); | ||
``` | ||
|
||
* With predis library: | ||
|
@@ -155,4 +162,17 @@ $fooTopic = $psrContext->createTopic('aTopic'); | |
$psrContext->deleteTopic($fooTopic); | ||
``` | ||
|
||
## Connect Heroku Redis | ||
|
||
[Heroku Redis](https://devcenter.heroku.com/articles/heroku-redis) describes how to setup Redis instance on Heroku. | ||
To use it with Enqueue Redis you have to pass REDIS_URL to RedisConnectionFactory constructor. | ||
|
||
```php | ||
<?php | ||
|
||
// REDIS_URL: redis://h:[email protected]:111 | ||
|
||
$connection = new \Enqueue\Redis\RedisConnectionFactory(getenv('REDIS_URL')); | ||
``` | ||
|
||
[back to index](../index.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
namespace Enqueue\Redis\Tests; | ||
|
||
use Enqueue\Redis\Redis; | ||
use Enqueue\Redis\RedisConnectionFactory; | ||
use Enqueue\Test\ClassExtensionTrait; | ||
use PHPUnit\Framework\TestCase; | ||
|
@@ -45,6 +46,17 @@ public function testThrowIfVendorIsInvalid() | |
new RedisConnectionFactory(['vendor' => 'invalidVendor']); | ||
} | ||
|
||
public function testCouldBeCreatedWithRedisInstance() | ||
{ | ||
$redisMock = $this->createMock(Redis::class); | ||
|
||
$factory = new RedisConnectionFactory($redisMock); | ||
$this->assertAttributeSame($redisMock, 'redis', $factory); | ||
|
||
$context = $factory->createContext(); | ||
$this->assertSame($redisMock, $context->getRedis()); | ||
} | ||
|
||
/** | ||
* @dataProvider provideConfigs | ||
* | ||
|
@@ -141,5 +153,24 @@ public static function provideConfigs() | |
'redis' => null, | ||
], | ||
]; | ||
|
||
// heroku redis | ||
yield [ | ||
'redis://h:[email protected]:111', | ||
[ | ||
'host' => 'ec2-111-1-1-1.compute-1.amazonaws.com', | ||
'port' => 111, | ||
'timeout' => null, | ||
'reserved' => null, | ||
'retry_interval' => null, | ||
'vendor' => 'phpredis', | ||
'persisted' => false, | ||
'lazy' => false, | ||
'database' => 0, | ||
'redis' => null, | ||
'user' => 'h', | ||
'pass' => 'asdfqwer1234asdf', | ||
], | ||
]; | ||
} | ||
} |