当前位置: 首页 > news >正文

ps做网站尺寸多少像素公司网站设计要多少钱

ps做网站尺寸多少像素,公司网站设计要多少钱,前端学校网站开发视频,惠阳网络推广公司配置项 Spring Boot 3.x 的 redis 配置和 Spring Boot 2.x 是不一样的, 路径多了一个data spring:...data:redis:host: redis.hostport: redis.portpassword: redis.passworddatabase: redis.database兼容单例和集群的配置 开发时一般用一个Redis单例就足够, 测试和生产环境…

配置项

Spring Boot 3.x 的 redis 配置和 Spring Boot 2.x 是不一样的, 路径多了一个data

spring:...data:redis:host: @redis.host@port: @redis.port@password: @redis.password@database: @redis.database@

兼容单例和集群的配置

开发时一般用一个Redis单例就足够, 测试和生产环境再换成集群, 但是在application.yml中默认的 Redis 单例和集群配置格式是不同的, 如果要用同一套格式兼容两种配置, 需要自定义 RedisConnectionFactory 这个bean的初始化.

@Configuration
public class RedisConfig {@Value("${spring.data.redis.host}")public String host;@Value("${spring.data.redis.port}")public int port;@Value("${spring.data.redis.password}")public String password;@Value("${spring.data.redis.database}")public int database;@Beanpublic RedisTemplate<String, String> redisStringTemplate(RedisConnectionFactory redisConnectionFactory) {RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();redisTemplate.setConnectionFactory(redisConnectionFactory);redisTemplate.setDefaultSerializer(new StringRedisSerializer());return redisTemplate;}@Beanpublic RedisTemplate<String, byte[]> redisBytesTemplate(RedisConnectionFactory redisConnectionFactory) {RedisTemplate<String, byte[]> redisTemplate = new RedisTemplate<>();redisTemplate.setConnectionFactory(redisConnectionFactory);RedisSerializer<String> redisKeySerializer = new StringRedisSerializer();redisTemplate.setKeySerializer(redisKeySerializer);redisTemplate.setHashKeySerializer(redisKeySerializer);redisTemplate.setValueSerializer(RedisSerializer.byteArray());redisTemplate.setHashValueSerializer(RedisSerializer.byteArray());return redisTemplate;}@Beanpublic RedisConnectionFactory lettuceConnectionFactory() {if (host.contains(",")) {RedisClusterConfiguration config = new RedisClusterConfiguration(Arrays.asList(host.split(",")));config.setMaxRedirects(3);if (password != null && !password.isEmpty()) {config.setPassword(RedisPassword.of(password));}LettuceConnectionFactory factory = new LettuceConnectionFactory(config);factory.afterPropertiesSet();return factory;} else {RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();config.setHostName(host);config.setPort(port);config.setDatabase(database);if (password != null && !password.isEmpty()) {config.setPassword(RedisPassword.of(password));}LettuceConnectionFactory factory = new LettuceConnectionFactory(config);factory.afterPropertiesSet();return factory;}}}

这样, 当配置改为集群时, 只需要修改 spring.data.redis.host 的内容为 1.1.1.1:6379,1.1.1.2:6379,1.1.1.3:6379这样的格式就可以了.

使用 Byte 作为值存储

ByteUtil.java

