Connection redis
[root@master src]# redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set name root
OK
127.0.0.1:6379> get name
"root"
127.0.0.1:6379> info # 获取系统信息
AUTH password (password protected)
If you open a password-protected, then, after each connection Redis server, then use AUTH
the command to unlock, you can use other Redis command after unlocking because Redis high-performance features, in a very short period of time try to guess the password is very likely more , so be sure to use passwords complex enough and long enough, so as not to suffer from password guessing attacks.
127.0.0.1:6379> CONFIG SET requirepass root # 设置密码为root
OK
127.0.0.1:6379> quit # 退出再连接,让新密码对客户端生效
Login redis again
127.0.0.1:6379> ping
(error) NOAUTH Authentication required. # 未验证密码,操作被拒绝
127.0.0.1:6379> auth root # 输入正确密码
OK
127.0.0.1:6379> ping # 密码验证成功,可以正常操作命令了
PONG
# 清空密码
127.0.0.1:6379> config set requirepass ""
OK
127.0.0.1:6379> quit
$ redis # 重新进入客户端
127.0.0.1:6379> ping # 执行命令不再需要密码,清空密码操作成功
PONG
ECHO (case insensitive)
ECHO message
Print a specific information message
, the use of the test.
return value
127.0.0.1:6379> ECHO "text"
"text"
127.0.0.1:6379> echo "ok"
"ok"
PING
Use a client sends to the Redis server PING
, if the server is functioning properly, it will return a PONG
.
Often used to test the server connection is still in force, or for measuring the delay value.
return value:
If you connect a normal return PONG
, otherwise a connection error.
127.0.0.1:6379> ping
PONG
ouit
Requests the server closes the connection to the current client.
Once all waiting for the reply (if any) successfully written to the client, the connection will be closed.
return value:
Always returns OK
(but not printed display, because it was Redis-cli has withdrawn).
127.0.0.1:6379> quit
SELECT
SELECT index
Switch to the specified database, the database index number index
specified with the digital values 0
as a starting index.
Default 0
number of the database.
return value
127.0.0.1:6379> set db 0 # 默认使用 0 号数据库
OK
127.0.0.1:6379> select 1 # 使用 1 号数据库
OK
127.0.0.1:6379[1]> get db # 已经切换到 1 号数据库,注意 Redis 现在的命令提示符多了个 [1
(nil)
127.0.0.1:6379[1]> set db 3
OK
127.0.0.1:6379[1]> get db
"3"
127.0.0.1:6379[1]> select 3 # 再切换到 3 号数据库
OK