spring-boot-starter-data-redis学习笔记01
1.Redis在Unbuntu14开启,
进入安装的src目录:
1.修改redis.conf,因为redis默认是受保护模式。
protected-mode yes (改为no)
bind 127.0.0.1 (注释掉,因为默认只有本机能访问)
requiredpass "password" (新增一行,作为权限验证密码)
接下来开启redis,(这里一定要指定conf文件,默认不会使用你修改的redis.conf文件,导致修改内容无效)
nohup ./redis-server ../redis.conf &
2.用./redis-cli 打开cli
127.0.0.1:6379>auth password
OK
127.0.0.1:6379>ping
PONG
验证通过
2.搭建SpringBoot-Redis环境
1.新建项目,pom.xml文件:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</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>
</dependencies>
2.application.properties配置
核心只需配:
spring.redis.port=6379
spring.redis.host=xxx
spring.redis.password=password 编写controller方法
@Autowired
private StringRedisTemplate stringRedisTemplate; @GetMapping("set")
public void setString() {
stringRedisTemplate.opsForValue().set("lisi", "美女");
} @GetMapping("show")
public String getString() {
return stringRedisTemplate.opsForValue().get("lisi");
}
启动
@SpringBootApplication
public class SpringDataRedis01Application { public static void main(String[] args) {
SpringApplication.run(SpringDataRedis01Application.class, args);
}
}
StringRedisTemplate是继承自RedisTemplate,提供的一种对Key,Value为String类型的一种便利的操作对象
官方文档(Since it’s quite common for the keys and values stored in Redis to bejava.lang.String, the Redis modules provides two extensions toRedisConnectionandRedisTemplate, respectively theStringRedisConnection(and itsDefaultStringRedisConnectionimplementation) andStringRedisTemplateas a convenient one-stop
solution for intensive String operations. In addition to being bound toStringkeys, the template and the connection use theStringRedisSerializerunderneath
which means the stored keys and values are human readable (assuming the same encoding is used both in Redis and your code))
public class StringRedisTemplate extends RedisTemplate<String, String> {
/**
* Constructs a new <code>StringRedisTemplate</code> instance. {@link #setConnectionFactory(RedisConnectionFactory)}
* and {@link #afterPropertiesSet()} still need to be called.
*/
public StringRedisTemplate() {
RedisSerializer<String> stringSerializer = new StringRedisSerializer();
setKeySerializer(stringSerializer);
setValueSerializer(stringSerializer);
setHashKeySerializer(stringSerializer);
setHashValueSerializer(stringSerializer);
}
。。。。。。
}
RedisProperties.java官方文档
# REDIS (RedisProperties)
spring.redis.cluster.max-redirects= # Maximum number of redirects to follow when executing commands across the cluster.
spring.redis.cluster.nodes= # Comma-separated list of "host:port" pairs to bootstrap from.
spring.redis.database=0 # Database index used by the connection factory.
spring.redis.url= # Connection URL. Overrides host, port, and password. User is ignored. Example: redis://user:password@example.com:6379
spring.redis.host=localhost # Redis server host.
spring.redis.jedis.pool.max-active=8 # Maximum number of connections that can be allocated by the pool at a given time. Use a negative value for no limit.
spring.redis.jedis.pool.max-idle=8 # Maximum number of "idle" connections in the pool. Use a negative value to indicate an unlimited number of idle connections.
spring.redis.jedis.pool.max-wait=-1ms # Maximum amount of time a connection allocation should block before throwing an exception when the pool is exhausted. Use a negative value to block indefinitely.
spring.redis.jedis.pool.min-idle=0 # Target for the minimum number of idle connections to maintain in the pool. This setting only has an effect if it is positive.
spring.redis.lettuce.pool.max-active=8 # Maximum number of connections that can be allocated by the pool at a given time. Use a negative value for no limit.
spring.redis.lettuce.pool.max-idle=8 # Maximum number of "idle" connections in the pool. Use a negative value to indicate an unlimited number of idle connections.
spring.redis.lettuce.pool.max-wait=-1ms # Maximum amount of time a connection allocation should block before throwing an exception when the pool is exhausted. Use a negative value to block indefinitely.
spring.redis.lettuce.pool.min-idle=0 # Target for the minimum number of idle connections to maintain in the pool. This setting only has an effect if it is positive.
spring.redis.lettuce.shutdown-timeout=100ms # Shutdown timeout.
spring.redis.password= # Login password of the redis server.
spring.redis.port=6379 # Redis server port.
spring.redis.sentinel.master= # Name of the Redis server.
spring.redis.sentinel.nodes= # Comma-separated list of "host:port" pairs.
spring.redis.ssl=false # Whether to enable SSL support.
spring.redis.timeout= # Connection timeout.
参考:https://docs.spring.io/spring-data/redis/docs/1.8.10.RELEASE/reference/html/#redis:connectors:jedis
spring-boot-starter-data-redis学习笔记01的更多相关文章
- 初次搭建spring boot 项目(实验楼-学习笔记)
首先说一下springboot 的优点: 使用Spring Initializr可以在几秒钟就配置好一个Spring Boot应用. 对大量的框架都可以无缝集成,基本不需要配置或者很少的配置就可以运行 ...
- spring boot 尚桂谷学习笔记10 数据访问02 mybatis
数据访问 mybatis 创建一个 springboot 工程,模块选择 sql 中 mysql(数据驱动), jdbc(自动配置数据源), mybatis Web模块中选择 web pom 引入: ...
- spring boot 尚桂谷学习笔记04 ---Web开始
------web开发------ 1.创建spring boot 应用 选中我们需要的模块 2.spring boot 已经默认将这些场景配置好了 @EnableAutoConfiguration ...
- spring boot 尚桂谷学习笔记11 数据访问03 JPA
整合JPA SpringData 程序数据交互结构图 (springdata jpa 默认使用 hibernate 进行封装) 使用之后就关注于 SpringData 不用再花多经历关注具体各个交互框 ...
- spring boot 尚桂谷学习笔记09 数据访问
springboot 与数据库访问 jdbc, mybatis, spring data jpa, 1.jdbc原生访问 新建项目 使用 springboot 快速构建工具 选中 web 组件 sq ...
- spring boot 尚桂谷学习笔记07 嵌入式容器 ---Web
------配置嵌入式servlet容器------ springboot 默认使用的是嵌入的Servlet(tomcat)容器 问题? 1)如何定制修改Servlet容器的相关配置: 1.修改和se ...
- redis学习笔记-01:redis简介
1.redis是一个高性能的Nosql数据库,遵守BSD协议,使用c语言编写.支持网络.可基于内存亦可持久化,是一种日志型.Key-Value数据库,也可看做是一个分布式的.基于内存的缓存工具. 2. ...
- redis学习笔记01 — 基本介绍、安装配置及常用命令
redis--NoSQL的一种 为了解决高并发.高可用.高扩展.大数据存储等一系列问题而产生的数据库解决方案,就是NoSQL NoSQL,非关系型数据库,全名:Not Only Sql,它不能代替关系 ...
- spring boot 尚桂谷学习笔记08 Docker ---Web
------Docker------ 简介:Docker是一个开元的应用容器引擎,性能非常高 已经安装好的软件打包成一个镜像放到服务器中运行镜像 MySQL容器,Redis容器...... Docke ...
- spring boot 尚桂谷学习笔记05 ---Web
------web 开发登录功能------ 修改login.html文件:注意加粗部分为 msg 字符串不为空时候 才进行显示 <!DOCTYPE html> <!-- saved ...
随机推荐
- mysql系列之6.mysql主从同步
普通文件的数据同步 nfs: 网络文件共享 samba: 共享数据 定时任务或守护进程结合 rsync.scp inotify(sersync)+rsync 触发式实时数据同步 ftp数据同步 ssh ...
- 【题解】P3796【模板】AC自动机(加强版)
[题解]P3796 [模板]AC自动机(加强版) 记录当前\(cnt\)是第几个"星".记录第几个串是对应着第几个星. 这里补充一点对于\(AC\)自动机的理解.可能一直有个问题我 ...
- SVM怎样解决多分类问题
从 SVM的那几张图能够看出来,SVM是一种典型的两类分类器.即它仅仅回答属于正类还是负类的问题.而现实中要解决的问题,往往是多类的问题(少部分例外,比如垃圾邮件过滤,就仅仅须要确定"是&q ...
- MongoDB入门学习(三):MongoDB的增删查改
对于我们这样的菜鸟来说,最重要的不是数据库的管理,也不是数据库的性能,更不是数据库的扩展,而是怎么用好这款数据库,也就是一个数据库提供的最核心的功能,增删查改. 由于M ...
- Java基础教程:多线程基础(2)——线程间的通信
Java基础教程:多线程基础(2)——线程间的通信 使线程间进行通信后,系统之间的交互性会更强大,在大大提高CPU利用率的同时还会使程序员对各线程任务在处理的过程中进行有效的把控与监督. 线程间的通信 ...
- Maximum Subsequence Sum 【DP】
Given a sequence of K integers { N1, N2, -, NK }. A continuous subsequence is defined to be ...
- A Pangram
Codeforces Round #295 div2 的A题,题意是判读一个字符串是不是全字母句,也就是这个字符串是否包含了26个字母,无论大小写. Sample test(s) input 12 t ...
- Machine Learning No.9: Dimensionality reduction
1. Principal component analysis algorithm data preprocessing 2. choosing the number of principal com ...
- 升级GCC 6.2编译LLVM的问题
[ 55%] Built target RTInterception.x86_64 [ 55%] Building ASM object projects/compiler-rt/lib/saniti ...
- 51Nod 1376 最长递增子序列的数量 —— LIS、线段树
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1376 1376 最长递增子序列的数量 基准时间限制:1 秒 空 ...