spring boot 官方文档翻译之 集成redis
来源:互联网 发布:ubuntu arm版 编辑:程序博客网 时间:2024/06/04 22:35
application.properties 按照自己的环境来
# REDIS (RedisProperties)spring.redis.database= # database namespring.redis.host=localhost # server hostspring.redis.password= # server passwordspring.redis.port=6379 # connection portspring.redis.pool.max-idle=8 # pool settings ...spring.redis.pool.min-idle=0spring.redis.pool.max-active=8spring.redis.pool.max-wait=-1spring.redis.sentinel.master= # name of Redis serverspring.redis.sentinel.nodes= # comma-separated list of host:port pairs
项目结构图
pom.xml依赖
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.haoran</groupId><artifactId>demo</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>demo</name><description>Demo project for Spring Boot</description><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.3.RELEASE</version></parent><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>RedisUtil.java
package com.haoran.boot;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.data.redis.core.RedisTemplate;import org.springframework.data.redis.core.ValueOperations;import org.springframework.stereotype.Component;@Componentpublic class RedisUtil {@Autowiredprivate RedisTemplate<String, String> redisTemplate;public void redisTemplateSet(String key, String value){ValueOperations<String, String> ops =redisTemplate.opsForValue();ops.set(key, value);System.out.println("redisTemplate set is ok");}public String redisTemplateGet(String key){ValueOperations<String, String> ops =redisTemplate.opsForValue();return ops.get(key);}}
RedisController
package com.haoran.boot.controller;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;import com.haoran.boot.RedisUtil;@RestController@RequestMapping(value="/redis")public class RedisController {@Autowiredprivate RedisUtil redisUtil;@RequestMapping(value="/set/{key}/{value}")public String set(@PathVariable String key, @PathVariable String value){//redisComponet.set(key, value);redisUtil.redisTemplateSet(key, value);return "set key succ!";}@RequestMapping(value="/get/{key}")public String get(@PathVariable String key){//return redisComponet.get(key);return redisUtil.redisTemplateGet(key);}}
运行效果截图
阅读全文
0 0
- spring boot 官方文档翻译之 集成redis
- spring boot 官方文档翻译之 集成 dubbo zookeeper
- spring boot 官方文档翻译之 Profiles
- spring boot 官方文档翻译之 Hello World
- spring boot 官方文档翻译之 配置log4j
- spring boot 官方文档翻译之整合 mybatis
- spring boot 官方文档翻译之 配置类详解
- Spring Boot官方翻译
- spring-boot官方文档翻译——第三部分
- Spring官方文档翻译
- Spring Boot Redis 集成
- Spring Boot集成Redis
- spring-boot 集成 redis
- spring boot 集成redis
- Spring boot集成Redis
- Spring Boot 集成Redis
- spring boot集成redis
- 【小QのSpringBoot-翻译】Spring Boot官方参考指南-第一部分 Spring Boot文档
- Python数据分析与挖掘实战(开发流程及常用库安装)
- linux sed 批量替换字符串
- CentOS 7下安装Python3.5
- 什么是工程师文化?
- UNIX ftp命令
- spring boot 官方文档翻译之 集成redis
- 怎么解决浏览器的兼容
- elasticsearch5.3.0安装sql插件
- Android Studio各类常见错误解决方案
- SVN 合并分支实用资源
- LoadRunner:Tran Response time没有显示数据
- MongoDB之数据建模
- mac 安装php
- 关于滚动条滚动到指定位置触发jq事件和html锚点