diff --git a/integrate-redis/pom.xml b/integrate-redis/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..cd4c5024d9e44894e2f9b9b6ef51591ea7f31ce3 --- /dev/null +++ b/integrate-redis/pom.xml @@ -0,0 +1,43 @@ + + + + springboot-demo + com.pannk + 1.0 + + 4.0.0 + + integrate-redis + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-data-redis + + + io.lettuce + lettuce-core + + + + + redis.clients + jedis + + + org.projectlombok + lombok + 1.18.4 + + + + \ No newline at end of file diff --git a/integrate-redis/src/main/java/com/pannk/demo/App.java b/integrate-redis/src/main/java/com/pannk/demo/App.java new file mode 100644 index 0000000000000000000000000000000000000000..1668738fcbf80ae7d9afde59917b1d3b0685cec9 --- /dev/null +++ b/integrate-redis/src/main/java/com/pannk/demo/App.java @@ -0,0 +1,43 @@ +package com.pannk.demo; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.types.RedisClientInfo; + +import java.util.List; + +/** + * Created by wolf on 20-11-13. + */ +@Slf4j +@SpringBootApplication +public class App implements CommandLineRunner{ + + @Autowired + private RedisTemplate redisTemplate; + + public static void main(String[] args) { + SpringApplication.run(App.class,args); + } + + + @Override + public void run(String... args) throws Exception { + /*redisTemplate.opsForValue().set("hello","Hello world redis"); + String hello = (String) redisTemplate.opsForValue().get("hello"); + List clientList = redisTemplate.getClientList(); + clientList.stream().forEach(info->{ + log.error("info:{}",info); + }); + log.error("=========hello:{}",hello); +*/ + for (int i = 0; i < 1000; i++) { + new Thread(() -> redisTemplate.opsForValue().set("key"+Thread.currentThread().getName(),"The value is "+Thread.currentThread().getId())).start(); + } + + } +} diff --git a/integrate-redis/src/main/java/com/pannk/demo/config/RedisConfig.java b/integrate-redis/src/main/java/com/pannk/demo/config/RedisConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..84286f777d2f1bc6d45997cf5083c666ae83423d --- /dev/null +++ b/integrate-redis/src/main/java/com/pannk/demo/config/RedisConfig.java @@ -0,0 +1,23 @@ +package com.pannk.demo.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +/** + * Created by wolf on 20-11-13. + */ +@Configuration +public class RedisConfig { + + @Bean + public RedisTemplate getRedisTemplate(RedisConnectionFactory redisConnectionFactory){ + RedisTemplate redisTemplate = new RedisTemplate(); + redisTemplate.setConnectionFactory(redisConnectionFactory); + redisTemplate.setKeySerializer(new StringRedisSerializer()); + redisTemplate.setValueSerializer(new StringRedisSerializer()); + return redisTemplate; + } +} diff --git a/integrate-redis/src/main/resources/application.yml b/integrate-redis/src/main/resources/application.yml new file mode 100644 index 0000000000000000000000000000000000000000..3ef22f10fe425be5230c8cd34cc96a732fb187ad --- /dev/null +++ b/integrate-redis/src/main/resources/application.yml @@ -0,0 +1,14 @@ +spring: + main: + banner-mode: off + redis: + host: localhost + port: 6379 + password: + database: 0 + jedis: + pool: + max-idle: 10 + min-idle: 10 + max-wait: -1ms + max-active: 100 diff --git a/pom.xml b/pom.xml index 7d47ea06bb7cd0b716869d117e250ce9ac834751..1a54a731b134baf100bb7c3b588644ee3f026220 100644 --- a/pom.xml +++ b/pom.xml @@ -16,6 +16,7 @@ integrate-mybatisplus testing integrate-druid + integrate-redis org.springframework.boot