Introduction and application of Redis database

Introduction

Redis is an open source high-performance key-value database developed in C language. The official test data is provided. 50 concurrent executions of 100,000 requests, the read speed is 110000 times/s, and the write speed is 81000 times. /s.

type of data

字符串类型 string
哈希类型 hash
列表类型 list
集合类型 set
有序集合类型 sortedset

Application scenarios

•	缓存(数据查询、短连接、新闻内容、商品内容等等)
•	聊天室的在线好友列表
•	任务队列。(秒杀、抢购、12306等等)
•	应用排行榜
•	网站访问统计
•	数据过期处理(可以精确到毫秒
•	分布式集群架构中的session分离

Download and install

Official website

* redis.windows.conf        配置文件
* redis-cli.exe:redis      的客户端
* redis-server.exe:redis   服务器端

operating

String type String

1. 存储: set key value             set name zhangsan
2. 获取: get key                   get name
3. 删除: del key                   del name

Hash type

1. 存储: hset key field value      hset myhash username lili
2. 获取: hget key field            hset myhash password 123
3. 获取: hgetall key               hgetall myhash
4. 删除:  hdel key field            hdel myhash username

List type List

1. lpush key value: 将元素加入列表左表
2. rpush key value:将元素加入列表右边
3. range key start end :范围获取   lrange myList 0 -1
4. lpop key: 删除列表最左边的元素,并将元素返回
5. rpop key: 删除列表最右边的元素,并将元素返回

Set type Set

1. sadd key value                   sadd myset a
2. smembers key                     smembers myset
3. srem key value                   srem myset a

Sortedset

zadd key score value                zadd mysort 60 lisi
zrange key start end                zrange mysort 0 -1
zrem key value                      zrem mysort lisi

General order

1. keys * : 查询所有的键
2. type key : 获取键对应的value的类型
3. del key:删除指定的key value

More details

Novice Tutorial

Guess you like

Origin blog.csdn.net/mrhs_dhls/article/details/107685303
Recommended