-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: How to check if an index is already exisiting? #61
Comments
You can use the use MacFJA\RediSearch\Redis\Command\IndexList;
$list = $client->execute(new IndexList());
if (!in_array($index_name, $list, true)) {
// Create index
} It's what I have done in the side library: https://github.com/MacFJA/php-redisearch-integration/blob/main/src/ObjectWorker.php#L227 (But it also checks if the index definition is in sync with Redis)
Yes, it's how is should be done. |
You can also look at the Unit Tests:
As the code coverage is high (97% of lines), in most case, there is, at least, one test that cover a functionality |
You rock! Thanks.
Strangely enough my VSC didn't pick up on these but I saw them in the IndexBuilder :) Next stop: getting it all into Slim4. About the setTemporary() agument, one of the other repos' stated it would be/could be reset on each visit, so as long at it is used it will reset to n-time / restart instead of expiring. Is that the case here as well? If not we'll make it last longer. |
Not sure if the time-out works though, see image. Here's one added the normal way, which does work: EDIT (again, sorry): it's a few hours later and those keys seem to be gone after all. Must be some misrepresentation in Redis stack browser. The keys have no expiration, but the entire index of course has. Maybe it helps future confused folks like myself :) |
Any chance there's a list of what results we can esasily retrieve from the |
Yes, it's not the document that have expiration, but the index itself
It's impossible to have the typing as the
For those cases, you can use The response of the rest of command are generally just Except for commands where results are a bit complex, the library is just a fine wrapper around the raw Redis command |
Thanks. I'm working my way to better understanding this Redisearch engine small steps at a time before I'm rolling this out to our project. I'm just trying to get the returned result into an array of keys/values. I can print_r the results fine, but I'm not too experienced in Instances and how they operate (I'm from PHP3+ so I'm stuck to old non OOP mindsets, trying to better myself ;-)).
Thanks again, I'll try some of the things mentioned. |
The result of a In the sister library I create an iterator to help to retrieve all the result: https://github.com/MacFJA/php-redisearch-integration/blob/main/src/Iterator/ResponseItemIterator.php: you put the command result into the |
If you mean something like this, then that does not work (Fatal error: Uncaught Error: Class "ResponseItemIterator" not found).
I feel like an idiot about now, so I'm moving on to storing data in our MySQL DB, that'll take me 5 minutes to do instead of days :). Earlier, I also got errors on trying a search like this: Thanks again for your time, effort and help. |
You need to install an extra package: https://packagist.org/packages/macfja/redisearch-integration to be able to use the
To enable command aliases, you need to register them as describe here: https://github.com/MacFJA/php-redisearch#use-predis-v1x-shorthand-syntax |
Right now, if you click refresh page you will get an error the index exists:
Fatal error: Uncaught Predis\Response\ServerException: Index already exists in /var/www/html/vendor/predis/predis/src/Client.php
Any way to verify if it already exists and if so, move on to setting the index without creating it First? Try/Catch didn't work.
EDIT:
Adding a question since it's not documented :-). It this the correct way to add arguments?
The text was updated successfully, but these errors were encountered: