Upstash Documentation

ARGREP

Search array values with predicates.
3 min read

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#

ArgumentRequiredRepeatableDescription
<key>YesNoArray key targeted by the command.
<start>YesNoFirst index of the range, inclusive. - means the lowest possible index.
<end>YesNoLast index of the range, inclusive. + means the highest possible index.
EXACT <value>NoYesMatch slots whose value equals <value>.
MATCH <substring>NoYesMatch slots whose value contains <substring>.
GLOB <pattern>NoYesMatch slots whose value matches the glob <pattern>.
RE <regex>NoYesMatch slots whose value matches the regular expression <regex>.
(AND | OR)NoNoCombine several predicates. OR matches a slot when any predicate matches and is the default; AND requires all of them.
NOCASENoNoCompare case-insensitively.
WITHVALUESNoNoReturn index-value pairs instead of bare indexes.
LIMIT <limit>NoNoMaximum 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 (\1 through \9) are not supported.
  • AND and OR apply 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.

ProtocolReply
RESP2Array of indexes, or array of two-element index-value arrays with WITHVALUES
RESP3Array of indexes, or array of two-element index-value arrays with WITHVALUES
Note

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
Note

This command is not supported yet in @upstash/redis.

upstash_redis
Note

This command is not supported yet in upstash_redis.

ioredis
node-redis
redis-py
go-redis
jedis
redis-rs