ARGET
Since 1.1.0Arrays
Syntax
ARGET key indexReturns the value at index in the array at key. Indexes are whole numbers from 0; negative indexes are not accepted, since a sparse array has no meaningful last element for -1 to name. Reading an empty slot, or a missing key, gives nil, so ARGET cannot tell an empty slot from a missing array: use EXISTS or ARCOUNT for that.
To read several slots, use ARMGET for chosen indexes, ARGETRANGE for a run of them with nil for the empty ones, or ARSCAN for only the filled slots in a range.
Reply
- The value, as a bulk string.
nilif the slot is empty or the key does not exist.
Errors
ERR invalid array indexfor an index that is negative or not a whole number.WRONGTYPEif the key holds a value that is not an array.
Examples
> ARSET a 0 x y z
(integer) 3
> ARGET a 1
"y"
> ARGET a 3
(nil)
> ARGET nokey 0
(nil)
> ARGET a -1
(error) ERR invalid array index