1.String数据类型单个和批量的插入和获取 set/get mset/mget
c:\Program Files>cd Redis
c:\Program Files\Redis>redis-cli.exe
127.0.0.1:6379> set name zhuyh
OK
127.0.0.1:6379> get name
"zhuyh"
127.0.0.1:6379> zset name zhuyonghao age 18 address hangzhou
(error) ERR unknown command 'zset'
127.0.0.1:6379> mset name zhuyonghao age 18 address hangzhou
OK
127.0.0.1:6379> mget name address
1) "zhuyonghao"
2) "hangzhou"
127.0.0.1:6379>
2.Hash数据类型单个和批量的插入和获取以及删除 hset/hget增 hmset/hmget/hgetall 查 hdel /del 删
127.0.0.1:6379> hset user name zhuyh
(integer) 1
127.0.0.1:6379> hget user name
"zhuyh"
127.0.0.1:6379> hmset user name zhuyh age 23 address hangzhou
OK
127.0.0.1:6379> hmget user age address
1) "23"
2) "hangzhou"
127.0.0.1:6379> hgetall user
1) "name"
2) "zhuyh"
3) "age"
4) "23"
5) "address"
6) "hangzhou"
127.0.0.1:6379> hdel user age
(integer) 1
127.0.0.1:6379> del name
(integer) 1
127.0.0.1:6379> del age
(integer) 1
3.List数据类型单个和批量的插入和获取以及删除 lpush/rpush增 lrem删
127.0.0.1:6379> lpush students zhangsan lisi
(integer) 2
127.0.0.1:6379> rpush students wangwu zhaoliu
(integer) 4
127.0.0.1:6379> lrange students 0 3
1) "lisi"
2) "zhangsan"
3) "wangwu"
4) "zhaoliu"
127.0.0.1:6379> llen students
(integer) 4
127.0.0.1:6379> lrem students 1 lisi
(integer) 1
127.0.0.1:6379> lrange students 0 3
1) "zhangsan"
2) "wangwu"
3) "zhaoliu"
127.0.0.1:6379>
4.Set数据类型单个和批量的插入和获取以及删除 sadd增 smembers查 scard长度 srem删
注意:aaa为Set的名称(这里打快了,没有特意命名)
127.0.0.1:6379> sadd aaa bbb ccc ddd eee
(integer) 4
127.0.0.1:6379> smembers aaa
1) "bbb"
2) "eee"
3) "ddd"
4) "ccc"
127.0.0.1:6379> scard aaa
(integer) 4
127.0.0.1:6379> srem aaa bbb
(integer) 1
127.0.0.1:6379>
5.Sorted Set数据类型单个和批量的插入和获取以及删除 zadd 增 zrange 查 zcard 长度 zrem 删
127.0.0.1:6379> zadd score 1 zhangsan 5 lisi 3 wangwu 8 zhaoliu
(integer) 4
127.0.0.1:6379> zrange score 0 3
1) "zhangsan"
2) "wangwu"
3) "lisi"
4) "zhaoliu"
127.0.0.1:6379> zcard score
(integer) 4
127.0.0.1:6379> zrem score zhangsan
(integer) 1
127.0.0.1:6379> zrange score 0 3
1) "wangwu"
2) "lisi"
3) "zhaoliu"
6.设置失效时间
127.0.0.1:6379> set code test ex 10 //设置十秒失效
OK
127.0.0.1:6379> get code
"test"
127.0.0.1:6379> ttl code // 获取还有多久失效 -2表示已经失效两秒
(integer) -2
127.0.0.1:6379> get code
(nil)
127.0.0.1:6379> set code test ex 15
OK
127.0.0.1:6379> ttl code
(integer) 11
127.0.0.1:6379> get code
(nil)
127.0.0.1:6379> set code test // 设置永不失效
OK
127.0.0.1:6379> ttl code //-1为永不失效
(integer) -1
127.0.0.1:6379> expire code 10 // 接着设置10秒失效
(integer) 1
127.0.0.1:6379> ttl code
(integer) 7
|