introduce

Content caching

When the CPU processes data, it looks in the Cache first. If the data is temporarily stored because it has been read in previous operations, there is no need to read from Main memory. Since the CPU is usually faster than Main memory, Main memory cycles (the time required to access main memory) several clock cycles. Therefore, to access main memory, you have to wait several CPU cycles, resulting in waste.

The purpose of providing “cache” is to make the speed of data access adapt to the processing speed of CPU. It is based on the principle of “local behavior of program execution and data access” in memory, that is, within a certain program execution time and space, the code to be accessed is concentrated in one part. In order to make the most of the cache, not only do we temporarily store the data we’ve just accessed, but we also use hardware-implemented instruction prediction and data prefetch techniques to pre-fetch as much data as possible from memory into the cache.

Concept of Redis

Redis is a remote in-memory database (non-relational database) with strong performance, replication features and a unique data model for problem solving. It can store mappings between key-value pairs and five different types of values, persist key-value pair data stored in memory to hard disk, use replication features to extend read performance, and use client sharding to extend write performance. Redis is a high performance key value database developed in C language. Redis can store data through several key value types. Key value type: String Character type MAP Hash type List List type SET Set type sortedSet Type of an ordered set.

Application scenarios

  • Caching (data queries, short links, news content, product content, and so on). (Maximum use)
  • Session separation in distributed cluster architecture.
  • A chat room’s list of online friends.
  • Task queues. (Seckill, Snap, 12306, etc.)
  • App leaderboards.
  • Website visit statistics.
  • Data expiration processing (to the millisecond)

The installation

  • Official website: redis.io/
  • Download address: download. Redis. IO/releases/re…
  • Upload the installation package to Linux
  • Extract:The tar - ZXVF redis. 3.0.0. Tar. Gz
  • Install c language environment:sudo apt-get install gcc-c++
  • compile
cdRedis - 3.0.0 makeCopy the code
  • The installation

The Redis installation path is /usr/local/redis

make install PREFIX = /usr/local/redis

Start & Test

  • Start the redis

redis-server /usr/local/redis.conf

  • Check whether Redis is started

ps -ef | grep redis

  • Accessing the Client

redis-cli

  • Set a key

set test 123

  • Gets the value of key

get test

  • exit

exit

conclusion

This is the end of the redis cache. It is understood from this perspective that the cache is a guarantee of high concurrency in the service. Simply install a stand-alone REDis through commands, execute commands to set key and value to test the success of the installation, and then continue to write the relationship between Redis and micro-services, as well as the practice of practical application.