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 toRedisConnection
andRedisTemplate
, respectively theStringRedisConnection
(and itsDefaultStringRedisConnection
implementation) andStringRedisTemplate
as a convenient one-stop
solution for intensive String operations. In addition to being bound toString
keys, the template and the connection use theStringRedisSerializer
underneath
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 ...
随机推荐
- 该 Bucket 已存在,或被其他用户占用
- Notepad++ QuickText 插件的 HTML 配置: \Notepad++\plugins\Config\QuickText.ini
# 缩写的注解 abbr=<abbr title=''>$</abbr> # 覆盖默认的文本方向 bdo=<bdo dir='rtl'>$</bdo> ...
- 使用 Nginx 提升网站访问速度(转)
Nginx 简介 Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器. Nginx 是由 Ig ...
- SpringBoot学习笔记(1):配置Mybatis
SpringBoot学习笔记(1):配置Mybatis 反思:如果自己写的笔记自己都看不懂,那就不要拿出来丢人现眼! IDEA插件 Free MyBatis Plugin插件可以让我们的MyBatis ...
- redis的持久化RDB与AOF
redis 持久化 Redis是一种内存型数据库,一旦服务器进程退出,数据库的数据就会丢失,为了解决这个问题,Redis提供了两种持久化的方案,将内存中的数据保存到磁盘中,避免数据的丢失. RDB ...
- LightOJ - 1079 Just another Robbery —— 概率、背包
题目链接:https://vjudge.net/problem/LightOJ-1079 1079 - Just another Robbery PDF (English) Statistics ...
- 大数据 - Zookeeper
Zookeeper 1. Zookeeper概念简介: Zookeeper是一个分布式协调服务:就是为用户的分布式应用程序提供协调服务 A.zookeeper是为别的分布式程序服务的 B.Zooke ...
- python读取文件后切片
from itertools import islice with open(“1.txt") as f: for a in islice(f,0,2): print(a)
- 转载h5问题总结
判断微信浏览器 function isWeixin(){ var ua = navigator.userAgent.toLowerCase(); if(ua.match(/MicroMessenger ...
- LoadRunner监控图表与配置(三)对系统与网络资源进行监控
1.Windows可监控的性能计数器 2.UNIX可监控的性能计数器 3.性能计数器信息说明 Windows 性能对象 计数器 数值说明 System %Total Processor Time 系统 ...