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

网站开发计入管理费用哪个明细宁波专业seo外包

网站开发计入管理费用哪个明细,宁波专业seo外包,余志国外贸网站建设,男女直接做的视频网站目录 一、添加依赖二、配置 Redis 连接池&#xff08;一&#xff09;通过 Java 配置类&#xff08;二&#xff09;通过 application.properties 文件 三、测试 Redis 操作四、总结 一、添加依赖 在 pom.xml 文件中添加以下依赖&#xff1a; <dependencies><dependen…

目录

    • 一、添加依赖
    • 二、配置 Redis 连接池
      • (一)通过 Java 配置类
      • (二)通过 `application.properties` 文件
    • 三、测试 Redis 操作
    • 四、总结

一、添加依赖

pom.xml 文件中添加以下依赖:

<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency><dependency><groupId>org.apache.commons</groupId><artifactId>commons-pool2</artifactId></dependency>
</dependencies>

二、配置 Redis 连接池

(一)通过 Java 配置类

创建一个配置类,用于定义 Redis 连接工厂和连接池配置:

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;@EnableCaching
@Configuration
public class RedisConfig extends CachingConfigurerSupport {@Beanpublic LettuceConnectionFactory redisConnectionFactory() {RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();redisStandaloneConfiguration.setHostName("localhost");redisStandaloneConfiguration.setPort(6379);GenericObjectPoolConfig<Object> poolConfig = new GenericObjectPoolConfig<>();poolConfig.setMaxTotal(10); // 最大连接数poolConfig.setMaxIdle(5); // 最大空闲连接数poolConfig.setMinIdle(1); // 最小空闲连接数poolConfig.setMaxWaitMillis(2000); // 获取连接的最大等待时间LettucePoolingClientConfiguration poolingClientConfig = LettucePoolingClientConfiguration.builder().poolConfig(poolConfig).build();return new LettuceConnectionFactory(redisStandaloneConfiguration, poolingClientConfig);}@Beanpublic RedisTemplate<String, Object> redisTemplate() {RedisTemplate<String, Object> template = new RedisTemplate<>();template.setConnectionFactory(redisConnectionFactory());template.setKeySerializer(new StringRedisSerializer());template.setValueSerializer(new StringRedisSerializer());return template;}
}

(二)通过 application.properties 文件

application.properties 文件中添加以下配置:

spring.redis.host=localhost
spring.redis.port=6379
spring.redis.database=0
spring.redis.lettuce.pool.max-active=10
spring.redis.lettuce.pool.max-idle=5
spring.redis.lettuce.pool.min-idle=1
spring.redis.lettuce.pool.max-wait=-1

三、测试 Redis 操作

创建一个简单的控制器来测试 Redis 的基本操作:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;@RestController
public class RedisController {@Autowiredprivate RedisTemplate<String, Object> redisTemplate;@GetMapping("/set")public String set(@RequestParam String key, @RequestParam String value) {redisTemplate.opsForValue().set(key, value);return "Value set successfully";}@GetMapping("/get")public String get(@RequestParam String key) {return (String) redisTemplate.opsForValue().get(key);}@GetMapping("/delete")public String delete(@RequestParam String key) {redisTemplate.delete(key);return "Value deleted successfully";}
}

四、总结

通过以上步骤,您已经成功配置了 Spring Boot 中的 Redis 连接池。这种配置方式不仅提高了 Redis 操作的性能,还确保了资源的高效利用。希望本文的示例和讲解对您有所帮助,如果您在配置 Redis 连接池时有任何疑问,欢迎随时交流探讨!

http://www.dtcms.com/wzjs/376214.html

相关文章:

  • 香港网站建设百度搜索结果
  • 统计网站建设沈阳seo团队
  • 网站开发与网页制作推广网络广告
  • 石家庄网站设计网站维护天眼查企业查询
  • 西双版纳傣族自治州政府官网长沙搜索排名优化公司
  • 洋桥网站建设山东工艺美术学院网站建设公司
  • 做易经类的网站百度网盘电脑网页版
  • 深圳品牌设计公司招聘济南网站seo公司
  • 网站标题title怎么写杭州网站优化流程
  • h5动画网站百度网络营销
  • 二手商品交易网站开发图片识别
  • 网站建设需要哪些人营业推广的方式有哪些
  • 小辰青岛网站建设seo推广网络
  • 普通电脑怎么做网站服务器推推蛙品牌策划
  • 建站技术知识个人开发app可以上架吗
  • 营商环境网站建设网络营销策划书范文
  • wordpress阿里巴巴图标安卓优化软件
  • 高端网站定制的案例搜索推广广告
  • 网站建设济宁靠谱的影视后期培训班
  • 网站建设应当注意网络营销的招聘信息
  • 网站国内空间价格软文发布
  • 郑州市网站制作公司关键词挖掘网站
  • 网站建站流程登封网络推广公司
  • wordpress网站全过程自媒体培训
  • 建设数据库搜索网站营销最好的方法
  • 公司两个网站如何都备案淘宝运营培训班学费大概多少
  • 西宁专业网站制作公司网络公关公司
  • 一个公司的网址数字营销服务商seo
  • wordpress邀请码用户分级谷歌seo快速排名优化方法
  • 网站做支付网站内容检测