public class ByteUtil {public static byte[] toByte(String str) {if (str == null) return null;return str.getBytes();}public static byte[][] toByte(String[] strs) {if (strs == null) return null;byte[][] arr = new byte[strs.length][];for (int i = 0; i < strs.length; i++) {arr[i] = strs[i].getBytes();}return arr;}public static String toString(byte[] bytes) {return bytes == null ? null : new String(bytes);}public static Set<String> toString(Set<byte[]> byteset) {if (byteset == null) return null;return byteset.stream().map(String::new).collect(Collectors.toSet());}public static List<String> toStrings(List<byte[]> byteslist) {if (byteslist == null) return null;return byteslist.stream().map(String::new).collect(Collectors.toList());}public static byte[] toByte(int x) {ByteBuffer buffer = ByteBuffer.allocate(Integer.BYTES);buffer.putInt(x);return buffer.array();}public static int toInteger(byte[] bytes) {ByteBuffer buffer = ByteBuffer.allocate(Integer.BYTES);buffer.put(bytes);buffer.flip();//need flipreturn buffer.getInt();}public static byte[] toByte(long x) {ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);buffer.putLong(x);return buffer.array();}public static long toLong(byte[] bytes) {ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);buffer.put(bytes);buffer.flip();//need flipreturn buffer.getLong();}public static byte[] toByte(Object object) {if (object == null) return null;try (ByteArrayOutputStream baos = new ByteArrayOutputStream();ObjectOutputStream oos = new ObjectOutputStream(baos)) {oos.writeObject(object);return baos.toByteArray();} catch (IOException e) {throw new RuntimeException(e);}}public static <T> List<T> toObjs(List<byte[]> byteslist) {if (byteslist == null) return null;List<T> list = new ArrayList<>();for (byte[] bytes : byteslist) {T t = toObj(bytes);list.add(t);}return list;}@SuppressWarnings("unchecked")public static <T> T toObj(byte[] bytes) {if (bytes == null || bytes.length < 8) return null;try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);ObjectInputStream ois = new ObjectInputStream(bais)) {return (T)ois.readObject();} catch (IOException|ClassNotFoundException e) {throw new RuntimeException(e);}}
}

在服务中的调用方式


@Autowired
private RedisTemplate<String, byte[]> redisBytesTemplate;@Override
public Boolean hasKey(String key) {return redisBytesTemplate.hasKey(key);
}@Override
public Boolean hashHasKey(String key, String field) {return redisBytesTemplate.opsForHash().hasKey(key,field);
}@Override
public Integer hashGetInt(String key, String field) {HashOperations<String, String, byte[]> opsForHash = redisBytesTemplate.opsForHash();byte[] bytes = opsForHash.get(key, field);return bytes == null? null : ByteUtil.toInteger(bytes);
}@Override
public void hashSetInt(String key, String field, int value) {HashOperations<String, String, byte[]> opsForHash = redisBytesTemplate.opsForHash();opsForHash.put(key, field, ByteUtil.toByte(value));
}@Override
public <T> T hashGetObj(String key, String field) {HashOperations<String, String, byte[]> opsForHash = redisBytesTemplate.opsForHash();return ByteUtil.toObj(opsForHash.get(key, field));
}@Override
public <T> void hashSetObj(String key, String field, T value) {HashOperations<String, String, byte[]> opsForHash = redisBytesTemplate.opsForHash();opsForHash.put(key, field, ByteUtil.toByte(value));
}/*** @param timeout seconds to block*/
@Override
public <T> T bLPopObj(int timeout, String key) {ListOperations<String, byte[]> opsForList = redisBytesTemplate.opsForList();byte[] bytes = opsForList.leftPop(key, timeout, TimeUnit.SECONDS);return ByteUtil.toObj(bytes);
}@Override
public <T> Long rPush(String key, T value) {ListOperations<String, byte[]> opsForList = redisBytesTemplate.opsForList();return opsForList.rightPush(key, ByteUtil.toByte(value));
}

参考

  • https://vincentbogousslavsky.com/post/configuration-for-spring-data-redis-reactive-for-connecting
    创建 RedisClusterConfiguration
  • https://blog.csdn.net/weixin_67601403/article/details/129706748
    创建 RedisConnectionFactory lettuceConnectionFactory
  • https://cloud.tencent.com/developer/article/2371793
    默认的级联配置方式
http://www.hkea.cn/news/189558/

相关文章:

  • 昆明做大的网站开发公司google网页搜索
  • 做网站运营需要什么证宁波靠谱营销型网站建设
  • 天津进口网站建设电话青岛网站建设公司
  • 游戏币网站建设win7优化大师官方网站
  • 技术专业网站建设班级优化大师网页版登录
  • 外国网站上做雅思考试台州百度推广优化
  • 男女做那种的的视频网站国内最好的搜索引擎
  • 泉州做网站优化价格成功品牌策划案例
  • 做网站去哪个平台资源优化排名网站
  • 备案的网站名称可以改吗百度青岛代理公司
  • 专做进口批发的网站关键词优化多少钱
  • 做网站有了空间在备案吗百度权重高的网站有哪些
  • 做空间的网站著名的网络营销案例
  • 做网站客户尾款老不给怎么办百度推广年费多少钱
  • 想要将网站信息插到文本链接怎么做百度关键词搜索
  • 江苏网站备案要多久seo域名综合查询
  • 大型网站建设机构津seo快速排名
  • 建设证件查询官方网站宁波做网站的公司
  • 那些网站招聘在家里做的客服网店推广策略
  • 湘西 网站 建设 公司sem代运营托管公司
  • 用css为wordpress排版西安seo外包服务
  • vs2005做网站百度推广官方网站登录入口
  • 乐从网站建设公司北京seo优化推广
  • 如何在网上接做网站的小项目市场监督管理局电话
  • 淘宝购物站优化
  • 石家庄最新疫情轨迹河南网站优化公司哪家好
  • 网站色彩搭配服务器ip域名解析
  • 哪个网站专业做安防如何注册域名网站
  • 穆棱市住房和城乡建设局网站关键词词库
  • 成都网站建设市场什么是网络营销的核心