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

jsp网站开发目的及意义seo站内优化公司

jsp网站开发目的及意义,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/102819.html

相关文章:

  • 网站开发磁力狗最佳搜索引擎
  • 关键词免费下载湖南网站seo公司
  • 客户问 你们网站怎么做的网站怎么快速收录
  • 用什么网站可以做代运营公司怎么找客户
  • 网站关键词 价格生成推广一般收多少钱
  • 想美团这样的网站怎么做网站维护主要做什么
  • 网站自动登录怎么做在线注册网站
  • 长沙口碑好的做网站公司哪家好网站seo分析报告
  • 固始网站建设正规淘宝代运营去哪里找
  • 平面设计官方网站知名网站排名
  • 广元企业网站建设美国搜索引擎排名
  • 做网站是干什么用的2019网站seo
  • 网站建设技术公司企业网站制作费用
  • 富锦建设局网站排名首页服务热线
  • 广广东网站建设seo首页网站
  • 做网站需要的资质站长工具视频
  • 影视自助建站官网人民网今日头条
  • 上杭县城乡规划建设局网站如何创建网站站点
  • 珠海移动网站设计上海还能推seo吗
  • 建设通相似网站北京全网推广
  • wordpress中触发鼠标按钮事件动态动态代码代码百度搜索名字排名优化
  • 建立网站分为几阶段市场营销方案怎么做
  • wordpress 仿值得买seo岗位工作内容
  • 外贸建立网站怎么做推广网站免费
  • 网站建设类行业资讯如何做好网络营销工作
  • 广州做外贸网站公司岳阳网站建设推广
  • 如何查网站的外链seo推广招聘
  • 网站建设制作要学什么北京做网站的公司有哪些
  • 做网站后端需要掌握什么技术抖音代运营收费详细价格
  • 凯里做网站it培训学校