Skip to content

Commit 1b277b5

Browse files
committed
[doc][redis] Add transport docs.
1 parent b6d3304 commit 1b277b5

File tree

2 files changed

+128
-1
lines changed

2 files changed

+128
-1
lines changed

docs/filesystem_transport.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Use files on local filesystem as queues.
44
It creates a file per queue\topic.
55
A message is a line inside the file.
6-
**Limitations** It works only in auto ack mode. Local by nature therefor messages are not visible on other servers.
6+
**Limitations** It works only in auto ack mode hence If consumer crashes the message is lost. Local by nature therefor messages are not visible on other servers.
77

88
* [Installation](#installation)
99
* [Create context](#create-context)

docs/redis_transport.md

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Redis transport
2+
3+
The transport uses [Redis](https://redis.io/) as a message broker.
4+
It creates a collection (a queue or topic) there. Pushes messages to the tail of the collection and pops from the head.
5+
The transport works with [phpredis](https://github.com/phpredis/phpredis) php extension or [predis](https://github.com/nrk/predis) library.
6+
Make sure you installed either of them
7+
8+
**Limitations** It works only in auto ack mode hence If consumer crashes the message is lost.
9+
10+
* [Installation](#installation)
11+
* [Create context](#create-context)
12+
* [Declare topic](#declare-topic)
13+
* [Declare queue](#decalre-queue)
14+
* [Bind queue to topic](#bind-queue-to-topic)
15+
* [Send message to topic](#send-message-to-topic)
16+
* [Send message to queue](#send-message-to-queue)
17+
* [Consume message](#consume-message)
18+
* [Purge queue messages](#purge-queue-messages)
19+
20+
## Installation
21+
22+
* With php redis extension:
23+
24+
```bash
25+
$ apt-get install php-redis
26+
$ composer require enqueue/redis
27+
```
28+
29+
* With predis library:
30+
31+
```bash
32+
$ composer require enqueue/redis predis/predis:^1
33+
```
34+
35+
## Create context
36+
37+
* With php redis extension:
38+
39+
```php
40+
<?php
41+
use Enqueue\Redis\RedisConnectionFactory;
42+
43+
$connectionFactory = new RedisConnectionFactory([
44+
'host' => 'localhost',
45+
'port' => 6379,
46+
'vendor' => 'phpredis',
47+
]);
48+
49+
$psrContext = $connectionFactory->createContext();
50+
```
51+
52+
* With predis library:
53+
54+
```php
55+
<?php
56+
use Enqueue\Redis\RedisConnectionFactory;
57+
58+
$connectionFactory = new RedisConnectionFactory([
59+
'host' => 'localhost',
60+
'port' => 6379,
61+
'vendor' => 'predis',
62+
]);
63+
64+
$psrContext = $connectionFactory->createContext();
65+
```
66+
67+
## Send message to topic
68+
69+
```php
70+
<?php
71+
/** @var \Enqueue\Redis\RedisContext $psrContext */
72+
73+
$fooTopic = $psrContext->createTopic('aTopic');
74+
$message = $psrContext->createMessage('Hello world!');
75+
76+
$psrContext->createProducer()->send($fooTopic, $message);
77+
```
78+
79+
## Send message to queue
80+
81+
```php
82+
<?php
83+
/** @var \Enqueue\Redis\RedisContext $psrContext */
84+
85+
$fooQueue = $psrContext->createQueue('aQueue');
86+
$message = $psrContext->createMessage('Hello world!');
87+
88+
$psrContext->createProducer()->send($fooQueue, $message);
89+
```
90+
91+
## Consume message:
92+
93+
```php
94+
<?php
95+
/** @var \Enqueue\Redis\RedisContext $psrContext */
96+
97+
$fooQueue = $psrContext->createQueue('aQueue');
98+
$consumer = $psrContext->createConsumer($fooQueue);
99+
100+
$message = $consumer->receive();
101+
102+
// process a message
103+
```
104+
105+
## Delete queue (purge messages):
106+
107+
```php
108+
<?php
109+
/** @var \Enqueue\Redis\RedisContext $psrContext */
110+
111+
$fooQueue = $psrContext->createQueue('aQueue');
112+
113+
$psrContext->deleteQueue($fooQueue);
114+
```
115+
116+
## Delete topic (purge messages):
117+
118+
```php
119+
<?php
120+
/** @var \Enqueue\Redis\RedisContext $psrContext */
121+
122+
$fooTopic = $psrContext->createTopic('aTopic');
123+
124+
$psrContext->deleteTopic($fooTopic);
125+
```
126+
127+
[back to index](index.md)

0 commit comments

Comments
 (0)