当前位置:网站首页>un7.27:redis数据库常用命令。
un7.27:redis数据库常用命令。
2022-07-28 03:55:00 【优秀的小爱子】
今天给大家分享一些我之前接触到的redis命令。
一、简介。
redis是一个开源的内存中的数据结构存储系统,它可以用作数据库/缓存和消息中间件。以键值对的形式存在(key-value),每秒/10万++。
二、数据库类型。
我们经常见到的数据库无非有两种,一种是以MySQL,Oracle,DB2,SQLServer为主的关系型数据库,还有一种,就是以Redis,mongo db,Memcached为主的非关系型数据库。
三、作用。
redis数据库作为典型的非关系型数据库,不仅有缓存的作用,而且还能进行任务队列、消息队列,以及进行分布式锁,为我们程序员提供了非常大的便利。
四、数据类型。
redis是以key-value键值对的形式存在的,key是字符串,value有五种常用。
1、字符串:String
2、哈希:hash 适合存储对象
3、列表:list 顺序列表,可以有重复元素
4、集合:set 无序集合,不能有重复元素
5、有序集合:sorted set 有序集合,不能有重复元素(排行榜)
五、String字符串常用命令。
1、赋值:set key(name) value(xiaoai)

2、获取值,后值覆盖:get key(name)

3、存活时间:setex key(城市) seconds(10) value(taiyuan)

4、key不存在即设值,存在即不变:setnx key value

六、hash哈希常用命令。
1、将key中的字段field的值设为value,命令:Hset key(001) field(name) value(xiaoai)

2、获取指定字段,命令:Hset key field

3、删除指定字段,命令:Hdel key field

4、获取所有字段,命令:Hkeys key

5、获取所有值,命令:Hvals key

6、获取指定key的所有字段和值,命令:Hgetall key

七、list常用命令。
1、将一个或多个值插入到列表头部,命令:Lpush key value1 [value2,value3......]

2、获取列表指定范围的元素,命令:LRange key start stop

3、移除并获取列表最后一个元素,命令:Rpop key

4、获取列表长度,命令:Llen key

5、移除并获取列表最后一个元素,或发现可弹出元素为止,命令:BRpop key1 [key2] timeout
八、set集合常用命令。
1、添加多个成员。命令:sadd key 1 2

2、返回集合,命令:smembers key

3、几个,命令:scard key

4、交集、共用。命令:sinter key1,key2

5、并集,命令:sunion key1,key2
6、差集,后面元素不存在,命令:sdiff key1,key2
7、移除,命令:SRem key key1,key2
九、sorted set 命令。
1、添加一个或多个(从小到大排序),命令:zadd key score1 member1 [score2 member2]
2、获取指定范围元素,命令:zrange key star stop[with scores]
3、修改分数,命令:zincrby key increment(加多少) member(成员)
4、移除一个或多个元素,命令:zrem key member
十、通用命令。
1、查找所有符合的key,命令:keys pattern

2、检查给定key值是否存在,命令:exists key

3、返回key所存储的值的类型,命令:type key
![]()
4、返回给定key的剩余生存时间(秒),命令:ttl key
![]()
5、该命令用于在key存在时删除key(此处不作展示),命令:del key
以上就是我总结的关于redis的常用命令,当然,大家也可以搜集更多的命令去完善自己的知识体系,如果是要日常使用的话,这些基本够用,祝大家好运。
边栏推荐
- After 95, Alibaba P7 published the payroll: it's really heartbreaking
- 构建“产业大脑”,以“数字化”提升园区运营管理及服务能力!
- In December, the PMP Exam adopted the new syllabus for the first time. How to learn?
- [P4] check the differences between the two historical versions of the library file
- Greed 45. Jumping game II
- 过滤器、拦截器、监听器
- Greedy - 53. Maximum subarray sum
- Summary and interpretation of CONDA virtual environment
- 【无标题】
- pip-script. py‘ is not present Verifying transaction: failed
猜你喜欢

高等数学(第七版)同济大学 习题3-4 个人解答(前8题)

CV2. Threshold(), CV2. Findcontours(), CV2. Findcontours image contour processing

In the official online CV2 document, check the optional values of OpenCV specific parameters

After 95, Alibaba P7 published the payroll: it's really heartbreaking

21天,胖哥亲自带你玩转OAuth2

Common weak network testing tools

How to solve MySQL deep paging problem

Leetcode brush question: dynamic planning 09 (weight of the last stone II)

一文读懂Plato Farm的ePLATO,以及其高溢价缘由

高等数学(第七版)同济大学 习题3-6 个人解答
随机推荐
Protocols in swift
【无标题】
Vertical align align the elements in the row are vertically centered
Lightpicture - exquisite drawing bed system
【图像分类】2021-MLP-Mixer NIPS
搬家通知!
Leetcode 0141. circular linked list - three solutions
TypeError: ufunc ‘bitwise_ and‘ not supported for the input types, and the inputs could not be safely
7/27(板子)染色法判定二分图+求组合数(递推公式)
面试必备杀技:SQL查询专项训练!
Advanced Mathematics (Seventh Edition) Tongji University exercises 3-4 personal solutions (the last 8 questions)
LeetCode_409_最长回文串
ES6 from entry to mastery 07: Deconstruction assignment
[openvx] VX for basic use of objects_ pyramid
VBA reads the create document of SQL in batches to create tables
常用的弱网测试工具
In depth introduction to sap ui5 fileuploader control - why do you need a hidden iframe trial
Dynamic planning - 1049. Weight of the last stone II
Monotonous stack -- 42. Receiving rain -- a difficult problem that big factories must know
简单、好用的性能测试工具推荐