feign starter 使用实例
This commit is contained in:
33
examples/redis-example/pom.xml
Normal file
33
examples/redis-example/pom.xml
Normal file
@ -0,0 +1,33 @@
|
||||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.chinaunicom.ebtp</groupId>
|
||||
<artifactId>mall-ebtp-cloud-parent</artifactId>
|
||||
<version>0.0.1</version>
|
||||
</parent>
|
||||
|
||||
<groupId>com.chinaunicom.mall.ebtp.cloud</groupId>
|
||||
<artifactId>redis-example</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>redis-example</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.chinaunicom.ebtp</groupId>
|
||||
<artifactId>mall-ebtp-cloud-redis-starter</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -0,0 +1,11 @@
|
||||
package com.chinaunicom.mall.ebtp.cloud.redis.example;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class RedisExampleApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(RedisExampleApplication.class, args);
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.chinaunicom.mall.ebtp.cloud.redis.example.service;
|
||||
|
||||
public interface RedisExampleService {
|
||||
|
||||
public void readAndWrite();
|
||||
public void transactionHandle();
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package com.chinaunicom.mall.ebtp.cloud.redis.example.service.impl;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.chinaunicom.mall.ebtp.cloud.redis.example.service.RedisExampleService;
|
||||
import com.chinaunicom.mall.ebtp.cloud.redis.starter.handler.NumberHandler;
|
||||
import com.chinaunicom.mall.ebtp.cloud.redis.starter.handler.StringHandler;
|
||||
import com.chinaunicom.mall.ebtp.cloud.redis.starter.util.RedisUtil;
|
||||
|
||||
@Service
|
||||
public class RedisExampleServiceImpl implements RedisExampleService {
|
||||
/**
|
||||
* 演示工具类的基本使用方法
|
||||
*/
|
||||
@Override
|
||||
public void readAndWrite() {
|
||||
StringHandler sh = RedisUtil.getStringHandler();
|
||||
sh.set("example-key", "example-value");
|
||||
|
||||
System.out.println(sh.get("example-key"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 演示事务的使用方式
|
||||
*/
|
||||
@Override
|
||||
public void transactionHandle() {
|
||||
List execute = RedisUtil.getTransactionHandler(2).execute(handler -> {
|
||||
handler.watch("redis-string-handler-key", "redis-number-handler-key");// 监控这些key
|
||||
|
||||
// 开启事务
|
||||
handler.beginTransaction();
|
||||
|
||||
StringHandler stringHandler = handler.getStringHandler();
|
||||
stringHandler.set("redis-string-handler-key", "hello");
|
||||
stringHandler.append("redis-string-handler-key", "redis");
|
||||
stringHandler.append("redis-string-handler-key", "!");
|
||||
|
||||
// 获取对应事务数字助手
|
||||
NumberHandler numberHandler = handler.getNumberHandler();
|
||||
numberHandler.addLong("redis-number-handler-key", 100);
|
||||
numberHandler.incrementLong("redis-number-handler-key");
|
||||
numberHandler.incrementLong("redis-number-handler-key");
|
||||
numberHandler.incrementLong("redis-number-handler-key");
|
||||
|
||||
// 提交事务返回结果
|
||||
return handler.commit();
|
||||
});
|
||||
System.out.println(Arrays.toString(execute.toArray()));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
server:
|
||||
port: 8762
|
||||
max-http-header-size: 1000000
|
||||
|
||||
spring:
|
||||
redis:
|
||||
database: 0
|
||||
host: 125.32.114.204
|
||||
password: redis@CC1234
|
||||
port: 16379
|
||||
timeout: 6000
|
||||
ssl: false
|
||||
lettuce:
|
||||
pool:
|
||||
max-wait: -1ms
|
||||
max-active: 8
|
||||
max-idle: 8
|
||||
min-idle: 0
|
10
examples/redis-example/src/main/resources/application.yml
Normal file
10
examples/redis-example/src/main/resources/application.yml
Normal file
@ -0,0 +1,10 @@
|
||||
spring:
|
||||
profiles:
|
||||
active: redis
|
||||
application:
|
||||
name: mall-ebtp-cloud-demo
|
||||
|
||||
logging:
|
||||
level:
|
||||
root: info
|
||||
|
@ -0,0 +1,27 @@
|
||||
package com.chinaunicom.mall.ebtp.cloud.redis.example;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.chinaunicom.mall.ebtp.cloud.redis.example.service.RedisExampleService;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class RedisExampleTest {
|
||||
|
||||
private @Autowired RedisExampleService redisExampleService;
|
||||
|
||||
@Test
|
||||
public void testReadAndWrite() {
|
||||
redisExampleService.readAndWrite();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransaction() {
|
||||
redisExampleService.transactionHandle();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user