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

中国建设工程造价网站可视化微信小程序制作工具

中国建设工程造价网站,可视化微信小程序制作工具,定制美瞳网站建设,网站工程是干啥的配置项 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.hostport: redis.portpassword: redis.passworddatabase: 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 RedisTemplateString, String redisStringTemplate(RedisConnectionFactory redisConnectionFactory) {RedisTemplateString, String redisTemplate new RedisTemplate();redisTemplate.setConnectionFactory(redisConnectionFactory);redisTemplate.setDefaultSerializer(new StringRedisSerializer());return redisTemplate;}Beanpublic RedisTemplateString, byte[] redisBytesTemplate(RedisConnectionFactory redisConnectionFactory) {RedisTemplateString, byte[] redisTemplate new RedisTemplate();redisTemplate.setConnectionFactory(redisConnectionFactory);RedisSerializerString 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 SetString toString(Setbyte[] byteset) {if (byteset null) return null;return byteset.stream().map(String::new).collect(Collectors.toSet());}public static ListString toStrings(Listbyte[] 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 ListT toObjs(Listbyte[] byteslist) {if (byteslist null) return null;ListT 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 RedisTemplateString, 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) {HashOperationsString, 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) {HashOperationsString, String, byte[] opsForHash redisBytesTemplate.opsForHash();opsForHash.put(key, field, ByteUtil.toByte(value)); }Override public T T hashGetObj(String key, String field) {HashOperationsString, String, byte[] opsForHash redisBytesTemplate.opsForHash();return ByteUtil.toObj(opsForHash.get(key, field)); }Override public T void hashSetObj(String key, String field, T value) {HashOperationsString, 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) {ListOperationsString, 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) {ListOperationsString, byte[] opsForList redisBytesTemplate.opsForList();return opsForList.rightPush(key, ByteUtil.toByte(value)); }参考 https://vincentbogousslavsky.com/post/configuration-for-spring-data-redis-reactive-for-connecting 创建 RedisClusterConfigurationhttps://blog.csdn.net/weixin_67601403/article/details/129706748 创建 RedisConnectionFactory lettuceConnectionFactoryhttps://cloud.tencent.com/developer/article/2371793 默认的级联配置方式
http://www.hkea.cn/news/14499626/

相关文章:

  • 电影网站怎么建设网站认证怎么做
  • 买网站账号做推广威海优化推广
  • 网站搭建需要多少钱?韩国网站never官网
  • 桂林北站离阳朔多远网站建设好吗
  • 怎么建立网站 个人热点网站的三种基本类型
  • 重庆网站备案注销海口建设工程信息网站
  • 天津企业网站推广方法凡科网站免费版怎么做
  • 东平县建设局信息网站浙江省城乡建设厅官网
  • 电子商务网站建设学什么软件市政工程建设规范免费下载网站
  • 在网站上可以做哪些互动活动网站怎么做关键词库
  • 张家港百度网站推广企业培训课程ppt
  • asp网站管理系统源码莱芜话题莱芜在线牛泉
  • 深圳网站建设方案书网站建设款属于什么科目
  • 2022小说排行榜百度风云榜sem优化推广
  • 做微官网什么网站好小区百货店网怎么做网站
  • 网站建设与维护是做什么做网站的基本功能
  • 网站建设进度及实过程百度seo点击软件
  • 泾阳县建设局网站小程序功能
  • 天眼查网站南宁网站建设优化案例
  • 公司可以备案几个网站wordpress的登陆地址修改密码
  • 建网站可以卖钱网站开发后端作用
  • 电商网站建设流程千万别自学软件编程
  • 东台市住房和建设局网站wordpress外网固定链接
  • 网站搜索引擎怎样做wordpress选了中文还是英文
  • 湖南网站建设找拉米拉自己小程序制作流程
  • 网站demo怎么做济宁百度推广价格
  • 做网站要什么知识条件在网站中动态效果怎么做
  • 建设教育信息网站工作总结杭州计算机公司排名
  • 企业网站响应式googleplaystore
  • 网站最新程序策划书c2c电子商务网站策划