Login
网站首页 > 文章中心 > 其它

docker_安装Redis_以及_springboot整合redis

作者:小编 更新时间:2023-10-06 14:32:02 浏览量:370人看过

docker pull  redis:③2



# 如果不想开启RDB,就是配置成 save ""


#900秒内变更1次才触发bgsave


save 900 1 
save 300 10
save 60 10000


#rdb保存的文件名


dbfilename dump.rdb 

#就是存放我们RDB备份文件的目录
dir /data #yes:如果save过程出错了则停止Redis写操作 #no:没所谓save是否出错 stop-writes-on-bgsave-error yes #开启RDB压缩 rdbcompression yes #进行CRC64算法校验,有10%的性能损耗 rdbchecksum yes

命令说明:

-v $PWD/data:/data :?将主机中当前目录下的data挂载到容器的/data

runoob@runoob:~/redis$ docker exec -it 容器id  redis-cli 

如果有密码docker exec -it 容器id redis-cli -a mypassword
172.1⑦0.1:6379> info
# Server
redis_version:③2.0
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:f449541256e7d446
redis_mode:standalone
os:Linux ④2.0-16-generic x86_64
arch_bits:64
multiplexing_api:epoll


 
    
        org.springframework.boot
        spring-boot-starter-data-redis
    

    
        org.springframework.boot
        spring-boot-starter-test
    



spring:
#redis配置
  redis:
#Redis服务器地址
host: 192.16⑧1.193
#Redis服务器连接端口
port: 6379
#Redis数据库索引(默认为0)
database: 0
jedis:
  pool:
    #连接池最大连接数(使用负值表示没有限制)
    max-active: 50
    #连接池中的最大空闲连接
    max-idle: 20
    #连接池最大阻塞等待时间(使用负值表示没有限制)
    max-wait: 3000
    #连接池中的最小空闲连接
    min-idle: 2
#连接超时时间(毫秒)
timeout: 5000
#Redis密码
password: mypassword

package com.fengshun.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
 * redis操作工具类.
* (基于RedisTemplate) * @author xcbeyond * 2018年7月19日下午2:56:24 */ @Component public class RedisUtils { @Autowired private RedisTemplate redisTemplate; /** * 读取缓存 * * @param key * @return */ public String get(final String key) { return redisTemplate.opsForValue().get(key); } /** * 写入缓存 */ public boolean set(final String key, String value) { boolean result = false; try { redisTemplate.opsForValue().set(key, value); result = true; } catch (Exception e) { e.printStackTrace(); } return result; } /** * 更新缓存 */ public boolean getAndSet(final String key, String value) { boolean result = false; try { redisTemplate.opsForValue().getAndSet(key, value); result = true; } catch (Exception e) { e.printStackTrace(); } return result; } /** * 删除缓存 */ public boolean delete(final String key) { boolean result = false; try { redisTemplate.delete(key); result = true; } catch (Exception e) { e.printStackTrace(); } return result; } }
package com.fengshun.config;

import javax.annotation.Resource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit④SpringJUnit4ClassRunner;
/**
 *
 * @author xcbeyond
 * 2018年7月19日下午3:08:04
 */

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class RedisTest {
@Resource
private RedisUtils redisUtils;

/**
 * 插入缓存数据
 */
@Test
public void set() {
    redisUtils.set("redis_key", "redis_vale");
}

/**
 * 读取缓存数据
 */
@Test
public void get() {
    String value = redisUtils.get("redis_key");
    System.out.println(value);
}

}


https://github.com/Blank-mind/token-authentication-example

以上就是土嘎嘎小编为大家整理的docker_安装Redis_以及_springboot整合redis相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章