From 89a72d96cd337256a371b20d47dba15fd0dfe91e Mon Sep 17 00:00:00 2001 From: javahongxi Date: Mon, 24 Dec 2018 23:20:21 +0800 Subject: [PATCH] whatsmars-redis demo --- whatsmars-spring-boot/pom.xml | 10 +++++++ .../org/hongxi/whatsmars/spring/boot/App.java | 2 ++ .../spring/boot/controller/InitRunner.java | 7 +++++ .../src/main/resources/application.yml | 27 +++++++++++++++++++ 4 files changed, 46 insertions(+) diff --git a/whatsmars-spring-boot/pom.xml b/whatsmars-spring-boot/pom.xml index ec2b5844..72b33eb5 100644 --- a/whatsmars-spring-boot/pom.xml +++ b/whatsmars-spring-boot/pom.xml @@ -98,6 +98,16 @@ + + + org.springframework.boot + spring-boot-starter-data-redis + + + org.hongxi + whatsmars-redis + 1.0-SNAPSHOT + diff --git a/whatsmars-spring-boot/src/main/java/org/hongxi/whatsmars/spring/boot/App.java b/whatsmars-spring-boot/src/main/java/org/hongxi/whatsmars/spring/boot/App.java index d7dbf032..bcb627de 100644 --- a/whatsmars-spring-boot/src/main/java/org/hongxi/whatsmars/spring/boot/App.java +++ b/whatsmars-spring-boot/src/main/java/org/hongxi/whatsmars/spring/boot/App.java @@ -4,6 +4,7 @@ import org.hongxi.whatsmars.spring.boot.config.UserConfig; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ImportResource; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; @@ -15,6 +16,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; @SpringBootApplication @EnableConfigurationProperties({UserConfig.class}) @ImportResource(locations={"classpath*:spring/*.xml"}) +@ComponentScan({"org.hongxi.whatsmars.spring.boot", "org.hongxi.whatsmars.redis.client"}) public class App { public static void main(String[] args) { diff --git a/whatsmars-spring-boot/src/main/java/org/hongxi/whatsmars/spring/boot/controller/InitRunner.java b/whatsmars-spring-boot/src/main/java/org/hongxi/whatsmars/spring/boot/controller/InitRunner.java index 6cb90978..0ff3622f 100644 --- a/whatsmars-spring-boot/src/main/java/org/hongxi/whatsmars/spring/boot/controller/InitRunner.java +++ b/whatsmars-spring-boot/src/main/java/org/hongxi/whatsmars/spring/boot/controller/InitRunner.java @@ -1,5 +1,6 @@ package org.hongxi.whatsmars.spring.boot.controller; +import org.hongxi.whatsmars.redis.client.service.RedisStringService; import org.hongxi.whatsmars.spring.boot.async.MessageService; import org.hongxi.whatsmars.spring.boot.dao.UserMapper; import org.slf4j.Logger; @@ -22,6 +23,8 @@ public class InitRunner implements CommandLineRunner { private UserMapper userMapper; @Autowired private MessageService messageService; + @Autowired + private RedisStringService redisStringService; @Override public void run(String... args) throws Exception { @@ -31,5 +34,9 @@ public class InitRunner implements CommandLineRunner { for (int i = 0; i < 10; i++) { messageService.send("message" + i); } + + String key = "domain"; + redisStringService.set(key, "hongxi.org", 60); // 60s + System.out.println(redisStringService.get(key)); } } diff --git a/whatsmars-spring-boot/src/main/resources/application.yml b/whatsmars-spring-boot/src/main/resources/application.yml index 3e3ab2e3..8e9cf6ca 100644 --- a/whatsmars-spring-boot/src/main/resources/application.yml +++ b/whatsmars-spring-boot/src/main/resources/application.yml @@ -56,6 +56,15 @@ spring: test-while-idle: true time-between-eviction-runs-millis: 5000 validation-query: SELECT 1 + redis: + host: 127.0.0.1 + port: 6379 + timeout: 10000 + pool: + max-active: 8 + max-idle: 8 + max-wait: -1 + min-idle: 0 server: port: 8081 tomcat: @@ -87,6 +96,15 @@ spring: test-while-idle: true time-between-eviction-runs-millis: 5000 validation-query: SELECT 1 + redis: + host: 127.0.0.1 + port: 6379 + timeout: 10000 + pool: + max-active: 8 + max-idle: 8 + max-wait: -1 + min-idle: 0 server: port: 8081 tomcat: @@ -118,6 +136,15 @@ spring: test-while-idle: true time-between-eviction-runs-millis: 5000 validation-query: SELECT 1 + redis: + host: 127.0.0.1 + port: 6379 + timeout: 10000 + pool: + max-active: 8 + max-idle: 8 + max-wait: -1 + min-idle: 0 server: port: 8081 tomcat: -- GitLab