Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

SETRANGE

Josh Baker edited this page Oct 11, 2016 · 7 revisions

SETRANGE key offset value

Overwrites part of the string stored at key, starting at the specified offset, for the entire length of value. If the offset is larger than the current length of the string at key, the string is padded with zero-bytes to make offset fit. Non-existing keys are considered as empty strings, so this command will make sure it holds a string large enough to be able to set value at offset.

Return value

Integer reply: the length of the string after it was modified by the command.

Examples

Basic usage:

> SET key1 "Hello World"
OK
> SETRANGE key1 6 "Redis"
(integer) 11
> GET key1
"Hello Redis"

Example of zero padding:

> SETRANGE key2 6 "Redis"
(integer) 11
> GET key2
"\u0000\u0000\u0000\u0000\u0000\u0000Redis"

Related Commands

APPEND, BITCOUNT, BITOP, BITPOS, DBSIZE, DECR, DECRBY, DEL, EXISTS, EXPIRE, EXPIREAT, FLUSHDB, GET, GETBIT, GETRANGE, GETSET, INCR, INCRBY, INCRBYFLOAT, KEYS, MGET, MSET, MSETNX, PDEL, PERSIST, PEXPIRE, PEXPIREAT, PTTL, RENAME, RENAMENX, SET, SETBIT, SETRANGE, STRLEN, TTL

Clone this wiki locally