Redis sentry — cache server

Time:2021-9-17

Redis sentry

Website: https://redis.io/

Note: the cache server can effectively improve the access efficiency of users

1. Precautions:

A: The data structure of the cache should be K-V structure. As long as K is unique, the result must be the same
B: The total cached data cannot be stored all the time. It is necessary to optimize the memory data regularly. LRU algorithm
C: The cached running data needs to be fast. The C language implementation… Runs in memory
D: If the cached data is in memory, power failure or downtime will be added, and the memory data will be lost directly; Persistent operation of memory data (disk)

2. Redis cache server:

Concept: it is an open source, in memory data structure storage system, which can be used in database, cache and message middleware; Support multiple types of data structures, such as string, hashes, list sets, sorted sets;

3. Redis installation

A: Enter the SRC root directory = > upload the compressed package = > execute tar -zxvf redis-5.0.4.tar.gz to decompress the file = > modify the file storage location = > MV redis-5.0.4 redis to modify the file name;

B: Install redis and enter the redis root directory CD redis = > make = > make install

4. Modification of redis.conf configuration file:

(bind 127.0.0.1 indicates IP binding)

Step 1: annotation binding address
Redis sentry -- cache server
Step 2: change yes to No
Redis sentry -- cache server
Step 3: start the background and change no to yes

Redis sentry -- cache server

A: Enter the following directory = > open redis.conf

5. Redis startup:

A: Start redis: redis server redis.conf
Redis sentry -- cache server

B: View the process PS – EF | grep redis
Redis sentry -- cache server

C: Enter redis client: redis cli – P 6379 (- P indicates port number)
Redis sentry -- cache server

D: Set key void form
Redis sentry -- cache server

E: Closing redis: two methods
1. Direct kill
2.reis-cli -p 6379 shutdown

6. Redis command:

1. String type

Redis sentry -- cache server
Redis sentry -- cache server
Redis sentry -- cache server
Redis sentry -- cache server
Redis sentry -- cache server

2. Hash type

Description: you can save object and attribute values with hash type
Example: user object {ID: 2, name: Xiao Ming, age: 19}
Redis sentry -- cache server

3. List type

Note: the list set in redis is a double ended circular list, which can insert data from the left and right directions respectively
The list collection can be used as a queue or as a stack
Queue: the direction of storing data is opposite to that of obtaining data
Stack: the direction of storing data is the same as that of obtaining data
Redis sentry -- cache server
Redis sentry -- cache server

4. Redis transaction command

Note: transaction support can be added for operations in redis. A task can be completed by multiple redis commands. If one command fails and the receipt fails, transaction rollback needs to be implemented
Redis sentry -- cache server

5. Integration of redis and mybatis

A: Add jar package

<dependency>
 <groupId>redis.clients</groupId>
 <artifactId>jedis</artifactId>
</dependency>
<dependency>
 <groupId>org.springframework.data</groupId>
 <artifactId>spring-data-redis</artifactId>
</dependency>

B: Test connectivity:
Redis sentry -- cache server
C:setnx(k, v); The high-level API determines whether the data exists. If there is data, it will not be processed
Redis sentry -- cache server~~~~

D: The setex (k, time, V) (set expiration time and set value) method is executed successfully or fails;
Jedis.setex (“2007”, 100, “test time”)

E:jedis.set

6. Redis business

1. Multi command: mark the beginning of things
2. The exec command indicates the submission of things
3. Rollback explanation of discard transaction

Recommended Today

Supervisor

Supervisor [note] Supervisor – H view supervisor command help Supervisorctl – H view supervisorctl command help Supervisorctl help view the action command of supervisorctl Supervisorctl help any action to view the use of this action 1. Introduction Supervisor is a process control system. Generally speaking, it can monitor your process. If the process exits abnormally, […]