当前位置:网站首页>St. Regis Takeaway Notes - Lecture 05 Getting Started with Redis
St. Regis Takeaway Notes - Lecture 05 Getting Started with Redis
2022-08-02 14:28:00 【Xiao Liyi】
一、Redis简介
Redis(Remote Dictionary Server ),即远程字典服务!是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API.
redis会周期性的把更新的数据写入磁盘或者把修改操作写入追加的记录文件,并且在此基础上实现了master-slave(主从)同步.
免费和开源!是当下最热门的 NoSQL 技术之一!也被人们称之为结构化数据库!
1.关系型数据库(RDBMS)
- Mysql
- Oracle
- DB2
- SQLService
2.非关系型数据库(NoSql)
- Redis
- Mongo db
- MemCached
3.Redis应用场景
- 缓存
- 任务队列
- 消息队列
- 分布式锁
二、Redis下载与安装
Redis安装包分为windows版与Linux版:
Windows版下载地址:Releases · microsoftarchive/redis · GitHub
Linux版下载地址:Index of /releases/

1.在Linux系统安装Redis步骤:
- 将Reids安装包上传到Linux
- 解压安装包,命令tar -zxvf redis-4.0.0.tar.gz -C /usr/local

- 安装Reids的环境依赖gcc,命令:yum install gcc-c++

- 进入/usr/local/redis-4.0.0,进行编译,命令:make

- 进入redis的src目录,进行安装,命令make install

安装完成后llYou can see these two files,命令窗口输入cd ..回到上一级ll查看当前文件,Configuration is all thereconf

2.Redis下载与安装
Redis的Windows版属于绿色软件,直接解压即可使用,解压后目录结构如下:


3.Redis服务启动与停止
Linux中redis服务启动,可以使用redis-service,默认端口号为6379,ctrl+C停止Redis服务



4.配置相关文件

/dae+enter 查找信息
配置当前redisWhether the service runs in the foreground or background after it is started,默认为no,yes开启后台运行


5.在Windows系统安装Redis步骤:
双击运行即可,If it crashes, try running it as administrator,for flashbackredis-server.exe redis.windows.conf,ctrl+C停止Redis服务

6.设置密码远程连接
requirepass foobared,Note here,Description No password is required,如需密码,iWriting will be done#删除

查找redis:
ps -ef | grep redis 获得进程id

杀掉进程:
kill -9 21848

At this time, the authentication is passed
连接虚拟机中的redis服务,点击redis-cli时shirt+Right-click to open the terminal,Use the following password:
.\redis-cli.exe -h 192.168.72.128 -p 6379 -a 123456
Generally speaking, the above password can directly connect successfully,But still can't connect,需要更改配置文件

将其加上#make it possible to connect remotely,Restart the service after saving and exiting

Re-enter the password after closing the firewall
关闭防火墙:暂时关闭防火墙(systemctl stop firewalld)

三、Redis数据类型
Redis存储的是key-value结构的数据,其中key是字符串类型,value有五种常用的数据类型:
- 字符串:String(最常用)
- 哈希:hash(Good for storing some objects)
- 列表:list(Can do task queue)
- 集合:set
- 有序集合:sorted set (排行榜)

四、Redis常用命令
1.字符串:String


此时重新输入set age 20,getIf you get it, you will find that the quotation marks are still there,是因为setAssignments are eventually converted to strings,string类型.注意,如果key值相同的情况下,后设置的值会覆盖之前设置的值.
set key value
get key

setex key seconds value

时间一到redis自动清除
setnx key value

2.哈希:hash

hset key field value
hget key field
hkeys key
hvals key
hgetall key
hdel key field

3.列表:list

lpush key value1 [value2]
lrange key start stop
rpop key
llen key
brpop key1 [key2] timeout


4.集合:set

sadd key member1 [member2]
smembers key
scard key
sinter key1 [key2]
sunion key1 [key2]
sdiff key1 [key2]
srem key member1 [member2]


5.有序集合:sorted set

zadd key score1 member1 [score2 member2]
zrange key start stop [withscores]
zincrby key increment member
zrem key member [member]

6.通用命令
keys pattern 查找所有符合给定模式( pattern)的key

exists key 检查给定key是否存在

type key 返回key所存储的值的类型

ttl key 返回给定key的剩余生存时间(TTL,time to live),以秒为单位

del key 该命令用于在key存在是删除key

边栏推荐
- verilog学习|《Verilog数字系统设计教程》夏宇闻 第三版思考题答案(第十章)
- 【Camera2】由Camera2 特性想到的有关MED(多场景设备互动)的场景Idea
- paddleocr window10 first experience
- Deep learning framework pytorch rapid development and actual combat chapter3
- Programming Specifications - LiteOS
- Flask request application context source code analysis
- chapter7
- Unit 5 Hold Status
- 8576 顺序线性表的基本操作
- MobileNet ShuffleNet & yolov5 replace backbone
猜你喜欢
随机推荐
Basic operations of 8583 sequential stack
MarkDown语法汇总
verilog学习|《Verilog数字系统设计教程》夏宇闻 第三版思考题答案(第十二章)
Hands-on OCR (1)
C语言日记 5 运算符和表达式
8580 合并链表
paddle window10环境下使用conda安装
[ROS](01)创建ROS工作空间
[ROS] The difference between roscd and cd
Unit 12 associated serialization
MongoDB Compass 安装与使用
[ROS] (06) ROS Communication - Topic Communication
云GPU(恒源云)训练的具体操作流程
MobileNet ShuffleNet & yolov5替换backbone
跑跑yolov5吧
c语言用scanf出错不安全的解决办法
Web Design (Beginners) [easy to understand]
c语言三子棋详解!!! (电脑智能下棋)(附上完整代码)
uniapp小程序禁止遮罩弹窗下的页面滚动的完美解决办法
C语言日记 5、7setprecision()问题









