zoukankan      html  css  js  c++  java
  • SpringDataRedis常用方法

    // 向redis里存入数据和设置缓存时间
    stringRedisTemplate.opsForValue().set("test", "100", 60 * 10, TimeUnit.SECONDS);
    
    // 根据key获取缓存中的val
    stringRedisTemplate.opsForValue().get("test");
    
    // val做-1操作
    stringRedisTemplate.boundValueOps("test").increment(-1);
    
    // val +1
    stringRedisTemplate.boundValueOps("test").increment(1);
    
    // 根据key获取过期时间
    stringRedisTemplate.getExpire("test");
    
    // 根据key获取过期时间并换算成指定单位
    stringRedisTemplate.getExpire("test", TimeUnit.SECONDS);
    
    // 根据key删除缓存
    stringRedisTemplate.delete("test");
    
    // 检查key是否存在,返回boolean值
    stringRedisTemplate.hasKey("546545");
    
    // 设置过期时间
    stringRedisTemplate.expire("red_123", 1000, TimeUnit.MILLISECONDS);
    
    // 向指定key中存放set集合
    stringRedisTemplate.opsForSet().add("red_123", "1", "2", "3");
    
    // 根据key查看集合中是否存在指定数据
    stringRedisTemplate.opsForSet().isMember("red_123", "1");
    
    // 根据key获取set集合
    stringRedisTemplate.opsForSet().members("red_123");
    
  • 相关阅读:
    linux
    算法
    算法
    数据结构 与 算法
    mysql
    mysql
    mysql
    mysql
    【解决】Could not get JDBC Connection、java.lang.InterruptedException问题和排查过程
    git: unable to checkout working tree error: unable to create file Filename too long on windows
  • 原文地址:https://www.cnblogs.com/tian-ci/p/10543063.html
Copyright © 2011-2022 走看看