Redis - SPLessons

Redis String Commands

Home > Lesson > Chapter 7
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Redis String Commands

Redis String Commands

shape Description

The first and most basic data type is string data types. The strings in Redis doesn't have to be strings of text. Data stored as a string can basically contain any kind of data. A common use of strings in Redis is to store whole objects in a serialized format and can also append data to a string using APPEND. A common use of strings in Redis is to store whole objects is a serialized format. Normally this wouldn't make sense. But since Redis can't index or query data anyway there isn't much point in Redis in breading that data up.Unless the user want to store it in a hash. Strings also allow for low level bid operations and will actually set individual bits within the string to really save the bit. A sample of some of the most useful string commands that exists in Redis. And can also append data to a string using APPEND and if the string is a number and can utilize the INCR and DECR to increment or decrements a string values. Get range works like a sub strings, Which can return back part of the string values. MGET and MSET iets and get some set of multiple values at the same works of substrings.

String commands in Redis

shape Description

The following are the basic strings commands in Redis sever database.
1 Commands Description
1 Get key Get the value of a key
2 Set key values This command sets the values at the specified key
3 Get set key values Set the string values of a key and return its old values
4 Get range key start end Get a substring of the string stored at a key
5 Mget key1 [key2..] Get the values of all the given keys
6 Setbit key offset values Sets or clears the bits at bit at offset in the string values stored at key
7 Setex key seconds values Set the values with expiry of a key
8 Setnx key values Set the values with expiry of a key
9 Setnx key values Set the values of a key, only if the key doesn't exists
10 Strlen key Get the length of the values stored in a key
11 Mset key values[key values..] Set multiple keys to multiple values
12 Psetex key milliseconds values Set the values and expiration in milliseconds of a key
13 Incr key Increment the integer values of a key by one
14 Incrby key increment Increment the integer values of a key by the given amount
15 Decr key Decrement the integer values of a key by one
16 Decrby key decrement Decrement the integer values of a key by the given number
17 Append key values Append a value to a key

shape Syntax

The syntax for string command
redis 127.0.0.1:6379>COMMAND KEY_NAME

shape Examples

The below example describes the basic example for string key commands in Redis. [c] redis 127.0.0.1:6379> SET SPLessons redis OK redis 127.0.0.1:6379> GET SPLessons "redis" [/c]

Summary

shape Key Points

  • Redis String Commands - Is used to store whole objects in a serialized format.
  • Redis String Commands - Describes the basic strings commands in Redis.