概述:redis是键值对的格式,键是字符串的形式,而其值是{字符串(String),哈希(hash),列表(list),无序集合(set),有序集合(zset)}
set user aaa
#添加一个键user 值为aaa
set user1 bbb
#添加一个键user1 值为bbb
127.0.0.1:6379> setex key3 10 value3
OK
127.0.0.1:6379> get key3
value3
127.0.0.1:6379> get key3
127.0.0.1:6379> mset user1 aaa user2 bbb user3 ccc
OK
127.0.0.1:6379> get user1
aaa
127.0.0.1:6379> get user2
bbb
127.0.0.1:6379> get user3
ccc
127.0.0.1:6379>
127.0.0.1:6379> mget user1 user2 user3
aaa
bbb
ccchaha
127.0.0.1:6379> APPEND user3 haha
7
127.0.0.1:6379> get user3
ccchaha
127.0.0.1:6379> del user1 user2
2 这个是返回的2
127.0.0.1:6379> keys user1
user1
127.0.0.1:6379> keys user11
//这里显示的是空,因为user11不存在
127.0.0.1:6379> keys *
user2
user3
key1
user1
use3
127.0.0.1:6379> exists user1
1
127.0.0.1:6379> exists user11
0
127.0.0.1:6379> type user1
string
127.0.0.1:6379> expire user1 3
1
127.0.0.1:6379> get user1
//这里显示的是空,因为user11不存在
127.0.0.1:6379> expire user2 100
1
127.0.0.1:6379> ttl user2
95
127.0.0.1:6379> ttl user2
93
127.0.0.1:6379> ttl user2
91
127.0.0.1:6379> ttl user2
85
127.0.0.1:6379> expire user2 100 //在效使的过程中还可以重新设置键的消失时间
1
127.0.0.1:6379> ttl user2
99
127.0.0.1:6379> hset user1 param1 value1
1
127.0.0.1:6379> hmset user5 field1 value1 field2 value2
OK
127.0.0.1:6379> hkeys user5
field1
field2
127.0.0.1:6379> hget user5 field1
value1
127.0.0.1:6379> hmget user5 field1 field2
value1
value2
127.0.0.1:6379> hkeys user5
field1
field2
127.0.0.1:6379> hgetall user5
field1
value1
field2
value2
127.0.0.1:6379> hdel user5 field1
1
127.0.0.1:6379> hvals user5
value2
127.0.0.1:6379> del user5
1
127.0.0.1:6379> exists user5
0
127.0.0.1:6379> lpush user6 2 3 4 5
5
127.0.0.1:6379>
127.0.0.1:6379> rpush user6 0 0 0
8
127.0.0.1:6379> linsert user6 before 3 -1
9
127.0.0.1:6379> linsert user6 after 3 -1
10
127.0.0.1:6379> lrange user6 0 5 //先边是对应的获取的值
5
4
-1
3
-1
2
127.0.0.1:6379> lset user6 1 wer
OK
127.0.0.1:6379> lrem user6 1 3
1
127.0.0.1:6379> lrange user6 0 -1
5
wer
-1
-1
2
1
0
0
0
127.0.0.1:6379> smembers set1
1
2
3
127.0.0.1:6379> srem set1 2
1
127.0.0.1:6379> smembers set1
1
3
对于zset有序集合中的数值为什么是有序的,同理有序集合中的数据也是只能添加删除,但是不能修改
排序之后每个之还会有一个索引
127.0.0.1:6379> zadd user7 1 asd 3 qwe 2 zxc
3
127.0.0.1:6379> zrange user7 0 -1 withscores
asd
1
zxc
2
qwe
3
127.0.0.1:6379> zrange user7 0 -1 withscores
zxc
2
qwe
3
ert
4
fgh
6
asd
9
127.0.0.1:6379> zrangebyscore user7 4 6
ert
fgh
127.0.0.1:6379> zscore user7 fgh
6
127.0.0.1:6379> zrem user7 fgh
1
127.0.0.1:6379> zremrangebyscore user7 3 6
2
127.0.0.1:6379> zrange user7 0 -1
zxc
asd
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。