Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

Writing in the front

In the previous article, we learned how the SpringBoot project integrates Redis related component functionality, and the object involved inside the SpringBoot integrated Redis component is the RedisTemplate.

Let’s take a look at the methods provided by RedisTemplate to manipulate the Redis database and how they are used.

Let’s learn.

Count the RedisTemplate family of methods.

As far as methods are concerned, we still look on the basis of the source code, so that we can see some comprehensive, two can see more things, help to a deeper understanding.

afterPropertiesSet()

RedisTemplate initializes some parameters of the RedisTemplate

Use scenario: this method is called when the RedisTemplate is initialized. If you do not execute this method, you may get some unexplained errors, which may be caused by some parameters not initialized.

Specific code use:

@Bean public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) { RedisTemplate<String, Object> template = new RedisTemplate<>(); template.setConnectionFactory(factory); . . I left that out, and you can look it up in the previous article. . template.afterPropertiesSet(); return template; }Copy the code

Note: One thing to note is that RedisTemplate initialization in SpringBoot projects is usually done by configuring a class to perform a method, as you saw in the previous article.

Source code screenshot: source code is too long, may not be able to paste the whole, please move to the IDEA to view redistemplate.java

summary

Today we will just learn it for the first time. We will talk about the function and usage of this method first. Then we will introduce some interesting methods for this series every day.