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

集团网站建设 中企动力做网站怎么导入地图

集团网站建设 中企动力,做网站怎么导入地图,wordpress能做大站吗,上海网警目录 一、添加依赖二、配置 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/799008.html

相关文章:

  • 网站建设在哪能看手机seo百度点击软件
  • 济南自助建站模板点瑞网络网站建设
  • 虚拟空间的网站赚钱吗公司网站建设费用入什么费用
  • 网站建设的展望 视频网页网络优化
  • 老师让做网站怎么做四川省建筑人员证书查询
  • 哪些分类网站医疗行业企业网站建设
  • 怎样发掘网站建设的客户天津市工商网站查询企业信息
  • 网站建设平台官网河间米各庄免费的ppt模板网站有哪些
  • 广州网站备案怎样用jsp做网站登录
  • 做企业网站的凡客系统
  • 朝阳专业网站建设seoul
  • 快速建设网站视频教程公司网站的个人主页怎么做
  • wordpress建站详解acg wordpress模板
  • 徐州网站建设xleccentos 如何建立网站
  • 网站开发语言 知乎购买云服务器之后怎么使用
  • wordpress 架站 电子书最热门的网页游戏排行
  • 品牌网站建设有哪些功能营口网站设计
  • 建设信用卡网站是什么青岛网站优化公司
  • 杭州网站建设方案wordpress菜单产品目录
  • 服务好的南京网站建设企业网站主页设计图片
  • 高中课程免费教学网站申请公司注册需要什么材料
  • 秦皇岛网站seo乌镇网站建设投标书
  • 自己公司网站维护wordpress portal
  • wordpress 架站 电子书php支持大型网站开发吗
  • 怎么做网站首页oa系统多少钱一套
  • 网络营销seo是什么意思整站seoseo优化
  • 安溪建设局网站毕节网站建设推广
  • 学做网站培训 上海有关网站升级建设的申请书
  • 网站建设网广州网站建设工程
  • 网站内页权重查询网络运营推广是做什么的