Redis – String Set Command

  • Post author:
  • Post category:Redis
  • Post comments:1 Comment

Redis SET command is used to set some string value in Redis key.

Return Value

Simple string reply. OK, if the value is set in the key. Null, if the value does not set.

Syntax

Following is the basic syntax of Redis SET command.

redis 127.0.0.1:6379> SET KEY_NAME VALUE

Example

redis 127.0.0.1:6379> SET Adglob redis 
OK 

Options

In SET command, there are many options available, that modify the behavior of command. Following is the basic syntax of SET command with available options.

redis 127.0.0.1:6379> SET KEY VALUE [EX seconds] [PX milliseconds] [NX|XX]
  • EX seconds − Sets the specified expire time, in seconds.
  • PX milliseconds − Sets the specified expire time, in milliseconds.
  • NX − Only sets the key if it does not already exist.
  • XX − Only sets the key if it already exists.

Example

redis 127.0.0.1:6379> SET Adglob redis EX 60 NX  
OK

The above example will set the key ‘Adglob’, with expiry of 60 seconds, if the key does not exist.

This Post Has One Comment

Leave a Reply