提交 37b2e923 编写于 作者: Q qinxiaodong@pannk.com

集成Redis

上级 2246f3a9
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>springboot-demo</artifactId>
<groupId>com.pannk</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>integrate-redis</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<exclusions>
<exclusion>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
</dependency>
<!--<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>-->
</dependencies>
</project>
\ No newline at end of file
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<String,Object> 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<RedisClientInfo> 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();
}
}
}
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;
}
}
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
......@@ -16,6 +16,7 @@
<module>integrate-mybatisplus</module>
<module>testing</module>
<module>integrate-druid</module>
<module>integrate-redis</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册