Home > Redis > Redis Learning Note – 04 Command in Redis (String)

Redis Learning Note – 04 Command in Redis (String)

In Readis, STRINGs are used to store three types of values:

  1. Byte string value.
  2. Integer value.
  3. Floating-point value.

Integers and floars can be incremented or decremented by an arbitary numeric value (integers turning into floats as necessary).

INCR key
Increment the integer value of a key by one. The string stored at the key is interpreted as a base-10 64 bit signed integer to execute the operation.
INCR

DECR key
Decrement the integer value of a key by one.
DECR

DECRBY key decrement
Decrement the integer value of a key by the given number.
DECRBY

INCRBY key increment
Increment the integer value of a key by the given amount.
INCRBY

INCRBYFLOAT key increment
Increment the float value of a key by the given amount. If the key does not exist, it is set to 0 before performing the operation. An error is returned if one of the following conditions occur:

  1. The key contains a value of the wrong type (not a string).
  2. The current key content or the specified increment are not parsable as a double precision floating point number.
    INCRBYFLOAT
APPEND key value
Append a value to a key. If key does not exist it is created and set as an empty string, so APPEND will be similar to SET in this special case.
APPEND
GETRANGE key start end
Get a substring of the string stored at a key. Negative offsets can be used in order to provide an offset starting from the end of the string. So -1 means the last character, -2 the penultimate and so forth.
GETRANE
SETRANGE key offset value
Overwrite part of a string at key starting at the specified offset. 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.
Note that the maximum offset that you can set is 229 -1 (536870911), as Redis Strings are limited to 512 megabytes. If you need to grow beyond this size, you can use multiple keys.
Note that once this first allocation is done, subsequent calls to SETRANGE for the same key will not have the allocation overhead.
SETRANGE
GETBIT key offset
Returns the bit value at offset in the string value stored at key.
GETBIT
SETBIT key offset value
Sets or clears the bit at offset in the string value stored at key.
SETBIT
BITCOUNT key [start end]
Count set bits in a string. Non-existent keys are treated as empty strings, so the command will return zero.
BITCOUNT
BITOP operation destkey key [key …]
Perform a bitwise operation between multiple keys (containing string values) and store the result in the destination key.
  1. BITOP AND destkey srckey1 srckey2 srckey3 … srckeyN
  2. BITOP OR destkey srckey1 srckey2 srckey3 … srckeyN
  3. BITOP XOR destkey srckey1 srckey2 srckey3 … srckeyN
  4. BITOP NOT destkey srckey
BITOP
References:
Categories: Redis
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: