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

网站建设书籍2013年的做网站得叫什么

网站建设书籍2013年的,做网站得叫什么,门户网站 字体,图书管理系统网站开发教程目录 一、Jedis 二、Lettuce 三、一个Demo Java集成Redis主要有3个方案#xff1a;Jedis、Lettuce和Redisson。 其中#xff0c;Jedis、Lettuce侧重于单例Redis#xff0c;而Redisson侧重于分布式服务。 项目资源在文末 一、Jedis 1、创建SpringBoot项目 2、引入依赖 …目录 一、Jedis 二、Lettuce 三、一个Demo Java集成Redis主要有3个方案Jedis、Lettuce和Redisson。 其中Jedis、Lettuce侧重于单例Redis而Redisson侧重于分布式服务。 项目资源在文末 一、Jedis 1、创建SpringBoot项目 2、引入依赖 其中jedis是所需要的依赖lombok是为了方便后续配置 dependencygroupIdredis.clients/groupIdartifactIdjedis/artifactId/dependencydependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactId/dependency 3、 配置yml #redis配置--jedis版 jedis:pool:#redis服务器的IPhost: localhost#redis服务器的Portport: 6379#数据库密码password:#连接超时时间timeout: 7200#最大活动对象数maxTotall: 100#最大能够保持idel状态的对象数maxIdle: 100#最小能够保持idel状态的对象数minIdle: 50#当池内没有返回对象时最大等待时间maxWaitMillis: 10000#当调用borrow Object方法时是否进行有效性检查testOnBorrow: true#当调用return Object方法时是否进行有效性检查testOnReturn: true#“空闲链接”检测线程检测的周期毫秒数。如果为负值表示不运行“检测线程”。默认为-1.timeBetweenEvictionRunsMillis: 30000#向调用者输出“链接”对象时是否检测它的空闲超时testWhileIdle: true# 对于“空闲链接”检测线程而言每次检测的链接资源的个数。默认为3.numTestsPerEvictionRun: 50 4、导入配置文件和加载配置类 导入配置文件JedisProperties导入yml文件内容 加载配置类JedisConfig加载JedisProperties内容 ①JedisProperties package com.example.redis_java.config;import lombok.Getter; import lombok.Setter; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component;Component ConfigurationProperties(prefix jedis.pool) Getter Setter public class JedisProperties {private int maxTotall;private int maxIdle;private int minIdle;private int maxWaitMillis;private boolean testOnBorrow;private boolean testOnReturn;private int timeBetweenEvictionRunsMillis;private boolean testWhileIdle;private int numTestsPerEvictionRun;private String host;private String password;private int port;private int timeout; } ②JedisConfig 说明如果SpringBoot是2.x版本JedisConfig请使用注释掉的两行代码而不是它们对应的上面的代码 package com.example.redis_java.config;import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.util.StringUtils; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig;import java.time.Duration;Configuration public class JedisConfig {/*** jedis连接池** param jedisProperties* return*/Beanpublic JedisPool jedisPool(JedisProperties jedisProperties) {JedisPoolConfig config new JedisPoolConfig();config.setMaxTotal(jedisProperties.getMaxTotall());config.setMaxIdle(jedisProperties.getMaxIdle());config.setMinIdle(jedisProperties.getMinIdle());config.setMaxWait(Duration.ofMillis(jedisProperties.getMaxWaitMillis()));// config.setMaxWaitMillis(jedisProperties.getMaxWaitMillis());config.setTestOnBorrow(jedisProperties.isTestOnBorrow());config.setTestOnReturn(jedisProperties.isTestOnReturn());config.setTimeBetweenEvictionRuns(Duration.ofMillis(jedisProperties.getTimeBetweenEvictionRunsMillis()));// config.setTimeBetweenEvictionRunsMillis(jedisProperties.getTimeBetweenEvictionRunsMillis());config.setTestWhileIdle(jedisProperties.isTestWhileIdle());config.setNumTestsPerEvictionRun(jedisProperties.getNumTestsPerEvictionRun());if (StringUtils.hasText(jedisProperties.getPassword())) {return new JedisPool(config, jedisProperties.getHost(), jedisProperties.getPort(), jedisProperties.getTimeout(), jedisProperties.getPassword());}return new JedisPool(config, jedisProperties.getHost(), jedisProperties.getPort(), jedisProperties.getTimeout());} } ③项目结构 5、测试 ①测试前 ②测试类 package com.example.redis_java;import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool;SpringBootTest public class JedisTest {Autowiredprivate JedisPool jedisPool;Testpublic void testConnection() {System.out.println(jedisPool);Jedis jedis jedisPool.getResource();jedis.set(name, Trxcx);System.out.println(jedis.get(name));jedis.sadd(mySet, a, b, d);System.out.println(jedis.smembers(mySet));// jedis的方法名就是redis的命令jedis.close();} } ③项目结构 ④运行测试类 ⑤测试后 说明jedis的方法名就是redis的命令。如sadd、smembers。 二、Lettuce Lettuce配置比较简单这里直接在上一个项目的基础上进行配置新项目配置Lettuce方法一致。 1、引入依赖 !--Lettuce依赖--dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-redis/artifactId/dependency 2、配置yml 如果有密码设置对应的密码。 spring:redis:host: 127.0.0.1port: 6379# password: admin 3、测试 ①编写测试类 package com.example.redis_java;import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.redis.core.StringRedisTemplate;SpringBootTest public class LettureTest {Autowiredprivate StringRedisTemplate template;// 约定// 操作redis的key是字符串// value是字符串类型或字符串类型元素Testpublic void testRedis() {template.opsForValue().set(name, Trxcx);System.out.println(template.opsForValue().get(name));template.opsForSet().add(Games,RDR2,CS2,ACOd);System.out.println(template.opsForSet().members(Games));// 操作string// template.opsForValue().xx();// 操作hash// template.opsForHash().xx();// 操作list// template.opsForList().xx();// 操作set// template.opsForSet().xx();// 操作zset// template.opsForZSet().xx();// spring-data-redis方法是redis命令全称// template.opsForList().rightPush() //rpush// 全局命令在template类上// template.keys(*);} } ②项目结构 ③运行测试类 4、说明 ①Lettuce使用StringRedisTemplate的一个对象完成对Redis的操作不存在像Jedis那样获取Redis资源使用完再关闭的情况。 ②Lettuce通过opsForxxx完成对不同value类型的操作例如 opsForValue()是操作String类型的opsForHash()是操作Hash类型的opsForList()是操作List类型的opsForSet()是操作Set类型的opsForZSet()是操作Zset类型的 ③Lettuce的方法名是Redis命令的全称 例如template.opsForList().rightPush()对应Redis中的rpush命令 ④全局命令作用在StringRedisTemplate对象上 例如template.keys(*); 三、一个Demo 这个demo实现了每次刷新或者访问网页时阅读量1的效果。 启动SpringBoot项目后访问http://localhost:8080/detail.html每次刷新页面阅读量1。  项目资源链接 1、【免费】Redis-Java.zip资源-CSDN文库 2、【免费】RedisDemo.zip资源-CSDN文库
http://www.w-s-a.com/news/566496/

