当前位置:网站首页>Getting started with redis
Getting started with redis
2022-07-25 11:22:00 【ruochen】
Redis install
- Installation dependency
yum install -y gcc tcl- Upload the installation package and unzip it
tar -zxvf redis-6.2.6.tar.gzlink : https://pan.baidu.com/s/1uBw8qC2JMcbagrX7U9mlOA Extraction code : wbs6
- compile make && make install
Redis start-up
- The front desk starts
redis-server- Specify profile startup
- Backup
```shell
cp redis.conf redis.conf.bck
```
- Modify the configuration file
```shell
# Allow access to address
bind 0.0.0.0
# Log output
logfile "redis.log"
# password
requirepass ruochen666
``` Use systemctl To configure vim /etc/systemd/system/redis.service
# Write as follows
[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/bin/redis-server /usr/local/src/redis-6.2.6/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
# Overloading system services
systemctl daemon-reloadRedis command
General Command (generic)
- keys: View all that match the template key,
It is not recommended to use... On production environment equipment - del: Delete specified key
- exists: Judge key Whether there is
- expire: to key Set expiration date , At the expiration of the validity period, the key Will be automatically deleted
- ttl: see key The remaining validity period of
String type
- set: add to / Modify an existing String Key value pairs of type
- get: according to key obtain String Type of value
- mset: Batch addition
- mget: Batch acquisition
- incr: Let an integer key Self increasing 1
- incrby: Let an integer key Increment and specify the step size
incrby num 2:num Self increasing 2 - incrbyfloat: Floating point numbers grow by themselves ( You must specify a growth step )
- setnx: Add one String Key value pairs of type ( The premise is this key non-existent , Otherwise, do not execute )
- setex: Add one String Key value pairs of type , And specify the validity period
Key Hierarchical structure
- Redis Of key Multiple words are allowed to form a hierarchy , Use... Between multiple words
:separate , for exampleProject name : Business name : type :id - For example, the project name is
ruochen, YesuserandproductTwo different types of data , We can define key: - user dependent key:ruochen:user:1- product dependent key:ruochen:product:1
set ruochen:user:1 '{"id":1, "name":"Jack", "age": 21}'
set ruochen:user:2 '{"id":2, "name":"Rose", "age": 18}'
set ruochen:product:1 '{"id":1, "name":" millet 11", "price": 4999}'
set ruochen:product:2 '{"id":2, "name":" glory 6", "price": 2999}'Hash type
- Value It's an unordered Dictionary , Be similar to Java Medium HashMap structure
- String Structure stores the serialized objects json data , It is inconvenient to modify a field
- Hash Structure can store each field in the object independently , You can do this for a single field CRUD( be relative to String More flexible structure )
- Common commands - hset key field value: add to / modify hash type key Of field Value ,eg:
hset ruochen:user:3 name Lucy- hget key field: Get one hash type key Of field value ,eg:hget ruochen:user:3 name- hmset: Batch add ,eg:hmset ruochen:user:4 name Tom age 22 sex man- hmget: Batch acquisition ,eg:hmget ruochen:user:4 name age sex- hgetall: Get one hash Type of key All of them field and value,eg:hgetall ruochen:user:4- hkeys: Get one hash Type of key All of the field,eg:hkeys ruochen:user:4- hvals: Get one hash Type of key All of the value,eg:hvals ruochen:user:4- hincrby: To make a hash type key The field value of increases automatically and specifies the step size ,eg:hincrby ruochen:user:4 age 2- hsetnx: Add one hash Type of key Of field value ( The premise is this field non-existent , Otherwise, do not execute )
List type
- Redis Medium List The type and Java Medium LinkedList similar , It can be regarded as a two-way linked list architecture ( Both support forward retrieval , Reverse retrieval is also supported )
- features - Orderly - Elements can be repeated - Insert and delete fast - The query speed is average
- Use scenarios : Friends circle the likes list , Comment list, etc
- Common commands - lpush key element ...: Insert one or more elements to the left of the list ( Team leader ),eg:
lpush users 1 2 3- lpop key: Remove and return the first element to the left of the list , No return nil,eg:lpop users 1- rpush key element ...: Insert one or more elements to the right of the list ( A party ),eg:rpush users 4 5 6- rpop key: Remove and return the first element to the right of the list , No return nil,eg:rpop users 1- lrange key start end: Returns all elements within a range of subscripts ( Subscript from 0 Start ),eg:lrange users 1 2- blpop and brpop: And lpop and rpop similar , Just wait for the specified time when there is no element , Not directly back nil,eg:blpop users2 100lpush users2 jack - How to use it list Structure simulates a stack ? - The entrance and exit are on the same side -
lpush + lpopperhapsrpush + rpop - How to use it list Structure simulates a queue ? - The entrance and exit are on different sides -
lpush + rpopperhapsrpush + lpop - How to use it list Structure simulates a blocking queue ? - The entrance and exit are on different sides - Used when matching
blpoporbrpop
Set type
- Redis Of Set Structure and Java Medium HashSet similar , Can be seen as a value by null Of HashMap. Because it is also a hash surface , Therefore, it has the ability to communicate with HashSet Similar features - disorder - Element is not repeatable - Quick search - Support intersection 、 Combine 、 Difference set and other functions
- Common commands - sadd key member ... : towards set Add one or more elements to ,eg:
sadd s1 a b c- srem key member ... : remove set The specified element in ,eg:srem s1 a- scard key: return set The number of elements in ,eg:scard s1- sismember key member: Determine whether an element exists in set in ,eg:sismember s1 a- smembers: obtain set All elements in ,eg:smembers s1- sinter key1 key2 ... : seek key1 and key2 Intersection - sdiff key1 key2 ... : seek key1 and key2 The difference between the set - sunion key1 key2 ... : seek key1 and key2 Union
SortedSet type
- Sortable sets , And Java Medium TreeSet Some similar , But the underlying data structure is very different .SortedSet Each element in the has a score attribute , Can be based on score Attribute to sort elements , The underlying implementation is a jump table (SkipList) Add hash surface
- characteristic - Sortable - Elements do not repeat - Fast query speed
- Application scenarios : Ranking List
- Common commands - zadd key score member: Add one or more elements to sorted set, If it already exists, update its score value ,eg:
zadd stus 85 Jack 89 Lucy 82 Rose 95 Tom 78 Jerry 92 Amy 76 Miles- zrem key member: Delete sorted set A specified element in ,eg:zrem stus Tom- zscore key member: obtain sorted set Of the specified element in score value - zrank key member: obtain sorted set The ranking of the specified elements in ,eg:zrevrank stus Rose- zcard key: obtain sorted set The number of elements in ,eg:zcard stus- zcount key min max: Statistics score The number of all elements whose values are within a given range ,eg:zcount stus 0 80- zincrby key increment member: Give Way sorted set The specified element in is incremented , The step size is the specified increment value ,eg:zincrby stus 2 Amy- zrange key min max: according to score After ordering , Get the elements within the specified ranking range ,eg:zrevrange stus 0 2- zrangebyscore key min max: according to score After ordering , Get specified score Elements in scope ,eg:zrangebyscore stus 0 80- zdiff、zinter、zunion: Difference set 、 intersection 、 Combine
All rankings are in ascending order by default , If descending order is required, the order is
zAdd laterrevthat will do
边栏推荐
- PostgreSQL stepping on the pit | error: operator does not exist: UUID = character varying
- HCIA experiment (09)
- Flask framework -- flask caching
- MLX90640 红外热成像仪测温模块开发笔记(五)
- 数据库设计-简化字典表[通俗易懂]
- mysql主从复制与读写分离
- LVS负载均衡之LVS-NAT与LVS-DR模式原理详解
- Syncronized lock upgrade process
- 30000 word express Servlet
- C# Newtonsoft.Json 高级用法
猜你喜欢

从开源的视角,解析SAP经典ERP “三十年不用变”的架构设计

The most complete detailed tutorial on importing ad into lichuanyuan device packaging Library in history (always white and always cool)

Some usages of beautifulsoup

The most detailed MySQL index analysis (mind map is attached at the end of the article)
![[flask advanced] combined with the source code, explain the operation mechanism of flask (in and out of the stack)](/img/a0/9110b83ff5c7965809bbc9f3948956.jpg)
[flask advanced] combined with the source code, explain the operation mechanism of flask (in and out of the stack)

Learn NLP with Transformer (Chapter 6)

新能源销冠宏光MINIEV,有着怎样的产品力?

NowCoderTOP7-11——持续更新ing

HCIP(12)

Learn NLP with Transformer (Chapter 7)
随机推荐
How to optimize the performance when the interface traffic increases suddenly?
Signal integrity (SI) power integrity (PI) learning notes (XXXIV) 100 rules of thumb for estimating signal integrity effects
Esp32c3 based on the example tutorial of esp32 Rainmaker development under Arduino framework
只知道预制体是用来生成物体的?看我如何使用Unity生成UI预制体
Flame framework - Flame WTF form: file upload, verification code
Learn NLP with Transformer (Chapter 5)
Flask framework - Message flash
Tree dynamic programming
数据库设计-简化字典表[通俗易懂]
tensorflow 调用多块GPU的一些错误
JS convert pseudo array to array
Learn NLP with Transformer (Chapter 6)
【flask高级】从源码深入理解flask的应用上下文和请求上下文
JDBC的APi补充
PostgreSQL踩坑 | ERROR: operator does not exist: uuid = character varying
HCIP(11)
[cloud enjoys freshness] community weekly · Vol 72 - the first opening ceremony of the 2022 Huawei developer competition in China was launched; Huawei cloud koomessage is in hot public beta
Learn NLP with Transformer (Chapter 6)
BeautifulSoup的一些用法
Learn PHP -- phpstudy tips mysqld Exe: Error While Setting Value ‘NO_ ENGINE_ Solution of substitution error