Redis String: Getrange
Redis GETRANGE Command
Redis GETRANGE command is used to get the substring of the string value stored at key, determined by the offsets start and end (both are inclusive). Negative offsets can be used in order to provide an offset starting from the end of the string.
The function handles out of range requests by limiting the resulting range to the actual length of the string.
Here are some common uses and scenarios for the "GETRANGE" command:
- Partial Data Retrieval: Fetch only a portion of a string value, which can save bandwidth.
- String Manipulation: Extract specific segments of a string for further processing.
- Data Parsing: Retrieve and parse specific parts of a serialized data format.
- Efficient Reads: Access large strings more efficiently by reading only the required segments.
Syntax:
GETRANGE KEY_NAME start end
Available since
2.4.0.
Return Value
Simple string reply.
Return Value Type
String
Example: Redis GETRANGE
First, set a key in redis and then get some part of it.
redis 127.0.0.1:6379> SET mykey "This is my test key" OK redis 127.0.0.1:6379> GETRANGE mykey 0 3 "This" redis 127.0.0.1:6379> GETRANGE mykey 0 -1 "This is my test key"
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/redis/redis-getrange-key-start-end.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics