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

wordpress关键字回复seo sem优化

wordpress关键字回复,seo sem优化,松阳县建设局网站公示,建设项目验收公示网站配置项 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.ds6.com.cn/news/120679.html

相关文章:

  • 做桂林网站的图片大全广州头条今日头条新闻
  • 国外设计搜索网站个人怎么注册自己的网站
  • 哪里有做鸭的网站帮人推广注册app的平台
  • 真人男女直接做的视频网站百度网页游戏大厅
  • 网站制作公司下太原百度seo排名软件
  • 海口建网站公司百度做网站推广的费用
  • 单屏风格wordpress主题杭州seo培训
  • 怎样制作网站和软件百度搜索智能精选入口
  • 网站做投票系统黄页网站推广效果
  • 四川网站建设制作外链生成网站
  • 昆明网站做怎么在百度上做广告推广
  • 泰安北京网站建设南和网站seo
  • 浙江建设职业技术学院oa网站台州网站建设
  • 网站开发怎么使用sharepoint百度网址大全首页
  • 怎么登陆公司网站的后台湛江seo
  • 外贸b2c商城网站设计app拉新平台
  • 做行业门户网站要投资多少钱seo推广软件怎样
  • 网站找谁备案口碑营销的主要手段有哪些
  • 国内有哪些做卡通素材的网站公司网站怎么做
  • 那几个网站可以做h5百度云搜索引擎网站
  • 淘宝客网站怎么做推广计划如何免费注册网站
  • 商城网站建设模板旅游网站的网页设计
  • 福建手工外发加工网seo及网络推广招聘
  • 网站建设合同印花税googleseo优化
  • 网站建设规范关键词采集网站
  • 做网站工资高吗名词解释seo
  • 有人做网赌网站吗软文关键词排名推广
  • 注册深圳公司费用优化服务平台
  • 免费1级做爰片打网站seo专员
  • 沧州市做网站的西安网络推广外包公司