当前位置:网站首页>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 :

边栏推荐
- Flutter dynamic | fair 2.5.0 new version features
- Go 1.16.4: manage third-party libraries with Mod
- Unable to stop it, domestic chips have made another breakthrough, and some links have reached 4nm
- 怎样删除对象的某个属性或⽅法
- Mastering the cypress command line options is the basis for truly mastering cypress
- 记录关于银行回调post请求405 问题
- jvm-运行时数据区
- Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station
- 叶酸修饰的金属-有机骨架(ZIF-8)载黄芩苷|金属有机骨架复合磁性材料([email protected])|制备路线
- Selenium browser (1)
猜你喜欢
[email "/>Doxorubicin loaded on metal organic framework MIL-88 DOX | folic acid modified uio-66-nh2 doxorubicin loaded [email

QT learning 22 layout manager (I)

Example analysis of QT learning 18 login dialog box

GoLand 2021.2 configure go (go1.17.6)

Mastering the cypress command line options is the basis for truly mastering cypress

Implementation of Muduo accept connection, disconnection and sending data

FPGA test method takes mentor tool as an example

jvm-对象生命周期

JVM object lifecycle

Global event bus
随机推荐
Uniapp skills - dom display and hiding
QT learning 23 layout manager (II)
28:第三章:开发通行证服务:11:在配置文件中定义属性,然后在代码中去获取;
[556. Next larger element III]
UiO-66-COOH装载苯达莫司汀|羟基磷灰石( HA) 包裹MIL-53(Fe)纳米粒子|装载黄芩苷锰基金属有机骨架材料
Solve MySQL 1045 access denied for user 'root' @ 'localhost' (using password: yes)
The solution of Chinese font garbled code in keil5
JS download files through URL links
Uniapp tips - set background music
Uniapp tips - scrolling components
Formation of mil-100 (FE) coated small molecule aspirin [email protected] (FE) | glycyrrhetinic acid modified metal organ
Qt学习18 登录对话框实例分析
[ACNOI2022]猜数
Logback log sorting
Why are grass-roots colleges and universities with "soil and poverty" called "Northeast small Tsinghua"?
Record 405 questions about bank callback post request
Flutter dynamic | fair 2.5.0 new version features
Implementation of Muduo asynchronous logging
Qt学习22 布局管理器(一)
Dlopen() implements dynamic loading of third-party libraries