CLI
RediSearch-PHP includes a CLI tool powered by Symfony Console. It lets you manage indexes, documents, and queries directly from the terminal — useful for debugging, exploration, and rapid prototyping.
Installation
Section titled “Installation”The CLI is included with the library. After installing via Composer, the binary is available at:
vendor/bin/redisearchRun it without arguments to see all available commands:
vendor/bin/redisearch listGlobal Options
Section titled “Global Options”All commands accept these connection options:
vendor/bin/redisearch <command> --host 127.0.0.1 --port 6379 --password secret --adapter predis| Option | Default | Description |
|---|---|---|
--host | 127.0.0.1 | Redis host |
--port / -p | 6379 | Redis port |
--password / -a | — | Redis password |
--adapter | predis | Adapter: predis, phpredis, or redisclient |
Index Management
Section titled “Index Management”Creating an Index
Section titled “Creating an Index”Create an index from a JSON schema file:
vendor/bin/redisearch index:create products schema.jsonThe schema file defines the fields for the index:
{ "fields": [ { "name": "title", "type": "TEXT", "weight": 2.0, "sortable": true }, { "name": "price", "type": "NUMERIC", "sortable": true }, { "name": "tags", "type": "TAG", "separator": "," }, { "name": "location", "type": "GEO" } ]}Supported field types: TEXT, NUMERIC, TAG, GEO, VECTOR.
Additional options:
vendor/bin/redisearch index:create products schema.json \ --on HASH \ --prefix "product:" \ --filter "@price > 0" \ --stopwords the a anListing Indexes
Section titled “Listing Indexes”vendor/bin/redisearch index:listvendor/bin/redisearch index:list --jsonViewing Index Info
Section titled “Viewing Index Info”vendor/bin/redisearch index:info productsvendor/bin/redisearch index:info products --jsonDropping an Index
Section titled “Dropping an Index”vendor/bin/redisearch index:drop productsvendor/bin/redisearch index:drop products --delete-docsDocument Management
Section titled “Document Management”Adding a Document
Section titled “Adding a Document”vendor/bin/redisearch document:add products doc1 title="Laptop" price=999 tags="electronics,computer"Use --replace to upsert, and optionally set language or score:
vendor/bin/redisearch document:add products doc1 title="Laptop Pro" price=1299 --replace --score 0.9Getting a Document
Section titled “Getting a Document”Retrieve a document by its full Redis key:
vendor/bin/redisearch document:get products doc1vendor/bin/redisearch document:get products doc1 --jsonDeleting a Document
Section titled “Deleting a Document”vendor/bin/redisearch document:delete products doc1Searching
Section titled “Searching”Run a full-text search query against an index:
vendor/bin/redisearch search products "laptop"Search Options
Section titled “Search Options”vendor/bin/redisearch search products "laptop" \ --limit 0,20 \ --sort price:ASC \ --fields title,price \ --highlight title \ --scores \ --json| Option | Format | Description |
|---|---|---|
--limit | offset,count | Paginate results (default 0,10) |
--sort | field:ASC|DESC | Sort by a sortable field |
--fields | field1,field2 | Return only specific fields |
--highlight | field1,field2 | Highlight matching terms |
--scores | flag | Include relevance scores |
--verbatim | flag | Disable stemming |
--language | name | Set stemming language |
--dialect | 1|2|3 | Query dialect version |
--json | flag | Output as JSON |
Filters
Section titled “Filters”Apply numeric, tag, or geo filters:
# Numeric filtervendor/bin/redisearch search products "laptop" --numeric-filter price:500:2000
# Tag filtervendor/bin/redisearch search products "*" --tag-filter tags:electronics,computer
# Geo filter (field:lon:lat:radius:unit)vendor/bin/redisearch search products "*" --geo-filter location:-73.9:40.7:10:kmFilters can be combined and repeated.
Aggregation
Section titled “Aggregation”Run aggregation queries with grouping and reducers:
vendor/bin/redisearch aggregate products "*" \ --group-by tags \ --reduce avg:price \ --reduce count \ --sort-by price:DESC \ --limit 0,10| Option | Format | Description |
|---|---|---|
--group-by | field | Group results by field |
--reduce | func:field | Apply reducer (repeatable) |
--sort-by | field:ASC|DESC | Sort aggregated results |
--apply | expr:alias | Apply expression |
--filter | expression | Filter aggregated results |
--limit | offset,count | Limit results |
--load | field1,field2 | Load additional fields |
--json | flag | Output as JSON |
Available reducers: avg, sum, min, max, count, count_distinct, count_distinctish, stddev, tolist, first_value.
Developer Tools
Section titled “Developer Tools”Query Explain
Section titled “Query Explain”View the execution plan for a query using FT.EXPLAIN:
vendor/bin/redisearch explain products "laptop"This helps understand how RediSearch parses and executes a query.
Query Profile
Section titled “Query Profile”Profile a query to see timing and execution details using FT.PROFILE:
vendor/bin/redisearch profile products "laptop"vendor/bin/redisearch profile products "laptop" --jsonInteractive Shell
Section titled “Interactive Shell”Start a REPL session for rapid experimentation:
vendor/bin/redisearch shell --host 127.0.0.1 --port 6379Example session:
redisearch> index:listredisearch> use productsredisearch (products)> search "laptop"redisearch (products)> explain "laptop"redisearch (products)> aggregate "*" --group-by tags --reduce countredisearch (products)> exitThe shell supports:
use <index>— set a default index so you don’t have to repeat ithelp— list available commandsexit/quit— leave the shell- Command history via readline
- Quoted strings for queries with spaces
JSON Output
Section titled “JSON Output”Most commands support --json for machine-readable output, making the CLI useful in scripts:
vendor/bin/redisearch search products "laptop" --json | jq '.documents[].title'