V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  EminemW  ›  全部回复第 62 页 / 共 77 页
回复总数  1531
1 ... 58  59  60  61  62  63  64  65  66  67 ... 77  
2020-04-10 15:18:23 +08:00
回复了 WhereverYouGo 创建的主题 Java SpringBoot RedisTemplate 如何缓存类?
我是自己封装了 RedisUtil 来用,
2020-04-10 15:10:44 +08:00
回复了 WhereverYouGo 创建的主题 Java SpringBoot RedisTemplate 如何缓存类?
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration;
import org.springframework.data.redis.core.StringRedisTemplate;

/**
* Redis 配置
*
*/
@Slf4j
@Configuration
public class RedisConfig {

/**
* 配置 lettuce 连接池
* @return
*/
@Bean
@ConfigurationProperties(prefix = "spring.redis.lettuce.pool")
public GenericObjectPoolConfig redisPool() {
return new GenericObjectPoolConfig<>();
}

/**
* 配置数据源
* @return
*/

@Bean("redisConf")
@Primary
@ConfigurationProperties(prefix = "spring.redis")
public RedisStandaloneConfiguration redisConfig() {
return new RedisStandaloneConfiguration();
}

@Bean("redis1Conf")
@ConfigurationProperties(prefix = "spring.redis1")
public RedisStandaloneConfiguration redisConfig1() {
return new RedisStandaloneConfiguration();
}

/**
* 配置连接工厂
* @param poolConfig
* @param redisConfig
* @return
*/

@Bean("factory")
@Primary
public LettuceConnectionFactory factory(GenericObjectPoolConfig poolConfig,@Qualifier("redisConf") RedisStandaloneConfiguration redisConfig) {
LettuceClientConfiguration clientConfiguration = LettucePoolingClientConfiguration.builder().poolConfig(poolConfig).build();
return new LettuceConnectionFactory(redisConfig, clientConfiguration);
}

@Bean("factory1")
public LettuceConnectionFactory factory1(GenericObjectPoolConfig poolConfig,@Qualifier("redis1Conf") RedisStandaloneConfiguration redisConfig) {
LettuceClientConfiguration clientConfiguration = LettucePoolingClientConfiguration.builder().poolConfig(poolConfig).build();
return new LettuceConnectionFactory(redisConfig, clientConfiguration);
}


/**
* 默认 redis0
* @param connectionFactory
* @return
*/
@Bean
@Primary
public StringRedisTemplate redisTemplate(LettuceConnectionFactory connectionFactory) {
return getRedisTemplate(connectionFactory);
}

@Bean("redisTemplate1")
public StringRedisTemplate redisTemplate1(@Qualifier("factory1")LettuceConnectionFactory factory) {
return getRedisTemplate(factory);
}

@Bean
@Primary
public RedisUtil redis0Util(StringRedisTemplate redisTemplate) {
return new RedisUtil(redisTemplate);
}

@Bean("redis1")
public RedisUtil redis1Util(@Qualifier("redisTemplate1") StringRedisTemplate redisTemplate) {
return new RedisUtil(redisTemplate);
}

private StringRedisTemplate getRedisTemplate(LettuceConnectionFactory factory) {
StringRedisTemplate template = new StringRedisTemplate();
template.setConnectionFactory(factory);
template.afterPropertiesSet();
return template;
}

}


//注入的时候
@Autowired
private RedisTemplate redis0;

@Autowired
@Qualifier("redis1")
private RedisTemplate redis1;
@b821025551b 应用层应该用啥,我用的是 Big Decimal
2020-04-09 01:23:34 +08:00
回复了 a1274598858 创建的主题 Apple 已升级 IOS13.4.1,就为了体验下深圳通...
Apple pay 绑个银行卡不就好了,刷的时候按两下锁屏键调出 apple pay 界面,然后把手机靠近刷卡机就好了。公交地铁都能用,还有优惠
2020-04-09 01:10:14 +08:00
回复了 aydd2004 创建的主题 程序员 请教个诡异的邮箱问题
说到网易还有更诡异的呢,我的 PC 端网易有道云笔记已经几个月没办法同步了,卸载重装也解决不了,Web 端跟 ios 端没问题
2020-04-08 21:40:38 +08:00
回复了 di94sh 创建的主题 分享发现 删库跑路新姿势
注销不是真的删数据吧,只是解绑,数据打个 flag…
不还是需要 app 吗……
2020-04-08 18:05:28 +08:00
回复了 bzw875 创建的主题 上海 老婆想换房,要贷款一百万我怂了
既然换房卖一套买一套,抵得上大部分吧
2020-04-06 12:27:18 +08:00
回复了 Reatence 创建的主题 王者荣耀 王者的服务器分布在哪?
@Nadao 玩操作英雄时比较需要低延时
@kookio 这样看来我原来大部分加 static 的变量,可以不用加了
@kookio 感谢,这样讲我就懂了
2020-04-04 18:31:33 +08:00
回复了 whatalittleboy 创建的主题 分享发现 研究称每周食用 3~6 个鸡蛋为宜---咋研究出来的?
看运动量的吧,之前美国那个菲尔普斯一天 8 个鸡蛋
微信用 socket 的吧
2020-04-03 01:28:09 +08:00
回复了 storypanda 创建的主题 微信 如何看待微信小程序新规?
SaaS 改成帮每个商家维护一个开发者账号🙄
@xhinliang 我一般都是加上 static 的。。
@gemini767 SpringBoot 中的 Service 默认是单例的吧,在这种情况下,如果我有个类缓存 LoadingCache,那它用 static 修饰跟不用 static 修饰的效果是一样的吧。我一般是会用 static 修饰的,只是不知道哪个更好
@kookio 我的意思是 比如在这个 Service 里面有一个全局变量 /常量,假设它名为 EXPIRE,这个 EXPIRE 会被 Service 里面的几个方法使用,(外部不需要调用这个 EXPIRE ),那它用不用 static 修饰都不影响使用效果吧。
2020-03-30 17:09:11 +08:00
回复了 EminemW 创建的主题 问与答 一般接口保证幂等性的最佳实践是什么
@123444a 这个我知道,如果是一般的添加纪录请求呢,除了唯一索引,select+insert 还有没有更优雅的方法
2020-03-29 01:09:55 +08:00
回复了 findlisa 创建的主题 程序员 求问定时任务实现思路
@findlisa 接口返回的时候做生效时间判断不就好了?
1 ... 58  59  60  61  62  63  64  65  66  67 ... 77  
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5163 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 57ms · UTC 07:40 · PVG 15:40 · LAX 00:40 · JFK 03:40
Developed with CodeLauncher
♥ Do have faith in what you're doing.