ARGREP

ARGREP key start end
  <EXACT string | MATCH string | GLOB pattern | RE pattern [...]>
  [AND | OR | LIMIT limit | WITHVALUES | NOCASE [...]]
Available since:
Redis Open Source 8.8.0
Time complexity:
O(P * C) where P is the number of visited positions in touched slices and C is the cost of evaluating the predicates on one existing element.
ACL categories:
@array,

Searches array elements in a range using textual predicates and returns the indices of the matching elements. Empty slots in the range are skipped.

Required arguments

key

The name of the key that holds the array.

start

The zero-based integer index at which to begin searching. The special value - denotes the first index of the array. If start is greater than end, matches are returned in reverse index order.

end

The zero-based integer index at which to stop searching (inclusive). The special value + denotes the last index of the array.

predicate

One or more textual predicates to evaluate against each non-empty element in the range. Each predicate is one of:

  • EXACT string — Matches elements whose value is exactly equal to string.
  • MATCH string — Matches elements whose value contains string as a substring.
  • GLOB pattern — Matches elements whose value matches the glob-style pattern (with *, ?, and [...] wildcards), the same syntax used by KEYS and SCAN MATCH.
  • RE pattern — Matches elements whose value matches the regular expression pattern.

When more than one predicate is supplied, use the AND or OR option to control how they are combined. The default is OR.

Optional arguments

options

Zero or more of the following modifiers:

  • AND — Combine multiple predicates with logical AND. An element matches only if every predicate matches.
  • OR — Combine multiple predicates with logical OR. An element matches if any predicate matches. This is the default.
  • LIMIT limit — Stop after limit matches have been collected. limit must be a positive integer. When omitted, all matches in the range are returned.
  • WITHVALUES — In addition to each matching index, return the matching value. The reply becomes a flat list of alternating index-value pairs.
  • NOCASE — Perform case-insensitive comparisons for EXACT, MATCH, GLOB, and RE.

Examples

ARMSET log 0 "boot: ok" 1 "warn: disk" 2 "ERROR: cpu" 3 "info: ready" 4 "error: net" ARGREP log - + MATCH "error" NOCASE ARGREP log - + MATCH "error" NOCASE WITHVALUES ARGREP log 0 4 GLOB "warn:*" OR GLOB "error:*" ARGREP log 0 4 RE "^[A-Za-z]+: (cpu|net)$" NOCASE WITHVALUES ARGREP log 0 4 EXACT "info: ready" ARGREP log - + MATCH "error" NOCASE LIMIT 1

Return information

Array reply: Indices of the matching elements, in the same order in which the range is traversed (ascending when start <= end, descending when start > end). When WITHVALUES is given, a flat array of alternating index-value pairs: [idx1, val1, idx2, val2, ...]. An empty array is returned when the key does not exist or no element matches.
RATE THIS PAGE
Back to top ↑