当前位置:网站首页>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 :
边栏推荐
- 金属有机骨架材料ZIF-8包载姜黄素([email protected]纳米颗粒)|纳米金属有机框架搭载雷帕霉素|科研试剂
- Qt学习25 布局管理器(四)
- Failure of vector insertion element iterator in STL
- Formation of mil-100 (FE) coated small molecule aspirin [email protected] (FE) | glycyrrhetinic acid modified metal organ
- Windos creates Cordova prompt because running scripts is prohibited on this system
- How to use lxml to judge whether the website announcement is updated
- Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station
- Go language web development series 28: solve cross domain access of CORS with gin contrib / CORS
- Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:
- Redis:字符串类型数据的操作命令
猜你喜欢
全局事件总线
RocksDB LRUCache
JVM runtime data area
QT learning 24 layout manager (III)
【吉林大学】考研初试复试资料分享
SQL Injection (POST/Select)
Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:
How to use lxml to judge whether the website announcement is updated
Complete DNN deep neural network CNN training with tensorflow to complete image recognition cases
SQL Injection (AJAX/JSON/jQuery)
随机推荐
Similarities and differences of sessionstorage, localstorage and cookies
金属有机骨架材料ZIF-8包载姜黄素([email protected]纳米颗粒)|纳米金属有机框架搭载雷帕霉素|科研试剂
小项目(servelt+jsp+mysql+EL+JSTL)完成一个登录功能的Servlet,具有增删改查的操作。实现登录身份验证,防止非法登录,防止多点登录,记住用户名密码功能。
Mastering the cypress command line options is the basis for truly mastering cypress
Global event bus
Metal organic framework (MOFs) antitumor drug carrier | pcn-223 loaded with metronidazole | uio-66 loaded with ciprofloxacin hydrochloride(
[技術發展-24]:現有物聯網通信技術特點
Cross linked cyclodextrin metal organic framework loaded methotrexate slow-release particles | metal organic porous material uio-66 loaded with flavonoid glycosides | Qiyue
Summary of common error reporting problems and positioning methods of thrift
Go language web development series 29: Gin framework uses gin contrib / sessions library to manage sessions (based on cookies)
28:第三章:开发通行证服务:11:在配置文件中定义属性,然后在代码中去获取;
How to promote the progress of project collaboration | community essay solicitation
MySQL 数据增删改查综合案例
Qt学习20 Qt 中的标准对话框(中)
RocksDB LRUCache
[Jilin University] information sharing of postgraduate entrance examination and re examination
How to delete an attribute or method of an object
28: Chapter 3: develop Passport Service: 11: define attributes in the configuration file, and then obtain them in the code;
又一个行业被中国芯片打破空白,难怪美国模拟芯片龙头降价抛售了
[développement technologique - 24]: caractéristiques des technologies de communication Internet des objets existantes