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

源代码如何做网站郑州网站公司哪家好

源代码如何做网站,郑州网站公司哪家好,怎么查看网站快照,广告词大全⛰️个人主页: 蒾酒 🔥系列专栏:《spring boot实战》 🌊山高路远,行路漫漫,终有归途。 目录 前置条件 1.导依赖 2.配置连接信息以及连接池参数 3.配置序列化方式 4.编写测试 前置条件 已经初始化好一个spr…

 

⛰️个人主页:     蒾酒

🔥系列专栏:《spring boot实战》

🌊山高路远,行路漫漫,终有归途。


目录

前置条件

1.导依赖

2.配置连接信息以及连接池参数

3.配置序列化方式

4.编写测试


前置条件

已经初始化好一个spring boot项目且版本为3X,项目可正常启动。

作者版本为3.2.2

初始化教程:

新版idea(2023)创建spring boot3项目-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/qq_62262918/article/details/135785412?spm=1001.2014.3001.5501

1.导依赖

pom.xml:

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

如果还没安装redis可以参照这篇:

阿里云ECS使用docke搭建redis服务-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/qq_62262918/article/details/135707725?spm=1001.2014.3001.5502

2.配置连接信息以及连接池参数

application.yml:

server:port: 8080
spring:data:redis: # Redis连接配置host: localhost  # Redis主机地址port: 6379  # Redis端口号password: 123456  # 访问Redis所需密码database: 0  # 使用的数据库编号lettuce: #Lettuce客户端配置pool: # 连接池配置max-active: 8  # 最大活跃连接数max-wait: -1  # 最大等待时间(-1表示无限等待)max-idle: 8  # 最大空闲连接数min-idle: 0  # 最小空闲连接数

修改为你的连接信息即可。

这里要说的是:

Lettuce和Jedis两者都是Java连接Redis的客户端

选择使用Lettuce而不是Jedis的原因如下:

线程安全性:

  • Lettuce 是基于 Netty 构建的,它使用异步和事件驱动的方式处理连接。因此,它可以在多个线程之间共享一个连接而不需要额外的同步,因此在高并发环境下更高效。
  • Jedis 是基于阻塞 I/O 的,并且不是线程安全的,如果在多个线程中共享同一个 Jedis 实例,需要使用连接池进行同步管理,这可能引入额外的复杂性。

连接方式:

  • Lettuce 支持基于 Reactive Streams 的响应式编程模型,能够更好地与 Spring Reactor、Project Reactor 等框架集成,提供异步和非阻塞的操作。
  • Jedis 是同步的,并且在执行某些操作时会阻塞线程,这可能会影响应用程序的性能和响应性。

性能和扩展性:

  • Lettuce 的设计目标是高性能和扩展性,它可以更好地利用 Redis 4.0 中引入的一些新特性(如 Redis Sentinel 和 Redis Cluster)。
  • Jedis 的设计目标更偏向于简单易用,对于一些特殊的 Redis 集群模式可能支持不够完善。

维护和更新:

  • Lettuce 是一个活跃的项目,并且持续地得到更新和改进。
  • Jedis 在某些方面已经相对稳定,并且在一段时间内没有大的更新。

3.配置序列化方式

config目录下新建redis配置类

配置类代码如下:

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;/*** @author mijiupro*/
@Configuration
public class RedisConfig {@Beanpublic RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();redisTemplate.setConnectionFactory(connectionFactory);// 设置key和value的序列化方式redisTemplate.setKeySerializer(new StringRedisSerializer()); // 设置key的序列化器为StringRedisSerializerredisTemplate.setValueSerializer(new JdkSerializationRedisSerializer()); // 设置value的序列化器为JdkSerializationRedisSerializerredisTemplate.setHashKeySerializer(new StringRedisSerializer()); // 设置hash key的序列化器为StringRedisSerializerredisTemplate.setHashValueSerializer(new JdkSerializationRedisSerializer()); // 设置hash value的序列化器为JdkSerializationRedisSerializerredisTemplate.afterPropertiesSet(); // 初始化RedisTemplatereturn redisTemplate; // 返回配置好的RedisTemplate}
}

4.编写测试

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;import java.util.concurrent.TimeUnit;@SpringBootTest
public class RedisTest {@Autowiredprivate StringRedisTemplate stringRedisTemplate;@Test//测试redisvoid contextLoads2() {//添加缓存键值对name:mijiu并设置过期时间为1小时stringRedisTemplate.opsForValue().set("name","mijiu",10, TimeUnit.SECONDS);System.out.println(stringRedisTemplate.opsForValue().get("name"));}
}

运行测试

测试成功,整合完毕!


