Use ARGREP to find the array slots whose value matches one or more predicates.
Each predicate is a keyword and a pattern: EXACT compares the whole value, MATCH looks for a substring, GLOB applies a glob pattern with * and ?, and RE applies a regular expression. Several predicates can be given in one call; by default a slot matches when any of them matches, and AND switches that to requiring all of them. NOCASE makes every predicate in the call case-insensitive.
The bounds accept - and + as shorthand for the first and last possible index, so a whole array can be searched without knowing its extent. By default the reply is the list of matching indexes; WITHVALUES returns index-value pairs instead, which saves a follow-up ARMGET when you need the data as well as its position.
See the array command overview for the data model these commands share.
Syntax#
Arguments#
| Argument | Required | Repeatable | Description |
|---|---|---|---|
<key> | Yes | No | Array key targeted by the command. |
<start> | Yes | No | First index of the range, inclusive. - means the lowest possible index. |
<end> | Yes | No | Last index of the range, inclusive. + means the highest possible index. |
EXACT <value> | No | Yes | Match slots whose value equals <value>. |
MATCH <substring> | No | Yes | Match slots whose value contains <substring>. |
GLOB <pattern> | No | Yes | Match slots whose value matches the glob <pattern>. |
RE <regex> | No | Yes | Match slots whose value matches the regular expression <regex>. |
(AND | OR) | No | No | Combine several predicates. OR matches a slot when any predicate matches and is the default; AND requires all of them. |
NOCASE | No | No | Compare case-insensitively. |
WITHVALUES | No | No | Return index-value pairs instead of bare indexes. |
LIMIT <limit> | No | No | Maximum number of matches to return. Must be greater than 0. |
Important points#
- At least one predicate is required, and a call may carry at most 250 of them.
- A regular expression may be at most 2048 bytes long, and backreferences (
\1through\9) are not supported. ANDandORapply to the whole call, not to the predicate they follow.
Response#
The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.
| Protocol | Reply |
|---|---|
| RESP2 | Array of indexes, or array of two-element index-value arrays with WITHVALUES |
| RESP3 | Array of indexes, or array of two-element index-value arrays with WITHVALUES |
Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.
Examples#
TCP examples use the TLS REDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.
Redis CLI
@upstash/redis
This command is not supported yet in @upstash/redis.
upstash_redis
This command is not supported yet in upstash_redis.