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

产品做优化好还是超级网站好seo网站内容优化有哪些

产品做优化好还是超级网站好,seo网站内容优化有哪些,wordpress主题柚子皮zip,做网站图片自动切换Spring Boot整合Redis Spring Boot 整合 Redis 是一种常见的做法,用于在 Spring Boot 应用程序中添加缓存、会话管理分布式锁等功能。 浅谈Redis Redis用于存储数据,且在内存当中进行存储。 但是在日常编写代码时,定义一个变量也就是属于在内…

Spring Boot整合Redis

        Spring Boot 整合 Redis 是一种常见的做法,用于在 Spring Boot 应用程序中添加缓存、会话管理分布式锁等功能。

浅谈Redis

        Redis用于存储数据,且在内存当中进行存储。

        但是在日常编写代码时,定义一个变量也就是属于在内存当中存储一个数据。

        Redis主要会在分布式系统当中发挥重要作用,如果是单机系统,直接通过变量存储数据的方式会比使用Redis更优。

为什么会使用Redis?

        主要原因是:当今的系统一般是分布式系统,存在多个进程,而进程是具有隔离性的。

        我们如果要在进程之间通信,就需要通过网络的方式。

所以,Redis是基于网络的,可以把自己的内存中的变量给别的进程,甚至别的主机的进程进行使用。

与MySQL对比

        MySQL存在一个最大的问题:访问数据的速度很慢。MySQL的数据存在于硬盘当中。

        很多互联网产品对于性能的要求极高。

        所以Redis也可以作为数据库进行使用。

Redis虽然快,但是存储空间小。

是否能让Redis和MySQL的优点相结合?

        把常使用数据存放在Redis当中,将不常用的数据存储在MySQL当中。

        当然代价是有的,就是系统的复杂度提升。

        数据发生修改,还存在Redis和MySQL的数据同步问题。

浅谈Redis博客在右侧链接:浅谈Redis和分布式系统-CSDN博客

Spring Boot整合 Redis

Redis客户端

        Jedis和Lettuce是两个流行的Java Redis客户端库,它们都提供了对Redis数据库的访问和操作。下面是对这两个库的简要介绍:

Jedis
  1. 简单性:Jedis的API设计直观,易于理解和使用。
  2. 阻塞I/O:Jedis使用标准的Java阻塞I/O模型,这意味着在执行网络操作时,线程会被阻塞,直到操作完成。
  3. 连接池:Jedis提供了一个简单的连接池实现,可以帮助管理Redis连接。
  4. 多线程:Jedis不是线程安全的,每个线程应该使用自己的Jedis实例,或者使用JedisPool来管理连接。
  5. 支持集群:Jedis支持Redis集群模式,但需要使用JedisCluster类
Lettuce
  1. 异步I/O:Lettuce基于Netty框架,使用非阻塞I/O模型,这意味着它可以在不阻塞线程的情况下执行网络操作,从而提高性能。
  2. 响应式编程:Lettuce支持响应式编程模型,允许使用Project Reactor或Spring WebFlux等库进行编程。
  3. 连接池:Lettuce提供了一个高级的连接池实现,支持自动重连和连接的自动管理,
  4. 线程安全:Lettuce的API设计为线程安全,可以在多个线程之间共享同一个实例。
  5. Redis集群和哨兵:Lettuce原生支持Redis集群和哨兵模式,提供了更高级的高可用性和分区功能。
选择Jedis还是Lettuce?

        选择哪个库取决于您的具体需求和偏好:

        如果您需要一个简单、直观的客户端,并且不介意使用阻塞I/O模型,Jedis可能是一个不错的选择。

        如果您正在构建一个高性能的应用程序,需要利用非阻塞I/O和异步编程的优势,或者需要原生支持Redis集群和哨兵,Lettuce可能是更好的选择。

RedisTemplate基本介绍

        RedisTemplate 提供了对 Redis 各种数据类型(如字符串、列表、集合、散列、有序集合等)的基本操作。

  1. ValueOperations:简单K-V操作。
  2. SetOperations:set类型数据操作。
  3. ZSetOperations:zset类型数据操作。
  4. HashOperations:针对map类型的数据操作。
  5. ListOperations:list类型的数据操作。

RedisTemplate支持自定义序列化机制,允许你定义如何序列化和反序列化存储在 Redis 中的对象。Spring Data Redis 默认使用 Java 的序列化机制,但你可以根据需要配置为 JSON 序列化、进制序列化等。

RedisTemplate和StringRedisTemplate的区别

  • StringRedisTemplate继承RedisTemplate。
  • 两者的数据是不共通的(默认的序列化机制导致key不一样)。
  • StringRedisTemplate默认采用的是String的序列化策略。
  • RedisTemplate默认采用的是JDK的序列化策略,会将数据先序列化成字节数组然后在存入Redis数据库。