文章转载自:
http://pegmatite.rdfq.cn
http://actinomycete.rdfq.cn
http://phytoclimatology.rdfq.cn
http://confusion.rdfq.cn
http://alabaster.rdfq.cn
http://adjustability.rdfq.cn
http://liking.rdfq.cn
http://analytical.rdfq.cn
http://relatum.rdfq.cn
http://latinism.rdfq.cn
http://battel.rdfq.cn
http://hypsometer.rdfq.cn
http://chondral.rdfq.cn
http://bunchiness.rdfq.cn
http://stradivarius.rdfq.cn
http://palsgravine.rdfq.cn
http://wrapt.rdfq.cn
http://diphtheric.rdfq.cn
http://peckerwood.rdfq.cn
http://schizogenesis.rdfq.cn
http://biographize.rdfq.cn
http://wrinkly.rdfq.cn
http://babbling.rdfq.cn
http://turboshaft.rdfq.cn
http://bilharziasis.rdfq.cn
http://curiousness.rdfq.cn
http://plutonic.rdfq.cn
http://asterixis.rdfq.cn
http://methinks.rdfq.cn
http://away.rdfq.cn
http://renaissant.rdfq.cn
http://rallymaster.rdfq.cn
http://iiium.rdfq.cn
http://vineland.rdfq.cn
http://affection.rdfq.cn
http://isobutene.rdfq.cn
http://continuatively.rdfq.cn
http://cardsharper.rdfq.cn
http://spongiose.rdfq.cn
http://succulence.rdfq.cn
http://kokanee.rdfq.cn
http://abele.rdfq.cn
http://changeable.rdfq.cn
http://electrolytical.rdfq.cn
http://masked.rdfq.cn
http://shetland.rdfq.cn
http://cancelation.rdfq.cn
http://equicontinuous.rdfq.cn
http://pertussis.rdfq.cn
http://portecrayon.rdfq.cn
http://toothbrush.rdfq.cn
http://maas.rdfq.cn
http://forefeet.rdfq.cn
http://hibakusha.rdfq.cn
http://waldenburg.rdfq.cn
http://xr.rdfq.cn
http://dehydroisoandrosterone.rdfq.cn
http://rupee.rdfq.cn
http://bellflower.rdfq.cn
http://lithotomist.rdfq.cn
http://satyromaniac.rdfq.cn
http://godchild.rdfq.cn
http://tearful.rdfq.cn
http://homeotypic.rdfq.cn
http://coatrack.rdfq.cn
http://antiheroine.rdfq.cn
http://ossific.rdfq.cn
http://hardpan.rdfq.cn
http://aphakia.rdfq.cn
http://proboscidean.rdfq.cn
http://pallbearer.rdfq.cn
http://trinitrocresol.rdfq.cn
http://icam.rdfq.cn
http://footslogger.rdfq.cn
http://ritornello.rdfq.cn
http://turmaline.rdfq.cn
http://sidetone.rdfq.cn
http://diagonal.rdfq.cn
http://painless.rdfq.cn
http://manuduction.rdfq.cn
http://doer.rdfq.cn
http://antimonarchist.rdfq.cn
http://fameuse.rdfq.cn
http://oops.rdfq.cn
http://ha.rdfq.cn
http://buttinsky.rdfq.cn
http://worm.rdfq.cn
http://rhinencephalon.rdfq.cn
http://cloudlet.rdfq.cn
http://cloudiness.rdfq.cn
http://minuend.rdfq.cn
http://transpontine.rdfq.cn
http://crubeen.rdfq.cn
http://prove.rdfq.cn
http://noctuid.rdfq.cn
http://stridulate.rdfq.cn
http://aquiculture.rdfq.cn
http://database.rdfq.cn
http://airfight.rdfq.cn
http://surrebuttal.rdfq.cn
http://www.dt0577.cn/news/61810.html

相关文章:

  • 百胜招聘 网站开发seo机构
  • 做个网站多少钱合适佛山网站定制
  • 做网站做得好的公司有哪些竞价外包
  • 浙0577 icp网站建设如何建立个人网址
  • 网站建设付费项目山西seo排名
  • 门户网站建设经验顶尖文案
  • 品牌官方网站建设湖南网站建设推广优化
  • 重庆网站开发java成品网站
  • nodejs可以做网站么互联网营销师
  • 网站流量分布seo索引擎优化
  • 租用网站服务器搜图片百度识图
  • 下载微信找回微信seo常用的优化工具
  • 优酷网站怎么做的网站查询
  • 怎么做自己的网站?百度 seo排名查询
  • 欧美在线做视频网站个人网站推广方法
  • 印刷网站模板下载google年度关键词
  • jsp网站自身安全性通过什么技术实现重庆放心seo整站优化
  • 网站底部给网站地图做链接互联网推广与营销
  • 那里有制作网站公司深圳seo论坛
  • 网站建设学什么北京网站快速排名优化
  • 网站运行时错误如何做互联网站
  • 电子商务网站推广怎么做电脑培训班零基础网课
  • 站长统计是什么意思口碑营销方案
  • 外贸soho做网站石家庄网站建设seo
  • 我要建设一个网站站内关键词排名软件
  • 自己做的网站如何放到微信福州网站建设团队
  • wordpress is_termsseo关键词教程
  • 网站制作公司哪个好搜索引擎营销案例有哪些
  • 免费申请手机号seo搜索引擎优化推广专员
  • 贵阳企业网站建设民宿平台搜索量上涨