preface

Redis is a high performance open source, C language written Nosql (non-relational database), data stored in memory.

Summarized a Redis knowledge map to share with you

1. What is Redis?

Redis is a high performance open source, C language written Nosql (non-relational database), data stored in memory. Redis is stored in key-value format, which is different from traditional relational databases. Non-relational databases do not necessarily follow the basic requirements of traditional databases, such as SQL standards, transactions, table structures, etc. Non-relational databases are not strictly a database, but a collection of structured data storage methods. Java data structures: String, array, list, set map… Redis provides many methods for accessing data from various data structures.

2. Features (Advantages)

1. Data is stored in memory, with fast access speed and strong concurrency

2. It supports storing more value types, including string, list, set, zset, sorted set and hash.

3. Redis, to a large extent, compensates for the deficiency of memcached key/value storage. In some cases, redis can supplement relational databases (such as MySQL).

4. It provides Java, C/C++, C#, PHP, JavaScript and other clients, which is very convenient to use.

5.Redis supports clustering (master/slave synchronization and load balancing). Data can be synchronized from the master server to any number of slave servers, and the slave server can be the master server associated with other slave servers.

6. Supports persistence and saves data to files on hard disks

7. Support subscribe/publish function QQ group

1, data storage: stored in memory, but also irregularly persistent to the disk. Fast access speed, strong concurrency, no data loss after power failure.

2. Support more Value types.

3. Multiple clients (Java, PHP, c#, js)

4, support cluster to expand space 8G+8G+16G

5. Open source (free and maintained by many)

3. Install Redis server

3.1. Installation and use under Windows

1. Download redis software

Use redisbin32 or redisbin64

2. Green software, do not need to install, directly use

3. Start the Redis service (with or without a profile)

4. Connect to Redis for operation

CMD >{%redis%}/redis-cli-h IP address -p port number IP Is local by default. -P Default 6379 redis-cli-h 172.16.6.248 -p 6379 CMD >{%redis%}/redis-cliCopy the code

Basic usage

4. Redis persistent configuration

Redis provides two different levels of persistence: RDB and AOF, which can be configured by modifying redis.conf.

When the persistence condition is met, the system will persist the data. The data that has not been saved is saved in the form of AOF logs. When Redis starts, it parses log files (a bunch of commands) to recover data. Then you have to load the RDB file (fetch union).

5. RDB schema

RDB persistence can generate point-in-time snapshots of data sets at specified intervals. This mode is enabled by default. How to disable the RDB mode: save “” save 900 1 // Synchronize the storage at least once within 900 seconds save XXX save 60 10000

6.AOF log append mode

AOF persists all write commands executed by the server and restores the data set by re-executing these commands when the server starts, turning this mode off by default.

How to enable AOF mode:

Appendonly yes #appendfsync always // Fsync is executed every time a new command is generated. Everysec appendfsync everysec // fsync once per second #appendfsync no // never fsync(leave it to the operating system, maybe once for a long time) For other parameters, please refer to the redis. Conf configuration file for details

7.Redis classic practical scenario – cache

7.1 Why Cache is Used

Frequently queried data, rarely modified data stored in the cache, reduce database access, reduce database pressure and cache is generally memory, access speed is relatively fast.

7.2 What data is suitable for caching

Frequent queries: Caching is about providing efficient access to data queries. Rarely modified: The cache and database should be modified simultaneously when modified such as: region data, item categories, data dictionary menu (regardless of permissions)

7.3 Selecting an Appropriate Cache

Hibernate level 2 cache, MyBatis level 2 cache does not support cluster caching by default, use Redis instead

7.4 How Do I Store Data

1)

Json: Converts the data to a JSON string

When saving cache:

Java Object-----------> JSON Character string

Get cache:

Json string -------->Java Object-

Json framework:

jdk-json-lib jackson gson fastjson

2) Binary storage

The binary serialization framework implements the serialization of data to be stored

8. Implement menu caching

The last

I here organized a Redis database data document Java systematic information :(including Java core knowledge points, Spring series of family drum, interview topics and 21 years of the latest Internet real questions, e-books, etc.) friends who need to pay attention to the public number [procedures yuan small wan] can be obtained.