@@ -12,10 +12,62 @@ composer require macfja/redisearch
12
12
13
13
## Usage
14
14
15
+ ### Get a Redis client
16
+
17
+ This lib can use several connector for Redis:
18
+ - [ Predis] ( https://github.com/predis/predis/wiki ) - Pure PHP implementation
19
+ - [ Phpredis] ( https://github.com/phpredis/phpredis ) - PHP extension
20
+ - [ Phpiredis] ( https://github.com/nrk/phpiredis ) - PHP extension depending on [ hiredis] ( https://github.com/redis/hiredis )
21
+ - [ Amp\Redis] ( https://github.com/amphp/redis ) - Pure PHP Async implementation
22
+ - [ cheprasov/php-redis-client] ( https://github.com/cheprasov/php-redis-client ) - Pure PHP implementation
23
+ - [ Credis] ( https://github.com/colinmollenhour/credis ) - Pure PHP implementation
24
+ - [ Rediska] ( https://github.com/Shumkov/Rediska ) - Pure PHP implementation
25
+ - [ Redisent] ( https://github.com/jdp/redisent ) - Pure PHP implementation
26
+ - [ TinyRedis] ( https://github.com/ptrofimov/tinyredisclient ) - Pure PHP implementation
27
+
28
+ You can pick the connector depending of your need.
29
+
30
+ ``` php
31
+ $clientFacade = new \MacFJA\RediSearch\Redis\Client\ClientFacade();
32
+
33
+ // With Predis
34
+ $client = $clientFacade->getClient(new \Predis\Client(/* ... */));
35
+
36
+ // With Phpredis extension
37
+ $client = $clientFacade->getClient(new \Redis([/* ... */]));
38
+
39
+ // With Phpiredis extension
40
+ $client = $clientFacade->getClient(phpiredis_connect($host));
41
+
42
+ // With Amp\Redis
43
+ $client = $clientFacade->getClient(new \Amp\Redis\Redis(new RemoteExecutor(Config::fromUri(/* ... */))));
44
+
45
+ // With Cheprasov
46
+ $client = $clientFacade->getClient(new \RedisClient\Client\Version\RedisClient6x0([/* ... */]));
47
+
48
+ // With Rediska
49
+ $client = $clientFacade->getClient(new \Rediska(['servers' => [[/* ... */]]]));
50
+
51
+ // With Redisent
52
+ $client = $clientFacade->getClient(new \redisent\Redis(/* ... */));
53
+
54
+ // With TinyRedisClient
55
+ $client = $clientFacade->getClient(new \TinyRedisClient(/* ... */));
56
+
57
+ // With Credis
58
+ $client = $clientFacade->getClient(new \Credis_Client(/* ... */));
59
+ ```
60
+
61
+ You can add your own implementation, all you need is to implement the interface ` \MacFJA\RediSearch\Redis\Client ` and add it to the client facace with:
62
+ ``` php
63
+ $clientFacade = new \MacFJA\RediSearch\Redis\Client\ClientFacade();
64
+ $clientFacade->addFactory(\MyVendor\MyPackage\MyRedisClient::class);
65
+ ```
66
+
15
67
### Create a new index
16
68
17
69
``` php
18
- $client = new \Predis\Client( /* ... */) ;
70
+ $client = /* ... */;
19
71
$builder = new \MacFJA\RediSearch\IndexBuilder();
20
72
21
73
// Field can be create in advance
@@ -38,9 +90,9 @@ This will give you a new instance of the builder with the configured data.
38
90
### Add a document
39
91
40
92
``` php
41
- $client = new \Predis\Client( /* ... */) ;
93
+ $client = /* ... */;
42
94
$index = new \MacFJA\RediSearch\Index('person', $client);
43
- $index->addFromArray ([
95
+ $index->addDocumentFromArray ([
44
96
'firstname' => 'Joe',
45
97
'lastname' => 'Doe',
46
98
'age' => 30,
@@ -51,15 +103,15 @@ $index->addFromArray([
51
103
### Search
52
104
53
105
``` php
54
- $client = new \Predis\Client( /* ... */) ;
106
+ $client = /* ... */;
55
107
$search = new \MacFJA\RediSearch\Redis\Command\Search();
56
108
57
109
$search
58
110
->setIndex('person')
59
111
->setQuery('Doe')
60
112
->setHighlight(['lastname'])
61
113
->setWithScores();
62
- $results = $client->executeCommand ($search);
114
+ $results = $client->execute ($search);
63
115
```
64
116
65
117
#### Create a search query
@@ -96,9 +148,8 @@ use MacFJA\RediSearch\Redis\Command\AggregateCommand\GroupByOption;
96
148
use MacFJA\RediSearch\Redis\Command\AggregateCommand\ReduceOption;
97
149
use MacFJA\RediSearch\Redis\Command\Search;
98
150
use MacFJA\RediSearch\Redis\Command\SugGet;
99
- use Predis\Client;
100
151
101
- $client = new Client( /* ... */) ;
152
+ $client = /* ... */;
102
153
103
154
$query = '@age:[(17 +inf] %john%';
104
155
$search = new Search();
@@ -123,13 +174,7 @@ $suggestion->setDictionary('names')
123
174
->setPrefix('john')
124
175
->setFuzzy();
125
176
126
- $result = $client->pipeline()
127
- ->executeCommand($search)
128
- ->executeCommand($stats)
129
- ->executeCommand($aggregate)
130
- ->executeCommand($suggestion)
131
- ->execute()
132
- ;
177
+ $result = $client->pipeline($search, $stats, $aggregate, $suggestion);
133
178
134
179
// $result[0] is the search result
135
180
// $result[1] is the first aggregation result
0 commit comments