当前位置:网站首页>Redis: operation command of string type data
Redis: operation command of string type data
2022-07-03 14:04:00 【dengfengling999】
Catalog :
(1)redis Operation commands for string type data
1.set、2.get、3.append、4.strlen
(2)redis Operation commands for string type data 2
1.incr、2.decr、...
(1)redis Operation commands for string type data

String type (string)
The string type is Redis The most basic data type in , It can store any kind of string , Including binary numbers
According to the , Serialized data ,JSON The object is even a picture .
The general idea of string type data operation is through key operation value,key It's a data ID ,value It's our feeling
Business data of interest .
1.set
grammar :set key value
function : String value value Set to key in , If key Already exists , The last value will cover the previous value .
Return value :OK It means success

for example : save String Data of type use Set
If you save key Already exist , Then later vallue, Will take the old value overwrite :

2.get
grammar :get key
function : obtain key The string value set in
Return value :key There is , return key Corresponding value;
key non-existent , return nil

Get stored data use Get:

3.append
grammar :append key value
function : If key There is , Will value Append to key The end of the original old value
If key non-existent , Will key Set the value to value
Return value : The total length after appending the string ( The number of characters )

for example :
4.strlen
grammar :strlen key
function : return key The length of the stored string value
Return value : If key There is , Returns the length of the string value ;
key non-existent , return 0

for example : Gets the length of the string :
(2)redis Operation commands for string type data 2



1.incr
grammar :incr key
function : take key The value of the number stored in plus 1, If key non-existent , be key The value of is initialized to 0 Re execution incr operation .
Return value : Back to plus 1 After key value

for example : to zsage+1 The original value is :30

When key Value does not exist :
Give a name : Give non numerical data +1 Will report a mistake

2.decr
grammar :decr key
function : take key The number stored in minus 1, If key non-existent , Then key The value of is initialized to 0 Re execution decr operation .
Return value : Return minus 1 After key value

3.incrby
grammar :incrby key offset
function : take key The stored value plus the increment value , If key non-existent , be key The value of is initialized to 0 Re execution INCRBY command .
Return value : Return after increment key value .

for example : to zsage+10:

4.decrby
grammar :decrby key offset
function : take key Subtract the decrement value from the stored value , If key non-existent , be key The value of is initialized to 0 Re execution DECRBY command .
Return value : Go back to after decrement key value .

for example : to zsage-10:

5.getrange
grammar :getrange key startIndex endIndex It will not affect the amount data in the database
function : obtain key The string values in are derived from startIndex Start to endIndex The ending substring , Include startIndex and endIndex, Negative numbers start at the end of the string ,-1 Represents the last character .

for example : Interception acquisition 2-5: The data in the database will not change after interception

Results the same

Get the entire :

6.setrange
grammar :setrange key offsetIndex value
function : use value Cover key The stored values of are from offset Start .
Return value : The length of the modified string .

for example :

7.setex
grammar :setex key seconds value
function : Set up key Value , And will key The lifetime of is set to seconds ( In seconds ) , If key Already exist , Will overwrite old values .
Return value : Set up the success , return OK.

for example : add to k1 At the same time, set the existence time to 20, Delete after time

8.setnx solve set Set the existing key, Overwrite the original value
grammar :setnx key value
function :setnx yes set if not exists Abbreviation , If key non-existent , be set value , If it exists, the value is not set .
Return value : Set up the success , return 1
Setup failed , return 0

for example : The original existence abandons the setting

9.mset Batch addition set take String Type data is added to redis In the database
grammar :mset key value [key value…]
function : Set one or more... At the same time key-value Yes
Return value : Set up the success , return OK.

for example :

10.mget Batch acquisition from redis obtain String Data of type
grammar :mget key [key …]
function : Get all ( One or more ) Given key Value
Return value : Contains all the key A list of , If key non-existent , Then return to nil.

for example : If not , return nil

11. msetnx Batch settings ( add to ) , all key It doesn't exist , Set up the success , otherwise , Setup failed
grammar :msetnx key value[key value…]
function : Set one or more... At the same time key-value Yes , If there is a key Is there , The setting is not successful .
Return value : Set up the success , return 1
Setup failed , return 0

for example :

边栏推荐
- 如何使用lxml判断网站公告是否更新
- Uniapp skills - scrolling components -1
- [développement technologique - 24]: caractéristiques des technologies de communication Internet des objets existantes
- Software testing is so hard to find, only outsourcing offers, should I go?
- GoLand 2021.1: rename the go project
- Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station
- Solve MySQL 1045 access denied for user 'root' @ 'localhost' (using password: yes)
- page owner特性浅析
- Halcon combined with C # to detect surface defects -- Halcon routine autobahn
- Common mixins
猜你喜欢

Common network state detection and analysis tools
![[技术发展-24]:现有物联网通信技术特点](/img/f3/a219fe8e7438b8974d2226b4c3d4a4.png)
[技术发展-24]:现有物联网通信技术特点

挡不住了,国产芯片再度突进,部分环节已进到4nm

Rasp implementation of PHP

Ocean CMS vulnerability - search php

消息订阅与发布

JVM系列——概述,程序计数器day1-1

UiO-66-COOH装载苯达莫司汀|羟基磷灰石( HA) 包裹MIL-53(Fe)纳米粒子|装载黄芩苷锰基金属有机骨架材料

Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station

How to use lxml to judge whether the website announcement is updated
随机推荐
Use and design of Muduo buffer class
Common network state detection and analysis tools
selenium 浏览器(1)
Go 1.16.4: purpose of go mod tidy
JVM系列——概述,程序计数器day1-1
Thrift threadmanager and three monitors
Doxorubicin loaded on metal organic framework MIL-88 DOX | folic acid modified uio-66-nh2 doxorubicin loaded [email
交联环糊精金属有机骨架负载甲氨蝶呤缓释微粒|金属-有机多孔材料UiO-66负载黄酮苷类药物|齐岳
[技術發展-24]:現有物聯網通信技術特點
[understanding by chance-37]: the structure of human sensory system determines that human beings are self-centered
The solution of Chinese font garbled code in keil5
QT learning 23 layout manager (II)
Logback log sorting
jvm-类加载
Current situation, analysis and prediction of information and innovation industry
Use vscode to view hex or UTF-8 codes
Uniapp tips - scrolling components
Windos creates Cordova prompt because running scripts is prohibited on this system
Collection of mobile adaptation related articles
Which securities company has the lowest Commission for opening an account online? I want to open an account. Is it safe for the online account manager to open an account