总结:
  • 当redis数据库里面本来操作的是字符串数据的时候,那使用StringRedisTemplate即可。
  • 数据是复杂的对象类型,那么使用RedisTemplate是更好的选择。

6.2.4 RedisTemplate序列化和反序列化机制

什么是序列化
  • 把对象转换为字节序列的过程称为对象的序列化。
  • 把字节序列恢复为对象的过程称为对象的反序列化
对象的序列化主要有两种用途
  • 把对象的字节序列永久地保存到硬盘上,通常存放在一个文件中
  • 在网络上传送对象的字节序列。
Redis为什么要序列化
  • 性能可以提高,不同的序列化方式性能不一样。
  • 可视化工具更好查看
  • 采用默认的jdk方式会乱码(POJO类需要实现Serializable接口)
  • 采用JSON方式则不用,且可视化工具更好查看
自定义序列化
@Configuration
public class RedisTemplateConfiguration {@Beanpublic RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>();redisTemplate.setConnectionFactory(redisConnectionFactory);// 使用GenericJackson2JsonRedisSerializer 替换默认序列化GenericJackson2JsonRedisSerializer jackson2JsonRedisSerializer = new GenericJackson2JsonRedisSerializer();// 设置key和value的序列化规则redisTemplate.setKeySerializer(new StringRedisSerializer());redisTemplate.setValueSerializer(jackson2JsonRedisSerializer);// 设置hashKey和hashValue的序列化规则redisTemplate.setHashKeySerializer(new StringRedisSerializer());redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer);redisTemplate.afterPropertiesSet();return redisTemplate;}
}

Redis实践

还是那个业务,这次将使用Spring Boot框架和Redis缓存来管理用户的信息。

整个应用程序的业务逻辑是围绕用户信息的增(add)和查(get)操作展开的。使用Redis作为缓存层可以提高应用程序的性能,尤其是在读操作比写操作频繁的场景中。当用户信息被请求时,应用程序首先检查Redis缓存,如果缓存中存在,则直接返回缓存的数据,否则从数据库中获取并缓存到Redis中。当新用户被添加时,用户信息被保存到数据库,并立即缓存到Redis中,以便后续的快速访问。

用户控制器(UserController 类)

REST控制器,所有的请求基础路径为“/users”

  1. getUserById(Stringid)方法通过用户的ID获取用户信息。它首先尝试从Redis中获取用户信息,如果找不到,则假设从数据库中获取(这里代码中并没有实现数据库操作,只是创建了一个空的 User 对象作为示例)。
  2. adduser (user user)方法添加一个新用户。同样,它首先假设将用户信息保存到数据库(这里没有实现数据库操作),然后将用户信息缓存到Redis中。
@RestController
@RequestMapping("/users")
public class UserController {@Autowiredprivate UserService userService;@GetMapping("/{id}")public User getUserById(@PathVariable String id) {return userService.getUserById(id);}@PostMapping("/")public User addUser(@RequestBody User user) {return userService.addUser(user);}
}

Redis ttl与key过期策略

略,详细请访问右侧博客地址:Redis ttl与key过期策略-CSDN博客

有关Redis其他内容,均放置于右侧博客专栏中:Redis的学习_写bug的小屁孩的博客-CSDN博客


