After successful installation, open docker engine
Add domestic mirror
"registry-mirrors" : [ "http://hub-mirror.c.163.com" ],
Enter https://hub.docker.com/ and search redis, find the first official image
You can check how to start redis in the docker container
The relevant commands are as follows:
docker pull redis # Pull the remote redis image
docker run –name some-redis -p 6379:6379 -d redis #Start redis and expose it to the host’s 6379 Port
docker ps #View the currently running mirror process
docker restart some-redis #Restart a mirror
Start the SpringBoot project, configuration file
redis.host=localhost redis.maxTotal=5 redis.maxIdle=5 redis.testOnBorrow=true
Use Jedis to connect to redis, introduce pom
<dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> </dependency>
Add configuration class
@Bean @ConfigurationProperties("redis") public JedisPoolConfig jedisPoolConfig() { return new JedisPoolConfig(); } @Bean(destroyMethod = "close") public JedisPool jedisPool(@Value("${redis.host}") String host) { return new JedisPool(jedisPoolConfig(), host); }
Note: Jedis is not thread-safe, so you need to get it from JedisPool
The above is the detailed content of Docker+Redis+SpringBoot connection method. For more information, please follow other related articles on the PHP Chinese website!