当前位置:网站首页>Introduction to high performance key value database redis
Introduction to high performance key value database redis
2022-04-22 18:56:00 【Top high school students】
1. Definition
Redis Is a high-performance key-value database ,key It's a string type .
2. Core features
Redis The server program adopts the single process model to process the client's request . The response to read-write time is through epoll Function to do this .
3. data type
The type of key is string
There are five types of values : character string string, Hash hash, list list, unordered set set; Ordered set zset
3.1 string type
1. brief introduction
character string (string) yes Redis Most basic types , Can be stored String,Integer,Float Data of type , Even binary data , The maximum size of a string is 512M
2.set command
set key value
If the key doesn't exist , Is to add
If the bond exists , Is to modify
Set expiration time (setex key Expiration time / The unit is in seconds value )
setex name2 3 wangwu
Set multiple key value pairs
mset key1 value1 key2 value2 key3 value3
Additional value
append key value
3.get command
Get a single value
get key1
Get multiple values
mget key1 key2
4.del command
Delete a key
del key1
Delete multiple keys
del key1 key2
5.keys command ( Lookup key )
Find a key
keys Key name
check look for All keys
keys *
6.exists command ( Judge whether the key exists )
If there is a return 1, There is no return 0
exists key
7.type command ( View the type of the value corresponding to the key )
type key
8.expire command ( Set key expiration time )
expire key Number of seconds
expire name 5
9.TTL command ( View key effective time )
TTL key
In seconds , Return to a given key The remaining lifetime of (TTL, time to live).
Return value
When key When there is no , return -2 .
When key When the remaining lifetime exists but is not set , return -1 .
otherwise , In seconds , return key The remaining lifetime of .
3.2 list type
1. brief introduction
Values in the list (value) Type is string
character string List, The underlying implementation is not an array , It's a linked list , That is to say, insert a new element in the head and tail , Its time complexity is constant ; The disadvantage is : Element positioning is slower than array positioning
2. add to
Insert values from the left :
lpush key value1 value2
Insert values from the right :
rpush key value1 value2
3. obtain
The index starts on the left , The index of the first value is 0
The index can be negative , It means counting from the tail , Such as -1 Represents the last value
start,stop For the index to get the value
grammar ( Returns the value of the specified range in the list )
lrange key start stop
Get all the values in the list
lrange key 0 -1
Get the last value from the third element
lrange key 2 -1
4. modify
The index starts on the left , The index of the first value is 0
The index can be negative , From the tail ,-1 Represents the last value
grammar ( Set the value of the specified index position )
lset key index value
5. Delete
Put the list before count The value of the second occurrence is removed
count>0: Delete from beginning to end ;count<0: Delete... From tail to head ;count=0: Delete all values
grammar ( Delete the specified value )
lrem key count value
Query list
lrange born2 0 -1
Delete... From the right side of the key list 1 individual 2
lrem born2 -1 2
Delete... From the left side of the key list 2 individual 2
lrem born2 2 2
3.3 set type
1. brief introduction
character string Set, Disorder cannot be repeated , It's through HashTable Realized .
2. actual combat
sadd: Additive elements , The format is
SADD KEY_NAME VALUE1..VALUEN
smembers: Get all the elements in the collection , The format is
SMEMBERS key
sismember: Determines whether an element is in the set , The format is
SISMEMBER KEY VALUE
srem: Remove elements , The format is
SREM KEY MEMBER1..MEMBERN
scard: Get the number of elements in the collection , The format is
SCARD KEY_NAME
spop: Pop up elements , The format is
SPOP key [count]
smove: Move elements , The format is
SMOVE SOURCE DESTINATION MEMBER
3.4 Hash Hash type
brief introduction
Press Hash Method to store strings
actual combat
Set the value , The format is
HSET KEY_NAME FIELD VALUE
hmset: Set multiple pairs of values at the same time , The format is
HMSET KEY_NAME FIELD1 VALUE1 ...FIELDN VALUEN
hgetall: Get the key Under all the values , The format is
HGETALL KEY_NAME
hget: Get a single key Value , The format is
HGET KEY_NAME FIELD_NAME
hmget: Get multiple values at the same time , The format is
HMGET KEY_NAME FIELD1...FIELDN
hdel: Delete an item , The format is
HDEL KEY_NAME FIELD1.. FIELDN
3.5 zset Hash type
brief introduction
character string Set, Orderly and unrepeatable , according to Score Sort by .
actual combat
zadd: Additive elements , The format is
ZADD KEY_NAME SCORE1 VALUE1.. SCOREN VALUEN
score The sum can be many pairs ,score It can be an integer , It can also be a floating-point number , It can also be +inf It means positive infinity ,-inf Denotes negative infinity
zrange: Get the elements in the index interval , The format is
ZRANGE key start stop [WITHSCORES]
zrangebyscore: Get the elements in the fraction range , The format is
ZRANGEBYSCORE key min max [WITHSCORES]
zrem: Remove elements , The format is
ZREM key member [member ...]
zcard: Get the number of elements in the collection , The format is
ZCARD KEY_NAME
版权声明
本文为[Top high school students]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221854259964.html
边栏推荐
- Can amaze your login page
- The sandbox has entered into cooperative relations with slipknot and knotfest to jointly build knotverse
- yes. Net future
- 乌国家安全与国防委员会秘书:目前不可能恢复乌克兰的核地位
- Jsonobject data guarantee order of fastjson
- 青训营-刷题打卡-控制并发执行goroutine的数量
- TypeScript中的命名空间使用
- What does %[^\n] mean in C?
- Mmdeploy quick start
- 2020-09-08 remove comments from JS code
猜你喜欢
![[self redemption -- top 101 4-day question brushing plan of niuke.com] warm up exercise on the first day](/img/31/8120f310af28e4cf49f67616748b7a.png)
[self redemption -- top 101 4-day question brushing plan of niuke.com] warm up exercise on the first day

Jsonobject data guarantee order of fastjson

【洛谷】P2372 yyy2015c01挑战算周长(BFS)

系统分析师-论文写作 框架搭建

C#与 Halcon 联合编程

The Sandbox 与 Slipknot 以及 Knotfest 达成合作关系,共同打造 KNOTVERSE

leetcode151. Reverse the words in the string (thought + explanation)

Talk about the pit of cache Boolean value

企业沟通软件与其他通信对比的优势有哪些

存储网络请求日志
随机推荐
【最佳实践】巡检项:内容分发网络(CDN)开启URL鉴权
【洛谷】P2372 yyy2015c01挑战算周长(BFS)
蓝牙盾/颈椎按摩仪/迷你充电宝/探头温度记等,段码LCD液晶显示驱动IC-VK1088B QFN32 4*4超小体积,22seg*4com且可通过指令进入省电模式
Take you to understand the principle of highly flexible spark architecture
2020-11-04 go test编译成可执行文件
微星小飞机 性能监控设置
JSP learning (IX. filter, wildcard and cookie processing)
2020-01-14 dapp开发环境搭建
Nat. Commun. |用于学习生成模型的神经编码框架
TabLayout + ViewPager2 + Fragment的简单应用
leetcode 前缀和-题集
Simulation experiment of Arduino uno steering gear
nodejs文件操作
062 反序列化漏洞
[best practice] patrol item: turn on URL authentication in content distribution network (CDN)
Flink best practices: using tdsql connector (Part 1)
一份数据满足所有数据场景?腾讯云数据湖解决方案及DLC内核技术介绍
Nat. Commun. | Neural coding framework for learning generation model
C language precompiling (preprocessing) define
单片机红外模块知识分享,理论是日后实战的基础