Redis之基础知识

Redis是非关系型数据库,即Not-Only SQL。通常应用于缓存、Session共享和历史数据处理等。Redis基于C语言研发,通过键值对存储,可以承载大数据的高负载查询。

  1. 数据库高并发读写,即High Performance RW
  2. 海量数据的高效率查询和存储,即Huge Storage
  3. 高可用性、扩展性和易于集成,即High avaliability、scalability、Integration

Redis的数据类型

序号Type类型
1String字符串
2Hash散列类型
3List列表类型
4Set集合类型
5Zset有序集合类型

安装Redis

官方仅提供linux版本,Download不过需要自己编译,并打包成exe文件。
Github 上已经打包成windows版本的安装包,Download

Redis启动

windows


.\redis-server.exe .\redis.windows.conf
[27344] 23 Oct 12:16:44.974 # Redis version=5.0.9, bits=64, 
commit=9414ab9b, modified=0, pid=27344, just started
[27344] 23 Oct 12:16:44.974 # Configuration loaded

Linux

sudo service redis restart
#或者
sudo service redis stop
sudo redis-server /etc/redis.conf

Redis停止

 .\redis-cli.exe shutdown
 [20364] 23 Oct 12:45:18.515 # Redis is now ready to exit, bye bye...

客户端连接服务器

redis-cli

 .\redis-cli.exe -h 127.0.0.1 -p 6379
 127.0.0.1:6379> set mykey myvalue
 127.0.0.1:6379> get mykey
"myvalue"

本地连接

redis-cli -p 6379

redisinsight

启动

http://localhost:8001/

在这里插入图片描述
在这里插入图片描述

查询Redis的运行情况

查询Redis所使用的内存、硬盘使用状态等。

127.0.0.1:6379> info

以下把Redis制作成Windows的服务,方便使用

设置Windows的Redis服务

redis-server --service-install redis.windows.conf --loglevel verbose
[31104] 23 Oct 18:03:32.939 # Granting read/write access to 
'NT AUTHORITY\NetworkService' on: "D:\Redis-x64-5.0.9" 
[31104] 23 Oct 18:03:32.941 # Redis successfully installed as a service.

Windows服务Services.msc中生成Redis服务
D:\Redis-x64-5.0.9\redis-server.exe" --service-run redis.windows.conf --loglevel verbose

启动windows的Redis服务

 redis-server --service-start
 [32424] 23 Oct 18:12:50.754 # Redis service successfully started.

停止windows的Redis服务

 redis-server --service-stop
 [33536] 23 Oct 18:15:29.446 # Redis service successfully stopped.

卸载windows的Redis服务

 .\redis-server.exe --service-uninstall
 [27124] 23 Oct 18:01:02.657 # Redis service successfully uninstalled.

更改端口

D:\Redis-x64-5.0.9

修改redis.windows.conf文件

# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.
port 6379

密码登录

D:\ID>redis-cli
127.0.0.1:6379> auth abc123
OK

OR

D:\ID>redis-cli -p 6379 -a abc123

退出

127.0.0.1:6379> quit
OR
127.0.0.1:6379> exit

设置密码

Redis默认配置不需要密码认证,只要连接Redis服务器的host和port正确,就可以连接使用。在安全性上会有一定的问题,所以需要启用Redis的认证密码,增加Redis服务器的安全性。

127.0.0.1:6379> config set requirepass abc123
OK

或者 通过redis.windows-service.conf

requirepass abc123

查询密码

127.0.0.1:6379> config get requirepass
1) "requirepass"
2) "abc123"

清除密码

127.0.0.1:6379> config set requirepass ""
OK

添加Key-Value

127.0.0.1:6379> setnx abc 123
(integer) 1
127.0.0.1:6379> get abc
"123"

配置Log日志

修改redis.windows-service.conf

logfile "server_log.txt"
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值