一、Redis客户端
安装完成Redis,我们就可以操作Redis,实现数据库的CRUD了。这需要用到Redis客户端,包括:
- 命令行客户端
- 图形化桌面客户端
- 编程客户端
1.1 命令行客户端
Redis安装完成后就自带了命令行客户端redis-cli
使用方式:
redis-cli [options] [commonds]
其中常见的options有
- -h 127.0.0.1 指定要连接的redis节点的IP地址,默认是127.0.0.1
- -p 6379 指定要连接的redis节点的端口,默认是6379
- -a 123321 指定redis的访问密码
- ping 与redis服务端做心跳测试,服务端正常会返回pong
不指定commond时,会进入redis-cli的交互控制台
[root@mysql redis-6.2.7]# redis-cli -h 192.168.1.58 -a 123321
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.1.58:6379> ping
PONG
192.168.1.58:6379> exit
## 连接时不加上用户名及密码
[root@mysql redis-6.2.7]# redis-cli -h 192.168.1.58
192.168.1.58:6379> ping
(error) NOAUTH Authentication required.
## 使用这种方式去认证
192.168.1.58:6379> AUTH 123321
OK
192.168.1.58:6379> ping
PONG
192.168.1.58:6379>
## 设置键值对也可以叫存入键值对
192.168.1.58:6379> set name kk
OK
## 获取键值对
192.168.1.58:6379> get name
"kk"
192.168.1.58:6379> set age 30
OK
192.168.1.58:6379> get age
"30"
## 切换库
192.168.1.58:6379> SELECT 1
OK
192.168.1.58:6379[1]> get name
(nil)
192.168.1.58:6379[1]> SELECT 0
OK
192.168.1.58:6379> GET name
"kk"
1.2 使用RedisDesktopManager
直接点连接设置就可以了。