SETRANGE

Apply for Redis Developer Course Redis Regular Inspection / Technical Support Redis Enterprise Server

Write data at a specified position

Writes data starting at the specified position. Offset starts from 0.
Usage is setrange key offset value.

Example

Command>set key "This is MySQL Server"
Result>OK
Command>setrange key 8 Redis
Result>20
Command>get key
Result>This is Redis Server

View animation

offset cannot be negative.

Memory Usage Test

Memory usage bytes

MegabytesBytesPower of 2
2MB2,097,151221 -1
4MB4,194,303222 -1
8MB8,388,607223 -1
16MB16,777,215224 -1
32MB33,554,431225 -1
64MB67,108,863226 -1
128MB134,217,727227 -1
256MB268,435,455228 -1
512MB536,870,911229 -1

Redis Server 3.2.2 and CentOS 7

CommandsIncrease size(MB)Increase size(bytes)Return value
setrange key2 2097151 R2.5MB2,621,5202,097,152
setrange key4 4194303 R5MB5,242,9604,194,304
setrange key8 8388607 R10MB10,485,8408,388,608
setrange key16 16777215 R20MB20,971,60016,777,216
setrange key32 33554431 R40MB41,943,12033,554,432
setrange key64 67108863 R80MB83,886,37667,108,864
setrange key124 134217727 R160MB167,772,456134,217,728
setrange key256 268435455 R320MB335,544,616268,435,456
setrange key512 536870911 R640MB671,088,936536,870,912

If you enter 536,870,912 bytes (229), the following error occurs.   That is why the table uses a power of 2 minus 1.

127.0.0.1:7000> setrange key512 536870912 R
(error) ERR string exceeds maximum allowed size (512MB)


Syntax

SETRANGE key offset value

  • Available since version 2.2.0.
  • Time complexity depends on the string being processed.
    For a short string it can be treated as O(1); for a long string it is O(M), where M is the length of the value.
Related commands SET, GETRANGE, STRLEN
Clients for Java Jedis, Lettuce, Redisson
Clients for C Hiredis

<< STRLEN SETRANGE GETRANGE >>

Email 답글이 올라오면 이메일로 알려드리겠습니다.