当前位置:网站首页>Redis data type -string (string type)
Redis data type -string (string type)
2022-07-24 06:47:00 【Life goes on and battles go on】
#=======================#set get del append strlen#=======================127.0.0.1:6379> set key wyt # Set the value
OK
127.0.0.1:6379> get key # obtain key"wyt"
127.0.0.1:6379> del key # Delete key
(integer) 1
127.0.0.1:6379> keys * # Check out all of key
(empty array)
127.0.0.1:6379> exists key # Make sure key Whether there is
(integer) 0
127.0.0.1:6379> append key wyt # Yes, it doesn't exist key Conduct append, Equate to set key wyt
(integer) 3 # Character length
127.0.0.1:6379> append key -lmp-hyd # The existing string is append
(integer) 11 # Length from 3 Add characters to 11 Characters
127.0.0.1:6379> get key
"wyt-lmp-hyd"
127.0.0.1:6379> strlen key # Gets the length of the string
(integer) 11
#================================# incr decr Self increasing Self reduction It has to be numbers to add and subtract +1 and -1# incyby decrby The order will key The number stored in plus the specified value#================================
127.0.0.1:6379> set browse 0 # Set the number of views to 0
OK
127.0.0.1:6379> incr browse # Browse +1
(integer) 1
127.0.0.1:6379> incr browse # Browse +1
(integer) 2
127.0.0.1:6379> decr browse # Browse -1
(integer) 1
127.0.0.1:6379> incrby browse 10 # Browse +10
(integer) 11
127.0.0.1:6379> decrby browse -10 # Browse +10
(integer) 21
127.0.0.1:6379> decrby browse 10 # Browse -10
(integer) 11
#================================# range 【 Range 】# getrange Get the value in the specified range , similar between...and The relationship between . from 0 To -1 All#================================127.0.0.1:6379> set key wyt-lmp-hyd # Set up key Value
OK
127.0.0.1:6379> getrange key 0 -1 # Get all the values
"wyt-lmp-hyd"
127.0.0.1:6379> getrange key 0 3 # Intercept part of string
"wyt-"
#=============================# setrange Set the value within the specified range , The format is setrange key value Specific value#=============================127.0.0.1:6379> get key
"wyt-lmp-hyd"
127.0.0.1:6379> setrange key 4 cby # Replacement value
(integer) 11
127.0.0.1:6379> get key
"wyt-cby-hyd"#=============================# setex(set with expire) Key seconds# setnx (set if not exist)#=============================
127.0.0.1:6379> setex key2 60 yjy # Set expiration time
OK
127.0.0.1:6379> ttl key2 # Check the time remaining
(integer) 56
127.0.0.1:6379> setnx mykey redis # If it doesn't exist, set Successfully returns 1
(integer) 1
127.0.0.1:6379> set mykey gqy
OK
127.0.0.1:6379> setnx mykey gqy # If it exists, set Failure to return 0
(integer) 0
127.0.0.1:6379> get mykey
"gqy"#=======================# mset mset The command is used to set one or more at the same time key-value Yes# mget mget Command if all ( One or more ) Given key value# If given key Inside There is a certain key non-existent So this key Return special value nil# msetnx When all key All set successfully return 1# If all given key All settings failed ( At least one key Already exist ) Then the return 0 Atomic manipulation#=======================127.0.0.1:6379> mset k1 wyt k2 lmp k3 hyd k4 yjy k5 gqy k6 syy
OK
127.0.0.1:6379> keys *
1) "browse"
2) "k5"
3) "key"
4) "k3"
5) "k4"
6) "k2"
7) "k1"
8) "mykey"
9) "k6"
127.0.0.1:6379> mget k1 k2 k3 k4 k5 k6
1) "wyt"
2) "lmp"
3) "hyd"
4) "yjy"
5) "gqy"
6) "syy"
127.0.0.1:6379> mget k10
1) (nil)
127.0.0.1:6379> msetnx k10 by k15 yy # Atomic operation
(integer) 0
127.0.0.1:6379> get k15
(nil)# Traditional object cachingset user:1 value(json data )# Can be used to cache objects127.0.0.1:6379> mset user:1:name wyt user:1:age 2
OK
127.0.0.1:6379> mget user:1:name user:1:age
1) "wyt"
2) "2"#=============================# getset ( First get stay set)#=============================
127.0.0.1:6379> getset db mongodb # There is no old value return nil
(nil)
127.0.0.1:6379> get db
"mongodb"
127.0.0.1:6379> getset db redis # Return old value mongodb
"mongodb"
127.0.0.1:6379> get db
"redis"
边栏推荐
- 创建WPF项目
- Common commands and package management of go language
- Special effects - Cherry Blossom falling background effects
- Redis入门
- ESP32超详细学习记录:NTP同步时间
- 今天聊赖数据库MySQL底层架构设计,你了解多少?
- Kubernetes' deployment, service concept, dynamic capacity expansion
- 系统安全及应用
- Identification of Chinese medicinal materials
- 【媒体控制器】开源项目学习笔记(基于Arduino Micro开发板)
猜你喜欢

Jmeter分布式压测

Redis入门

记录PHPSerializer工具类反序列化遇到的坑

Detailed explanation of class loader and parental delegation mechanism

Sort by an attribute value of an object in the array

Special effects - click the mouse and the randomly set text will appear

JSONObject按照key的A——Z顺序排序

DNS domain name resolution service

【LVGL】组件的样式的设置、更改、删除API函数

磁盘管理和文件系统
随机推荐
Speed pointer in JS linked list
Redis入门
Depth first search (template use)
These 10 kinds of timed tasks have been learned, and you can float directly
Special effects - cobweb background effects
【LVGL(6)】显示中文设置,制作中文字库
[jQuery自定义插件] 1 自定义缓存插件-jQueryCache
Explain the event cycle mechanism and differences between browser and node in detail
Talk about browser cache again
Special effects - starry cosmic background effects
【小型物体测速仪】只有原理,无代码
(静态,动态,文件)三个版本的通讯录
Niuke net brush questions
Machine learning case: smoking in pregnant women and fetal health
Restful API introduction
Sed command
kubernetes简介(kubernetes优点)
随机森林、LGBM基于贝叶斯优化调参
[lvgl (1)] a brief introduction to lvgl
数据分析思维之从整体出发分析零售行业——全方位多方面细节分析