Redis之基础知识
Redis是非关系型数据库,即Not-Only SQL。通常应用于缓存、Session共享和历史数据处理等。Redis基于C语言研发,通过键值对存储,可以承载大数据的高负载查询。
- 数据库高并发读写,即High Performance RW
- 海量数据的高效率查询和存储,即Huge Storage
- 高可用性、扩展性和易于集成,即High avaliability、scalability、Integration
Redis的数据类型
序号 | Type | 类型 |
---|---|---|
1 | String | 字符串 |
2 | Hash | 散列类型 |
3 | List | 列表类型 |
4 | Set | 集合类型 |
5 | Zset | 有序集合类型 |
安装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"