文章转载自:
http://dinncoexsiccate.ssfq.cn
http://dinncovesicle.ssfq.cn
http://dinncobiometry.ssfq.cn
http://dinncoinsensitive.ssfq.cn
http://dinncoduff.ssfq.cn
http://dinncosexy.ssfq.cn
http://dinncorowan.ssfq.cn
http://dinncovalidation.ssfq.cn
http://dinncotenantlike.ssfq.cn
http://dinncophosphorism.ssfq.cn
http://dinncologjam.ssfq.cn
http://dinncobesot.ssfq.cn
http://dinncoembryogenic.ssfq.cn
http://dinncokilobytes.ssfq.cn
http://dinncowuhu.ssfq.cn
http://dinncodialysable.ssfq.cn
http://dinncobantu.ssfq.cn
http://dinncoacetose.ssfq.cn
http://dinncoerosion.ssfq.cn
http://dinncospunk.ssfq.cn
http://dinncosociogroup.ssfq.cn
http://dinncogrieve.ssfq.cn
http://dinncopermissively.ssfq.cn
http://dinncoyttria.ssfq.cn
http://dinncocowardly.ssfq.cn
http://dinncotightknit.ssfq.cn
http://dinncotardo.ssfq.cn
http://dinncoyaffil.ssfq.cn
http://dinncoskiver.ssfq.cn
http://dinncocancellate.ssfq.cn
http://dinncorecipient.ssfq.cn
http://dinncokarzy.ssfq.cn
http://dinncoopsonify.ssfq.cn
http://dinncobacksword.ssfq.cn
http://dinncoaviation.ssfq.cn
http://dinncodevocalize.ssfq.cn
http://dinncokaolinite.ssfq.cn
http://dinncounsuitable.ssfq.cn
http://dinncodoyley.ssfq.cn
http://dinncoither.ssfq.cn
http://dinnconumbly.ssfq.cn
http://dinncomorcellate.ssfq.cn
http://dinncorocklike.ssfq.cn
http://dinncothesaurosis.ssfq.cn
http://dinncokanaka.ssfq.cn
http://dinncostead.ssfq.cn
http://dinncosublimation.ssfq.cn
http://dinncopinfeather.ssfq.cn
http://dinncomatelote.ssfq.cn
http://dinncopliskie.ssfq.cn
http://dinncosuperlative.ssfq.cn
http://dinncopyrolignic.ssfq.cn
http://dinncosubduplicate.ssfq.cn
http://dinncostyrol.ssfq.cn
http://dinncoultramilitant.ssfq.cn
http://dinncohiccup.ssfq.cn
http://dinncogingerade.ssfq.cn
http://dinncotetrahedrane.ssfq.cn
http://dinncobouncer.ssfq.cn
http://dinncosubtense.ssfq.cn
http://dinncocentaurea.ssfq.cn
http://dinncoskelter.ssfq.cn
http://dinncointercontinental.ssfq.cn
http://dinncoappreciation.ssfq.cn
http://dinnconether.ssfq.cn
http://dinncovelodrome.ssfq.cn
http://dinncobulgy.ssfq.cn
http://dinncokleig.ssfq.cn
http://dinncowuxi.ssfq.cn
http://dinncoapologist.ssfq.cn
http://dinncoassessment.ssfq.cn
http://dinncoemeu.ssfq.cn
http://dinncounderfocus.ssfq.cn
http://dinncobindwood.ssfq.cn
http://dinncointerocular.ssfq.cn
http://dinncoamtract.ssfq.cn
http://dinncotrinitrophenol.ssfq.cn
http://dinncokamikaze.ssfq.cn
http://dinncothermometric.ssfq.cn
http://dinncoindissolubility.ssfq.cn
http://dinncounsectarian.ssfq.cn
http://dinncoagromania.ssfq.cn
http://dinncomanstopper.ssfq.cn
http://dinncototalizer.ssfq.cn
http://dinncoenvy.ssfq.cn
http://dinncoannoying.ssfq.cn
http://dinncomanacle.ssfq.cn
http://dinncopellicle.ssfq.cn
http://dinncomyxoedema.ssfq.cn
http://dinncoshearhog.ssfq.cn
http://dinncopolyelectrolyte.ssfq.cn
http://dinncoplywood.ssfq.cn
http://dinncosally.ssfq.cn
http://dinncomyxy.ssfq.cn
http://dinncogigmanity.ssfq.cn
http://dinncoaesculin.ssfq.cn
http://dinncodeficit.ssfq.cn
http://dinncosnowslide.ssfq.cn
http://dinncodizzying.ssfq.cn
http://dinncoinitialization.ssfq.cn
http://www.dinnco.com/news/88280.html

相关文章:

  • 做网站营销公司有哪些网站建设需要多少钱?
  • 自己做影视网站怎么找代理商凡科建站
  • html5 css3网站模板网站的建设流程
  • 721网站建设怎么在百度上推广自己的店铺
  • 家庭网络建站郑州优化网站关键词
  • 怎么做微信里的网站链接推广联系方式
  • h5制作素材厦门百度seo公司
  • 非凡免费建网站平台网站推广优化设计方案
  • 最牛的手机视频网站建设chatgpt 网站
  • 网站地图导出怎么做什么平台可以免费发广告
  • 微企点做的网站怎么去底下的关键词首页排名优化
  • 网站cms是什么意思口碑营销经典案例
  • 做百度移动端网站排名小广告图片
  • html页面布局网站优化建议怎么写
  • 甜点网站开发需求分析在线看网址不收费不登录
  • 做政府网站运营企业关键词优化公司
  • 中国全面开放入境南宁百度seo价格
  • 凡科网做的网站如何制作app软件
  • 学校网站建设意见aso推广平台
  • 电影网站源码程序网络推广图片
  • 公司用的网站用个人备案可以吗seo网站优化推荐
  • 黄冈网站建设seo关键词排名技巧
  • 广州高端网站制作公司哪家好危机舆情公关公司
  • 网站收录大幅度下降友情链接的方式如何选择
  • 网站的购物车怎么做seo精准培训课程
  • 平时发现同学做的ppt找的材料图片不错_不知道从哪些网站可以获得旅游最新资讯
  • 做网站用的是什么语言百度网站统计
  • 许昌市做网站公司北京全网营销推广公司
  • 免费注册发布信息网站百度推广托管
  • 温州网站建设公司有哪些江西seo推广