相关文章:

  • 柳州网站优化搜索引擎优化方法案例
  • 什么网站比较少人做响应式网站开发周期
  • 公司网站欢迎语工作期间员工花钱做的网站
  • 新网站该如何做网站优化呢网络营销网站设计
  • 旅游门户网站模板下载做策划网站推广怎么写简历
  • 建设隔离变压器移动网站wordpress动态导航
  • 平潭建设局网站中国免费素材网
  • 虚拟主机可以做视频视频网站吗做爰全过程免费的视频网站有声音
  • 专业做家电经销的网站网络管理系统有哪几部分组成
  • 自学网站编程网站名称需要注册吗
  • 网站后台管理系统怎么添加框安徽省工程建设协会网站
  • 雨花台网站建设wordpress找回
  • 四川哪家网站推广做的好网站开发人才需求
  • 什么网站可以找手工活做一站式服务平台官网
  • 做购物网站的步骤网站核心词如何做
  • 做品牌设计网站公司网站没做301怎么做301
  • 服务流程企业网站wordpress文章的使用
  • 网站开发组合淘宝网站开发选什么类目
  • 广东手机网站建设个人电脑做网站主机
  • 健身俱乐部网站开发文档建一个网站需要什么条件
  • 买的网站模板怎么做建设行政管理部门网站
  • 怎么让百度多收录网站关键词seo深圳
  • 陕西交通建设集团网站体检个人网站设计模板田田田田田田田田
  • ae模板网站推荐安徽建筑信息平台
  • 新网站建设代理商wordpress模板商店
  • 中国十大设计素材网站wordpress发布失败
  • 江西省建设监理网站网页制作与设计是什么
  • 在招聘网站做销售怎么样网址你懂我意思正能量不用下载ios
  • 高端企业网站定制公司企业网站2000元
  • 成都网站建设:河北省建设工程质量监督网站