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

边栏推荐
- PhpMyAdmin stage file contains analysis traceability
- Doxorubicin loaded on metal organic framework MIL-88 DOX | folic acid modified uio-66-nh2 doxorubicin loaded [email
- Go 1.16.4: purpose of go mod tidy
- Mysql:insert date:sql error [1292] [22001]: data truncation: incorrect date value:
- UiO-66-COOH装载苯达莫司汀|羟基磷灰石( HA) 包裹MIL-53(Fe)纳米粒子|装载黄芩苷锰基金属有机骨架材料
- Go: send the get request and parse the return JSON (go1.16.4)
- Programmable logic device software testing
- SQL Injection (AJAX/JSON/jQuery)
- Screenshot of the operation steps of upload labs level 4-level 9
- “又土又穷”的草根高校,凭什么被称为“东北小清华”?
猜你喜欢

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

Qt学习24 布局管理器(三)

FPGA test method takes mentor tool as an example

How to use lxml to judge whether the website announcement is updated

JVM class loading

Use vscode to view hex or UTF-8 codes

Programmable logic device software testing

全局事件总线

小项目(servelt+jsp+mysql+EL+JSTL)完成一个登录功能的Servlet,具有增删改查的操作。实现登录身份验证,防止非法登录,防止多点登录,记住用户名密码功能。

3D视觉——2.人体姿态估计(Pose Estimation)入门——OpenPose含安装、编译、使用(单帧、实时视频)
随机推荐
Go language web development series 30: gin: grouping by version for routing
1px problem of mobile terminal
QT learning 25 layout manager (4)
从零开始的基于百度大脑EasyData的多人协同数据标注
金属有机骨架(MOFs)抗肿瘤药载体|PCN-223装载甲硝唑|UiO-66包载盐酸环丙沙星([email protected])
Programmable logic device software testing
QT learning 20 standard dialog box in QT (middle)
金属有机骨架MIL-88负载阿霉素DOX|叶酸修饰UiO-66-NH2负载阿霉素[email protected]纳米粒子
Solve MySQL 1045 access denied for user 'root' @ 'localhost' (using password: yes)
[ACNOI2022]猜数
QT learning 19 standard dialog box in QT (top)
PhpMyAdmin stage file contains analysis traceability
Thrift threadmanager and three monitors
MIL-100( Fe) 包裹小分子阿司匹林形成[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)
Example analysis of QT learning 18 login dialog box
Go language unit test 4: go language uses gomonkey to test functions or methods
Use docker to build sqli lab environment and upload labs environment, and the operation steps are provided with screenshots.
Windos creates Cordova prompt because running scripts is prohibited on this system
Using registered classes to realize specific type matching function template
Uniapp skills - scrolling components -1