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

网站建设技术概述网站建设走的路线风格

网站建设技术概述,网站建设走的路线风格,建设搜索引擎网站,怎么给网站做备份呢目录 一、前言二、集成配置2.1、POM2.2、添加配置文件application.yml2.3、编写配置文件2.4、编写启动类2.5、编写测试类测试是否连接成功 一、前言 这里会使用到spring-boot-starter-data-redis包#xff0c;spring boot 2的spring-boot-starter-data-redis中#xff0c;默… 目录 一、前言二、集成配置2.1、POM2.2、添加配置文件application.yml2.3、编写配置文件2.4、编写启动类2.5、编写测试类测试是否连接成功 一、前言 这里会使用到spring-boot-starter-data-redis包spring boot 2的spring-boot-starter-data-redis中默认使用的是lettuce作为redis客户端也推荐使用lettuceRedis使用哨兵集群这里会通过lettuce连接到哨兵获取对应Redis节点地址从而操作Redis。 Linux部署Redis Cluster高可用集群https://blog.csdn.net/weixin_44606481/article/details/134052367 二、集成配置 工程结构 2.1、POM parentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.3.12.RELEASE/version/parentdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter/artifactId/dependency!--springboot中的redis依赖--dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-redis/artifactId/dependency!-- lettuce pool 缓存连接池--dependencygroupIdorg.apache.commons/groupIdartifactIdcommons-pool2/artifactId/dependency!-- 使用jackson作为redis数据序列化 --dependencygroupIdcom.fasterxml.jackson.core/groupIdartifactIdjackson-databind/artifactIdversion2.11.4/version/dependency!-- SpringBoot测试包 --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependency/dependencies2.2、添加配置文件application.yml 因为我们用的spring-boot-starter-data-redis包会自动配置redis连接在配置文件中添加对应配置即可 spring:#redis配置信息redis:## Redis数据库索引默认为0database: 0## Redis服务器连接密码默认为空password: 123456## 连接超时时间毫秒timeout: 5000## 集群配置cluster:### 集群中所有节点nodes:- 172.16.8.186:7001- 172.16.8.186:7002- 172.16.8.186:7003- 172.16.8.186:7004- 172.16.8.186:7005- 172.16.8.186:7006### 最大重定向数最好为集群节点数比如第一台挂了连第二台第二台挂了连第三台这个是重新连接的最大数量max-redirects: 6lettuce:pool:## 连接池最大连接数使用负值表示没有限制max-active: 8## 连接池最大阻塞等待时间使用负值表示没有限制max-wait: -1## 连接池中的最大空闲连接max-idle: 8## 连接池中的最小空闲连接min-idle: 1## 集群配置cluster:refresh:# 支持集群拓扑动态感应刷新,自适应拓扑刷新是否使用所有可用的更新默认false关闭类似nacos定时刷新服务列表adaptive: true# 定时刷新时间 毫秒period: 2000# 打印lettuce debug日志方便查看读写分离效果 logging:pattern:console: %date{yyyy-MM-dd HH:mm:ss.SSS} | %highlight(%5level) [%green(%16.16thread)] %clr(%-50.50logger{49}){cyan} %4line -| %highlight(%msg%n)level:root: infoio.lettuce.core: debugorg.springframework.data.redis: debug2.3、编写配置文件 import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.PropertyAccessor; import com.fasterxml.jackson.databind.ObjectMapper; import io.lettuce.core.ReadFrom; import org.apache.commons.pool2.impl.GenericObjectPoolConfig; import org.springframework.boot.autoconfigure.data.redis.RedisProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.RedisSentinelConfiguration; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration; import org.springframework.data.redis.core.*; import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer;import java.util.HashSet;Configuration public class RedisConfig{/*** retemplate相关配置配置自定义序列化规则为jackson*/Beanpublic RedisTemplateString, Object redisTemplate(RedisConnectionFactory factory) {RedisTemplateString, Object template new RedisTemplate();// 配置连接工厂template.setConnectionFactory(factory);//使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值默认使用JDK的序列化方式Jackson2JsonRedisSerializer jacksonSeial new Jackson2JsonRedisSerializer(Object.class);ObjectMapper om new ObjectMapper();// 指定要序列化的域field,get和set,以及修饰符范围ANY是都有包括private和publicom.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);// 指定序列化输入的类型类必须是非final修饰的final修饰的类比如String,Integer等会跑出异常om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);jacksonSeial.setObjectMapper(om);// 值采用json序列化template.setValueSerializer(jacksonSeial);//使用StringRedisSerializer来序列化和反序列化redis的key值template.setKeySerializer(new StringRedisSerializer());// 设置hash key 和value序列化模式template.setHashKeySerializer(new StringRedisSerializer());template.setHashValueSerializer(jacksonSeial);template.afterPropertiesSet();return template;} }2.4、编写启动类 import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;SpringBootApplication public class LettuceApplication {public static void main(String[] args) {SpringApplication.run(LettuceApplication.class);} }2.5、编写测试类测试是否连接成功 import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.test.context.junit4.SpringRunner;RunWith(SpringRunner.class) SpringBootTest(classes LettuceApplication.class) public class LettuceTest {Autowiredprivate RedisTemplateString,Object redisTemplate;Testpublic void t1(){String key key1;System.out.println(插入数据到redis);redisTemplate.opsForValue().set(key,value1);Object value redisTemplate.opsForValue().get(key);System.out.println(从redis中获取到值为 value);Boolean delete redisTemplate.delete(key);System.out.println(删除redis中值 delete);} }
http://www.w-s-a.com/news/899130/

相关文章:

  • 麻花星空影视传媒制作公司网站美食网站网站建设定位
  • 网站的切图是谁来做学会网站 建设
  • 交通局网站建设方案答辩ppt模板免费下载 素材
  • 个人摄影网站推介网手机版
  • 有哪些免费的视频网站网站开发和竞价
  • 学校网站如何做广州商城型网站建设
  • 微网站建设哪家便宜易优建站系统
  • 推荐做木工的视频网站毕业设计做的网站抄袭
  • 网站导航页面制作wordpress调用文章阅读量
  • app小程序网站开发品牌购物网站十大排名
  • 用wordpress做购物网站龙岩品牌设计
  • 网站开发是指wordpress系统在线升级
  • 网站建设运营的灵魂是什么意思页面跳转中
  • 家政服务网站源码重庆建网站企业有哪些
  • 怎样分析一个网站做的好坏重庆长寿网站设计公司哪家专业
  • 百度助手app下载苏州seo关键词优化排名
  • 17网站一起做 佛山诸城网站建设多少钱
  • 郑州网站建设培训学校泉州做网站设计公司
  • 西峡做网站深圳建筑工务署官网
  • 单县网站惠州seo计费
  • 万网网站建设 优帮云怎样用记事本做网站
  • 注册域名后网站建设百度指数的功能
  • 怎么做伪静态网站山西网站建设设计
  • 做小型企业网站多少钱衡阳市建设局网站
  • 金华专业网站建设公司网站建设空间和服务器方式
  • 自己做的网站在浏览器上显示不安全吗wordpress revolution slider
  • 西安网站建设推广优化搜索引擎营销
  • 互联网站备案管理工作方案 工信部注册深圳公司需要什么条件
  • 网站网站服务器网站建设 物流
  • 国外开发网站手机网站建设制作