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 be java.lang.String, the Redis modules provides two extensions to RedisConnection
 and RedisTemplate, respectively the StringRedisConnection (and its DefaultStringRedisConnection implementation) and StringRedisTemplate as a convenient one-stop
solution for intensive String operations. In addition to being bound to String keys, the template and the connection use the StringRedisSerializerunderneath
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

最新文章

  1. zookeeper源码分析之一服务端启动过程
  2. ubuntn下 nginx+phpstorm 中配置xdebug调试
  3. php require和include区别
  4. Python 读取文件下所有内容、获取文件名、截取字符、写回文件
  5. lua5.3调用C/C++
  6. JavaScript的问题
  7. Hdu3812-Sea Sky(深搜+剪枝)
  8. POJ2125 Destroying The Graph 二分图 + 最小点权覆盖 + 最小割
  9. linux kernel module
  10. js的apply()与call()的区别
  11. JAVA金额按比例分摊,零头处理
  12. Python进行文本处理
  13. 1.[Andriod]之Andriod布局 VS WinPhone布局
  14. 基于开发者中心DevOps流水线快速上云
  15. OGC标准服务 WMS WCS WFS WPS
  16. position:fixed 失效
  17. Django框架----视图(views)
  18. UI5-文档-4.6-Modules
  19. 三个在线django速成教程(转)
  20. Excel对同样项求和

热门文章

  1. oracle 11g ocr 冗余配置
  2. CUDA: 常量内存与事件
  3. drawable animation基础
  4. iOS 9 Safari广告拦截插件
  5. Linux- Linux自带定时调度Crontab使用详解
  6. linux应用之Lamp(apache+mysql+php)的源码安装(centos)
  7. L95
  8. codeforces 705B B. Spider Man(组合游戏)
  9. BZOJ4836: [Lydsy1704月赛]二元运算
  10. 三:JMS消息服务规范