Redis使用管道Pipe进行批处理一次执行多条DML语句-----Redis

本文详细展示了在Redis命令行中进行各种操作,包括设置键值对、哈希存储、列表操作以及错误处理实例,强调了使用命令行接口时安全性的注意事项。
摘要由CSDN通过智能技术生成
[root@localhost myredis]# vim cmd.txt
[root@localhost myredis]# cat cmd.txt
set k100 v100
set k200 v200
hset k300 name atguigu
hset k300 age 20
hset k300 gender male
lpush list 1 2 3 4 5
[root@localhost myredis]# cat cmd.txt|redis-cli -a abc123 --pipe
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
All data transferred. Waiting for the last reply...
Last reply received from server.
errors: 0, replies: 6

[root@localhost myredis]# vim cmd.txt
[root@localhost myredis]# cat cmd.txt
set k100 v100
set k200 v200
hset k300 name atguigu
hset k300 age 20
hset k300 gender male
lpush list 1 2 3 4 5
[root@localhost myredis]# cat cmd.txt|redis-cli -a abc123 --pipe
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
All data transferred. Waiting for the last reply...
Last reply received from server.
errors: 0, replies: 6

127.0.0.1:6379> incr key
(integer) 1
127.0.0.1:6379> get key
"1"
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> set k2 v2
OK
127.0.0.1:6379> set k3 v3
OK
127.0.0.1:6379> set k10000 v10000
OK
127.0.0.1:6379> mset k1 v1 k2 v2 k3 v3
OK
127.0.0.1:6379> get k100
"v100"
127.0.0.1:6379> get k300
(error) WRONGTYPE Operation against a key holding the wrong kind of value
127.0.0.1:6379> get 200
(nil)
127.0.0.1:6379> get k200
"v200"
127.0.0.1:6379> hget k300 name
"atguigu"
127.0.0.1:6379> hget k300 age
"20"
127.0.0.1:6379> hget k300 gender
"male"
127.0.0.1:6379> hgetall k300
1) "name"
2) "atguigu"
3) "age"
4) "20"
5) "gender"
6) "male"
127.0.0.1:6379> lrange list 0 -1
1) "5"
2) "4"
3) "3"
4) "2"
5) "1"

 127.0.0.1:6379> incr key
(integer) 1
127.0.0.1:6379> get key
"1"
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> set k2 v2
OK
127.0.0.1:6379> set k3 v3
OK
127.0.0.1:6379> set k10000 v10000
OK
127.0.0.1:6379> mset k1 v1 k2 v2 k3 v3
OK
127.0.0.1:6379> get k100
"v100"
127.0.0.1:6379> get k300
(error) WRONGTYPE Operation against a key holding the wrong kind of value
127.0.0.1:6379> get 200
(nil)
127.0.0.1:6379> get k200
"v200"
127.0.0.1:6379> hget k300 name
"atguigu"
127.0.0.1:6379> hget k300 age
"20"
127.0.0.1:6379> hget k300 gender
"male"
127.0.0.1:6379> hgetall k300
1) "name"
2) "atguigu"
3) "age"
4) "20"
5) "gender"
6) "male"
127.0.0.1:6379> lrange list 0 -1
1) "5"
2) "4"
3) "3"
4) "2"
5) "1"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值