Skip to content

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.

The CLI is included with the library. After installing via Composer, the binary is available at:

Terminal window
vendor/bin/redisearch

Run it without arguments to see all available commands:

Terminal window
vendor/bin/redisearch list

All commands accept these connection options:

Terminal window
vendor/bin/redisearch <command> --host 127.0.0.1 --port 6379 --password secret --adapter predis
OptionDefaultDescription
--host127.0.0.1Redis host
--port / -p6379Redis port
--password / -aRedis password
--adapterpredisAdapter: predis, phpredis, or redisclient

Create an index from a JSON schema file:

Terminal window
vendor/bin/redisearch index:create products schema.json

The 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:

Terminal window
vendor/bin/redisearch index:create products schema.json \
--on HASH \
--prefix "product:" \
--filter "@price > 0" \
--stopwords the a an
Terminal window
vendor/bin/redisearch index:list
vendor/bin/redisearch index:list --json
Terminal window
vendor/bin/redisearch index:info products
vendor/bin/redisearch index:info products --json
Terminal window
vendor/bin/redisearch index:drop products
vendor/bin/redisearch index:drop products --delete-docs
Terminal window
vendor/bin/redisearch document:add products doc1 title="Laptop" price=999 tags="electronics,computer"

Use --replace to upsert, and optionally set language or score:

Terminal window
vendor/bin/redisearch document:add products doc1 title="Laptop Pro" price=1299 --replace --score 0.9

Retrieve a document by its full Redis key:

Terminal window
vendor/bin/redisearch document:get products doc1
vendor/bin/redisearch document:get products doc1 --json
Terminal window
vendor/bin/redisearch document:delete products doc1

Run a full-text search query against an index:

Terminal window
vendor/bin/redisearch search products "laptop"
Terminal window
vendor/bin/redisearch search products "laptop" \
--limit 0,20 \
--sort price:ASC \
--fields title,price \
--highlight title \
--scores \
--json
OptionFormatDescription
--limitoffset,countPaginate results (default 0,10)
--sortfield:ASC|DESCSort by a sortable field
--fieldsfield1,field2Return only specific fields
--highlightfield1,field2Highlight matching terms
--scoresflagInclude relevance scores
--verbatimflagDisable stemming
--languagenameSet stemming language
--dialect1|2|3Query dialect version
--jsonflagOutput as JSON

Apply numeric, tag, or geo filters:

Terminal window
# Numeric filter
vendor/bin/redisearch search products "laptop" --numeric-filter price:500:2000
# Tag filter
vendor/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:km

Filters can be combined and repeated.

Run aggregation queries with grouping and reducers:

Terminal window
vendor/bin/redisearch aggregate products "*" \
--group-by tags \
--reduce avg:price \
--reduce count \
--sort-by price:DESC \
--limit 0,10
OptionFormatDescription
--group-byfieldGroup results by field
--reducefunc:fieldApply reducer (repeatable)
--sort-byfield:ASC|DESCSort aggregated results
--applyexpr:aliasApply expression
--filterexpressionFilter aggregated results
--limitoffset,countLimit results
--loadfield1,field2Load additional fields
--jsonflagOutput as JSON

Available reducers: avg, sum, min, max, count, count_distinct, count_distinctish, stddev, tolist, first_value.

View the execution plan for a query using FT.EXPLAIN:

Terminal window
vendor/bin/redisearch explain products "laptop"

This helps understand how RediSearch parses and executes a query.

Profile a query to see timing and execution details using FT.PROFILE:

Terminal window
vendor/bin/redisearch profile products "laptop"
vendor/bin/redisearch profile products "laptop" --json

Start a REPL session for rapid experimentation:

Terminal window
vendor/bin/redisearch shell --host 127.0.0.1 --port 6379

Example session:

redisearch> index:list
redisearch> use products
redisearch (products)> search "laptop"
redisearch (products)> explain "laptop"
redisearch (products)> aggregate "*" --group-by tags --reduce count
redisearch (products)> exit

The shell supports:

  • use <index> — set a default index so you don’t have to repeat it
  • help — list available commands
  • exit / quit — leave the shell
  • Command history via readline
  • Quoted strings for queries with spaces

Most commands support --json for machine-readable output, making the CLI useful in scripts:

Terminal window
vendor/bin/redisearch search products "laptop" --json | jq '.documents[].title'