Redis Learning Note (10)--redis Common operation instructions (i)

Source: Internet
Author: User
Tags delete key redis
keys keyword common directives

Here bloggers first set K1 v1 k2 v2
Exists key

Determine if key exists

Move Key Dbnum

Move key values to Dbnum library

Here move K1 to library 2nd, view current library only K2, after switching to library 2nd, view the current K1 has moved over

Expire key seconds

Set the expiration time for a given key

TTL key

See how many seconds are out of date, 1 means never expire, 2 means expired

Then the previous step to the K2 set the 10s expiration time, we have to check his validity period, until the last expiration (-2), notice that it has expired after the deletion, that is, there is no K2 this key.

In general our set key value default validity period is never expires, we reset K1 v1, and then see his expiration date

Type key

View Key Types

Del key

Delete key
String string Common directives

Set key value

Link string value value to key, note that if K1 has been set previously, then we will overwrite the previous value when we set K1 again.

Here we set the value of K1 to V1, then we set the value of K1 again to V11 as follows

Get key

Gets the value of the specified key

Append key value

Add content to the specified key, before our K1 value is v11 append add here, the resulting K1 value is v11add as shown in the figure below.

Strlen Key

Gets the length of the value of the specified key

INCR key

The value of the specified key is increased by +1, only the number can be added and reduced

DECR key

The value of the specified key is reduced by 1, and only the number can be added and reduced.

Incrby Key Step
The value of the specified key is self-increment according to the given step size

Decrby Key Step

The value of the specified key is self-decreasing according to the given step size

GetRange key start subscript end subscript

Gets the value in the specified range, similar to between and from 0 to 1, is to get all, truncate substring

SetRange Key Offset value

Assigns the value of the specified key starting at a certain location, such as K1 's original value V11add, from subscript 2 to the value v22, get v1v22d as follows

Setex Key Validity period value

Setex (set with expire), setting the expiration time for key-value pairs

Setnx Key value

SETNX (set if not exist) sets the value of key to value when and only if key does not exist

Because K1 has been set up before, so use setnx set K1 error, set K4 is OK, because there is no K4

Mset key1 value1 key2 value2 ....

Set multiple key values at once, where M stands for more

Mget key1 key2 Key3 ....

Gets the value of multiple keys at once, where M represents the more

Msetnx
Set multiple key values at once, when and only if key does not exist, note that if the set of multiple keys are already set, some key does not, this operation is all invalid, but not the key is set to succeed

The first time we tried to set K1 K8, because K1 already exists, so the setting failed, the second setting K8 K9 because the current library does not have K8 K9 so the setting succeeds

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.