feign starter 使用实例

This commit is contained in:
Administrator
2020-10-30 08:46:35 +08:00
parent 980a0fc2f1
commit 599d6bc70e
40 changed files with 976 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -0,0 +1,8 @@
package com.chinaunicom.mall.ebtp.cloud.redis.example.service;
public interface RedisExampleService {
public void readAndWrite();
public void transactionHandle();
}

View File

@ -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()));
}
}

View File

@ -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

View File

@ -0,0 +1,10 @@
spring:
profiles:
active: redis
application:
name: mall-ebtp-cloud-demo
logging:
level:
root: info