Springboot Connect Redis and dynamically switch database
As we all know, Redis has a db, in the Jedis can use the Select method to dynamically select the Redis database, but in the stringredistemplate provided by Springboot does not have this
With the further development of web2.0, the productivity of netizens is further improved and the total amount of storage begins to increase. While it is still a mode of reading and writing less, the amount of writing has been greatly improved. The
Redis Implement distributed lock
In the cluster and other multiple servers often used to synchronize the business, then the ordinary transaction is to meet the needs of the business, the need for distributed locks. Distributed locks are implemented
1, interface
/*** Priority to query member information from the cache* @param custnum* @return*/Public member Findmemberbycustnumfristbyredis (String custnum);
2. Implementation class
@OverridePublic member Findmemberbycustnumfristbyredis (String
I use the redis3.0 version. The 3.0 version mainly increased the Redis cluster function.
Prerequisites for Installation: Install Gcc:yum install gcc-c++
1, download the Redis source package.
2, the source package uploaded to the Linux server
3,
I. Understanding of Redis
1, NoSQL overviewBefore you know Redis, you should know the NoSQL.
(1) Nosql=not only SQL (read "N" "O" SQL instead of "no" SQL), is a relational database.
(2) Why need to use NoSQL. Gao Performance: High concurrent read
Yesterday after analyzing the Redis event-driven model very easily, today I'm going to look at Anet's code, Anet is a small encapsulation of Redis's network operations for Client/server. The official explanation for this file in the code is:
/*
Interface processing logic: Get weather forecast information, 1500 City weather: The first time the program processing, will first determine whether the Redis key exists, if there is, directly return the corresponding data; if there is no key, read
Using Redis to develop applications is a pleasant process, but as with other technologies, you need to remember a few things as well, based on Redis application design. Before, you might have a chest of the whole pattern of relational database
(Error) DENIED Redis is running in protected mode because protected mode is enabledRedis Protected-mode is a new feature added after 3.2, and in Redis.conf's comments we can see that his specific role and enabling conditions
Redis can only be linked
compression list in Redis
The compression list (ziplist) is one of the underlying implementations of the list key and hash keys. When a list key contains only a few list items, and each list item is either a small integer value or a shorter string,
I. Concept
In Redis, there is also a hash type for the structure of key-value pairs like other languages, and the key value of a redis hash type is itself a key-value pair structure.
Such as:
Key
value
User:1
Key
This is to share with you the use of Redis in Springboot, where the Redis Jedis client is used (here I docker running Redis, can refer to Docker to quickly build several popular third-party services ), Add dependencies as follows:
redis.clients
The internet is littered with code for distributed locks, mostly through setnx and expireThese two are not atomic operations, there will certainly be problems, there are many people by using SETNX value as the expiration time to compensate and so on.
First step: Add the middleware in the settings.py in the project directory middleware:# Session Middleware Django project is enabled by default session' Django.contrib.sessions.middleware.SessionMiddleware ',The second step: saving the session in
Redis is an open source, write with ANSI C language, support network, memory-based, persistent,Key-value database, and provides APIs in multiple languages. It is a data structure server for memory storage that can be used as a database, cache, and
I searched an article todayArticleNosql solution: Evaluation and comparison: MongoDB vs redis, Tokyo cabinet, and Berkeley dB. It is a Chinese translation version, which is well written by the author, but it takes several hours to insert 0.2 billion
Redis key)The redis key command is used to manage redis keys. Redis has a key for any data type--Redis command for deleting keys> Del key Redis transactionsRedis transactions can execute multiple commands at a time with the following three important
1. redis, as a memory database, needs to store a large amount of user data, but the data stored in redis is stored in the memory. Due to power failure or downtime, memory data will certainly be lost. To prevent data loss, usePersistence ModeTo back
I posted some transferred posts all day, and I have summarized them too little. write down what caused me a headache in redis some time ago. For this reason, the data of redis was originally migrated to tokyocabinet.
Redis is a nosql database with
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service