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

某企业网站建设论文seo搜索

某企业网站建设论文,seo搜索,做明星ps黄图网站,网站展示 包括什么应用场景 存放Token、存放用户信息或字典等需要频繁访问数据库获取但不希望频繁访问增加数据库压力且变化不频繁的数据。 集成步骤 1. 新建 Maven 项目并引入 redis 依赖【部分框架有可能已经集成&#xff0c;会导致依赖文件有差异】 <dependency><groupId>org…

应用场景

存放Token、存放用户信息或字典等需要频繁访问数据库获取但不希望频繁访问增加数据库压力且变化不频繁的数据。

集成步骤

1. 新建 Maven 项目并引入 redis 依赖【部分框架有可能已经集成,会导致依赖文件有差异】

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

2. 配置 application.yml文件

#数据源配置
spring:redis:##redis 单机环境配置# Redis服务器地址host: 127.0.0.1# Redis服务器连接端口port: 6379password:# Redis数据库索引(默认为0)database: 0ssl: falsedatasource:url: jdbc:mysql://*.***.**.**:3516/smart_order?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=trueusername: rootpassword: ******

3. 编写缓存服务和Controller

spring-boot 自动配置了 RedisConnectionFactory, StringRedisTemplate 和 RedisTemplate Bean。
默认,连接的 redis 服务端为 localhost:6379

CacheService 接口

/*** 缓存服务* @param <K>  缓存的 key* @param <V>  缓存的内容*/
public interface CacheService<K,V> {Boolean cache(K key, V value);Boolean remove(K key);V get(K key);}

RedisCacheService

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;/*** 基于 Redis 实现的的缓存服务*/
@Service("redisCacheService")
public class RedisCacheService implements CacheService<String, Object>{//  spring-boot 自动配置了 RedisConnectionFactory, StringRedisTemplate 和 RedisTemplate Bean。@Autowiredprivate RedisConnectionFactory connectionFactory;@Autowiredprivate StringRedisTemplate template;@Autowired@Qualifier("redisTemplate")private RedisTemplate redisTemplate;@Overridepublic Boolean cache(String key, Object value) {template.opsForValue().set(key,String.valueOf(value));return Boolean.TRUE;}@Overridepublic Boolean remove(String key) {return template.delete(key);}@Overridepublic Object get(String key) {return template.opsForValue().get(key);}
}

CacheController

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;/*** CacheController 用于提供 接口进行缓存操作*/
@RestController
@RequestMapping("/cache")
public class CacheController {@Autowired@Qualifier("redisCacheService")private CacheService cacheService;/*** 缓存* @param key* @param value* @return*/@GetMapping("/save")public Boolean cache(@RequestParam("key") String key, @RequestParam("value")String value){return cacheService.cache(key,value);}/*** 查询* @param key 缓存key* @return*/@GetMapping("/get")public Object get(@RequestParam("key") String key){return cacheService.get(key);}/*** 删除缓存* @param key 缓存key* @return*/@GetMapping("/remove")public Boolean remove(@RequestParam("key") String key){return cacheService.remove(key);}
}

4. 下载redis并打开

  • Redis3.0下载地址https://redis.io/download/
  • 解压后,打开其中的redis-server.exe即可。
    在这里插入图片描述

5. 启动项目并测试

在SpirngBoot测试类中,先用@Autowired引入RedisCache。通过调用该对象的方法来操作redis数据库。

@Autowired
private RedisCache redisCache;@Test
void TextRedisXX() {redisCache.setCacheObject("hhh", "123");String str = redisCache.getCacheObject("hhh");System.out.println(str);
}

亦或是容器初始化时获取

StringRedisTemplate redisTemplate = SpringUtil.getBean(StringRedisTemplate.class);

结果如下图:
在这里插入图片描述
除了在IDEA中通过调用 redisCache.getCacheObject(“hhh”);方法来获取之外,还可以打开解压文件中的redis-cli.exe,输入 get hhh 来获 取值。
在这里插入图片描述

http://www.tj-hxxt.cn/news/50112.html

相关文章:

  • mvc5 网站开发之學 pdf宝安网站建设
  • 网站建设是什么语言创建网站
  • 优惠券的网站怎么做seo网站优化优化排名
  • 网站注册信息查询百度快照推广效果怎样
  • 怎么做网站栏目关键词优化外包服务
  • 做普通网站公司吗青岛网站开发公司
  • 学院网站建设的作用热点新闻事件及评论
  • 做电影网站需要空间吗网站在线优化检测
  • 网站建设实验报告总结两千字培训课程设计
  • 微信客户管理系统如何优化推广网站
  • 校园网站建设需求分析南宁seo推广服务
  • 内容营销模式seo搜狗排名点击
  • 做个普通的网站在上海做要多少钱客户关系管理系统
  • 网站开发培训流程seoul是什么意思
  • B2C购物网站的特色东莞网站建设市场
  • 98同城招聘网信息seo的主要工作是什么
  • 江西中国建设银行网站首页网站销售怎么推广
  • 可以免费做网站吗电商平台推广公司
  • 数据来源网站怎么做脚注网络营销的优势
  • 下载好模板该怎么做网站免费观看行情软件网站进入
  • 服装网站建设论文范文b站推广网站2024下载
  • 做淘客app要网站吗徐州百度推广电话
  • 西安网站优化效果软文广告经典案例100字
  • 集约化网站建设管理排名检测
  • java做视频网站的需求微信软文范例大全100
  • 东营网站建设方案短链接
  • 网页设计图片排版代码鸡西seo
  • 商务门户网站怎么做百度信息流开户多少钱
  • 模拟登录wordpress流程优化的七个步骤
  • 哪一个做h5的网站好怎么做链接推广产品