redis#Part02_Basic Redis commands

This article introduces basic commands to manipulate redis Cache Server data.

Come on, let’s enjoy FA.

Reference Link

redis#Part01_Getting Started with Redis Cache Server

Implementation

Let’s continue with the previous article by launching the Redis Insight tool and connecting to the Redis Server in the Cloud.

This is the screen where the command is sent from Redis Insight.

SET 

SET command is used to set the key that will hold the string value; if the key already holds a value, it will be overwritten regardless of its type.

In the example below, the key name is set to the string value of Machine1.

To execute a command, press the green arrow button or Ctrl+Enter.

Done!The response was “OK.

Switch to the Browser screen and check the results of the command you just executed.

In some cases, the screen may not refresh, so click the Reflesh button.

Done!A Key named name has been added.

The name key now contains the string value “Machine1” that was set earlier.

GET

The value of key is obtained by using the GET command.If key does not exist, the ni value l is returned.Also, since GET can only handle string values, an error is returned if the value stored in key is not a string.

In the example below, a GET command is issued to obtain the name key value.

Done!A string value of “Machine1” is returned.

DEL

Use the DEL command to delete the specified key.If the corresponding key does not exist, it is then ignored.

In the example below, name2 Key is first created and machine2 is set.

I have confirmed that name2 has been added from Browser as well.

Next, issue the DEL command to delete Key name2 as shown in the figure below.

Done!Key name2 has been deleted.

I can confirm that Key name2 has been erased from Browser as well.

MSET

The MSET command is used to set each given key to a set of values; MSET, like SET, replaces existing values with new values.

In the example below, the MSET command is used to set Key Machine 2 to No. 1, location to “A-A-1”, and State to “RUN”.

Done!The MSET command was executed successfully.

The Browser also confirmed the results of the previous operation.

MGET

MGSET is used to return the values of all specified keys.The special value nil is returned for all keys that do not hold a string value or do not exist.Note that this does not cause the operation to fail.

In the example below, the MGET command is used to obtain the current values of multiple key names, locations, and states together.

Done!The MGET command executed successfully and the current values of key name, location, and state were obtained.

GETRANGE

GETRANGE can be used to return a substring of the string value stored in key.A negative offset can be used to specify an offset from the end of the string.That is, -1 is the last character and -2 is the last character in the operation.

In the example below, a partial string from Index 0 to 4 of Key name is obtained.

Done!I received a response only from Machi in Machine1.

Next, issue a GETRANGE command for the negative Index.In the example below, the command is to get the Index -3 to -1 of the Key name.

Done!This time, only ne1 of Machine1 was obtained.

SETRANGE

The SETRANGE command can be used to overwrite a portion of the string stored in key over the entire length of value from a specified offset.

In the example below, the SETRANGE command is used to replace the 0️ of the key name value with the string value “test”.

Done!SETRANGE command executed.

Using the GET command and checking the result, the machine was changed from Machine1 to testine1.

INCR

The INCR command can be used to add the number stored in key to 1.

In the example below, we first create a key named TimeConfig and set it to the integer 10.

Use the GET command to check the Key value of TimeConfig.

Next, use the INCR command to set the TimeConfig Key value to +1.

Done!The TimeConfig value is now 10 to 11.

INCRBY

By using the INCRBY command, the numbers stored in key can be added freely.In the example below, the INCRBY command adds +5 to the TimeConfig Key value created earlier.

Done!The current value of the TimeConfig Key value has been changed from 11 to 16.

DECR

The DECR command can be used to reduce the number stored in a key by one.Note that if the key contains a value of the wrong type or a string that cannot be represented as an integer, an error is returned.

In the example below, the TimeConfig Key value is reduced by 1 with the DECR command.

Done!TimeConfig Key value is now 16 to 15.

DECRBY

The DECRBY command can decrease the value stored in the specified key by the specified decrement value.Note that if the key value is not of the correct type or cannot be represented as an integer, an error is returned.

In the example below, the TimeConfig Key value is set to -10 with the DECRBY command.

Done!The current value of the TimeConfig Key value is now 15->5.

Footer_Basic

Please Support some devices for my blog

Amazon Gift List

Find ME

Twitter:@3threes2
Email:soup01threes*gmail.com (* to @)
YoutubeChannel:https://www.youtube.com/channel/UCQ3CHGAIXZAbeOC_9mjQiWQ

シェアする

  • このエントリーをはてなブックマークに追加

フォローする