Redis教程

redis简单应用demo

本文主要是介绍redis简单应用demo,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

redis简单应用demo
1.字符串
127.0.0.1:6379> set hello toney
OK
127.0.0.1:6379> type hello
string
127.0.0.1:6379> get hello
"toney"

2.Hash哈希表HashMap<key,HashMap<>>
127.0.0.1:6379> hset hash_test a 1
(integer) 1
127.0.0.1:6379> hset hash_test b 2
(integer) 1
127.0.0.1:6379> hgetall hash_test
1) "a"
2) "1"
3) "b"
4) "2"
127.0.0.1:6379> hget hash_test
(error) ERR wrong number of arguments for 'hget' command
127.0.0.1:6379> hget hash_test a
"1"
127.0.0.1:6379> hget hash_test b
"2"
127.0.0.1:6379> hkeys hash_test
1) "a"
2) "b"

3.List列表(存在重复的情况)
127.0.0.1:6379> lpush study redis
(integer) 1
127.0.0.1:6379> lpush study mongodb
(integer) 2
127.0.0.1:6379> lpush study mysql
(integer) 3
127.0.0.1:6379> lpush study mysql
(integer) 4
127.0.0.1:6379> lrange study 0 10
1) "mysql"
2) "mysql"
3) "mongodb"
4) "redis"

 

4.set集合(不存在重复的情况)
127.0.0.1:6379> sadd roomInfo::1001 tony
(integer) 1
127.0.0.1:6379> sadd roomInfo::1001 mike
(integer) 1
127.0.0.1:6379> sadd roomInfo::1001 steve
(integer) 1
127.0.0.1:6379> scard roomInfo::1001
(integer) 3
127.0.0.1:6379> smembers roomInfo::1001
1) "mike"
2) "steve"
3) "tony"

5.sortedSet有序集合(有序集合的成员是唯一的,但分数(score)却可以重复。)
127.0.0.1:6379> zadd itScort 1 redis
(integer) 1
127.0.0.1:6379> zadd itScort 2 mongodb
(integer) 1
127.0.0.1:6379> zadd itScort 3 mysql
(integer) 1
127.0.0.1:6379> zadd itScort 3 mysql
(integer) 0
127.0.0.1:6379> zadd itScort 4 mysql
(integer) 0
127.0.0.1:6379> zadd itScort 3 es
(integer) 1
127.0.0.1:6379> type itScort
zset
127.0.0.1:6379> zrange itScort 0 10 WITHSCORES
1) "redis"
2) "1"
3) "mongodb"
4) "2"
5) "es"
6) "3"
7) "mysql"
8) "4"


6.订单自增长的思路:业务编码+地区+自增数值
127.0.0.1:6379> set orderId 1
OK
127.0.0.1:6379> incr orderId
(integer) 2
127.0.0.1:6379> incr orderId
(integer) 3
127.0.0.1:6379> get orderId
"3"
127.0.0.1:6379> incr orderId
(integer) 4
127.0.0.1:6379> get orderId
"4"

这篇关于redis简单应用demo的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!