redis namespace

工作中发现redis 中存储的数据过多,看起来很不方便,无意中看到了session在redis中存的方式:
在这里插入图片描述
索性就想将自己的存入redis中的数据像这样展示,一来方便查找,二来也比较美观,查询了资料原来是redis key命名的方式导致的。如果你的key命名为XX:XX:XX
在这里插入图片描述
你就会得到这样一个key
在这里插入图片描述
,当然关于redis namesapce的命名方式还有很多,先放上两个链接以后整理
https://blog.csdn.net/songhuiqiao/article/details/50263017
https://blog.csdn.net/m0_38132420/article/details/71699677

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Session Data Redis中设置命名空间namespace),可以使用以下步骤: 1. 配置RedisConnectionFactory 在Spring Boot中,可以使用application.properties或application.yml文件配置RedisConnectionFactory,示例如下: ``` spring.redis.host=your-redis-host spring.redis.port=your-redis-port spring.redis.password=your-redis-password spring.redis.database=your-redis-database spring.redis.namespace=your-namespace ``` 可以通过设置spring.redis.namespace属性来指定命名空间。 如果没有使用Spring Boot,则需要在Java配置类中配置RedisConnectionFactory。 2. 配置RedisOperationsSessionRepository 在Spring Session中,使用RedisOperationsSessionRepository管理Session。可以在Java配置类中配置RedisOperationsSessionRepository,示例如下: ``` @Configuration @EnableRedisHttpSession public class HttpSessionConfig { @Autowired private RedisConnectionFactory redisConnectionFactory; @Value("${spring.redis.namespace}") private String namespace; @Bean public RedisOperationsSessionRepository sessionRepository() { RedisOperationsSessionRepository sessionRepository = new RedisOperationsSessionRepository(redisTemplate()); sessionRepository.setRedisKeyNamespace(namespace); return sessionRepository; } @Bean public RedisTemplate<String, Object> redisTemplate() { RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>(); redisTemplate.setConnectionFactory(redisConnectionFactory); return redisTemplate; } } ``` 在RedisOperationsSessionRepository中,通过调用setRedisKeyNamespace()方法设置命名空间。 在这个示例中,命名空间从application.properties或application.yml文件中获取。 通过这些步骤,就可以在Spring Session Data Redis中设置命名空间

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值