@@ -12,10 +12,62 @@ composer require macfja/redisearch
1212
1313## Usage
1414
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+
1567### Create a new index
1668
1769``` php
18- $client = new \Predis\Client( /* ... */) ;
70+ $client = /* ... */;
1971$builder = new \MacFJA\RediSearch\IndexBuilder();
2072
2173// Field can be create in advance
@@ -38,9 +90,9 @@ This will give you a new instance of the builder with the configured data.
3890### Add a document
3991
4092``` php
41- $client = new \Predis\Client( /* ... */) ;
93+ $client = /* ... */;
4294$index = new \MacFJA\RediSearch\Index('person', $client);
43- $index->addFromArray ([
95+ $index->addDocumentFromArray ([
4496 'firstname' => 'Joe',
4597 'lastname' => 'Doe',
4698 'age' => 30,
@@ -51,15 +103,15 @@ $index->addFromArray([
51103### Search
52104
53105``` php
54- $client = new \Predis\Client( /* ... */) ;
106+ $client = /* ... */;
55107$search = new \MacFJA\RediSearch\Redis\Command\Search();
56108
57109$search
58110 ->setIndex('person')
59111 ->setQuery('Doe')
60112 ->setHighlight(['lastname'])
61113 ->setWithScores();
62- $results = $client->executeCommand ($search);
114+ $results = $client->execute ($search);
63115```
64116
65117#### Create a search query
@@ -96,9 +148,8 @@ use MacFJA\RediSearch\Redis\Command\AggregateCommand\GroupByOption;
96148use MacFJA\RediSearch\Redis\Command\AggregateCommand\ReduceOption;
97149use MacFJA\RediSearch\Redis\Command\Search;
98150use MacFJA\RediSearch\Redis\Command\SugGet;
99- use Predis\Client;
100151
101- $client = new Client( /* ... */) ;
152+ $client = /* ... */;
102153
103154$query = '@age:[(17 +inf] %john%';
104155$search = new Search();
@@ -123,13 +174,7 @@ $suggestion->setDictionary('names')
123174 ->setPrefix('john')
124175 ->setFuzzy();
125176
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);
133178
134179// $result[0] is the search result
135180// $result[1] is the first aggregation result
0 commit comments