org.springframework.data.redis.core.RedisTemplate.opsForValue()

Here are the examples of the java api org.springframework.data.redis.core.RedisTemplate.opsForValue() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

940 Examples 7

19 Source : RedisUtil.java
with GNU Affero General Public License v3.0
from zycSummer

/**
 * 递增 此时value值必须为int类型 否则报错
 * @param key 键
 * @param delta 要增加几(大于0)
 * @return
 */
public static long incr(String key, long delta) {
    if (delta < 0) {
        throw new RuntimeException("递增因子必须大于0");
    }
    return redisTemplate.opsForValue().increment(key, delta);
}

19 Source : RedisUtil.java
with GNU Affero General Public License v3.0
from zycSummer

/**
 * 普通缓存放入
 * @param key 键
 * @param value 值
 * @return true成功 false失败
 */
public static boolean set(String key, Object value) {
    try {
        redisTemplate.opsForValue().set(key, value);
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

19 Source : RedisUtil.java
with GNU Affero General Public License v3.0
from zycSummer

/**
 * 普通缓存放入并设置时间
 * @param key 键
 * @param value 值
 * @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期
 * @return true成功 false 失败
 */
public static boolean set(String key, Object value, long time) {
    try {
        if (time > 0) {
            redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
        } else {
            set(key, value);
        }
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

19 Source : RedisUtil.java
with GNU Affero General Public License v3.0
from zycSummer

/**
 * 递减
 * @param key 键
 * @param delta 要减少几(小于0)
 * @return
 */
public static long decr(String key, long delta) {
    if (delta < 0) {
        throw new RuntimeException("递减因子必须大于0");
    }
    return redisTemplate.opsForValue().increment(key, -delta);
}

19 Source : RedisShiroCache.java
with Apache License 2.0
from ztgreat

@Override
public V put(K k, V v) throws CacheException {
    if (this.EXPTIMES != null) {
        redisTemplate.opsForValue().set(k, v, this.EXPTIMES, TimeUnit.SECONDS);
    } else {
        redisTemplate.opsForValue().set(k, v);
    }
    return v;
}

19 Source : RedisShiroCache.java
with Apache License 2.0
from ztgreat

@Override
public V remove(K k) throws CacheException {
    V v = redisTemplate.opsForValue().get(k);
    redisTemplate.delete(k);
    return v;
}

19 Source : RedisShiroCache.java
with Apache License 2.0
from ztgreat

@Override
public V get(K k) throws CacheException {
    return redisTemplate.opsForValue().get(k);
}

19 Source : RedisShiroCache.java
with Apache License 2.0
from ztgreat

public V put(K k, V v, Long EXPTIMES) throws CacheException {
    redisTemplate.opsForValue().set(k, v, EXPTIMES, TimeUnit.SECONDS);
    return v;
}

19 Source : RedisUtil.java
with GNU General Public License v2.0
from ZoeShaw101

/**
 * 缓存value操作
 * @param k
 * @param v
 * @param time
 * @return
 */
public boolean cacheValue(String k, Serializable v, long time) {
    String key = KEY_PREFIX_VALUE + k;
    try {
        ValueOperations<Serializable, Serializable> valueOps = redisTemplate.opsForValue();
        valueOps.set(key, v);
        if (time > 0)
            redisTemplate.expire(key, time, TimeUnit.SECONDS);
        return true;
    } catch (Throwable t) {
        logger.error("缓存[{}]失败, value[{}]", key, v, t);
    }
    return false;
}

19 Source : RedisClientDetailsService.java
with Apache License 2.0
from zlt2000

/**
 * 缓存client并返回client
 * @param clientId
 * @return
 */
private ClientDetails cacheAndGetClient(String clientId) {
    // 从数据库读取
    ClientDetails clientDetails = null;
    try {
        clientDetails = super.loadClientByClientId(clientId);
        if (clientDetails != null) {
            // 写入redis缓存
            redisTemplate.opsForValue().set(clientRedisKey(clientId), clientDetails);
            log.info("缓存clientId:{},{}", clientId, clientDetails);
        }
    } catch (NoSuchClientException e) {
        log.error("clientId:{},{}", clientId, clientId);
    } catch (InvalidClientException e) {
        log.error("cacheAndGetClient-invalidClient:{}", clientId, e);
    }
    return clientDetails;
}

19 Source : RedisClientDetailsService.java
with Apache License 2.0
from zlt2000

/**
 * 将oauth_client_details全表刷入redis
 */
public void loadAllClientToCache() {
    List<ClientDetails> list = super.listClientDetails();
    if (CollectionUtils.isEmpty(list)) {
        log.error("oauth_client_details表数据为空,请检查");
        return;
    }
    list.parallelStream().forEach(client -> redisTemplate.opsForValue().set(clientRedisKey(client.getClientId()), client));
}

19 Source : RedisServiceImpl.java
with Apache License 2.0
from zifangsky

@Override
public void set(String key, Object value) {
    ValueOperations<String, Object> valueOperation = redisTemplate.opsForValue();
    valueOperation.set(key, value);
}

19 Source : RedisServiceImpl.java
with Apache License 2.0
from zifangsky

@Override
public <K> K get(String key) {
    ValueOperations<String, Object> valueOperation = redisTemplate.opsForValue();
    return (K) valueOperation.get(key);
}

19 Source : RedisFrequencyLimiter.java
with MIT License
from zidoshare

private void createTag(String key, long date, long timeout) {
    template.opsForValue().set(prefix + key, date, timeout);
}

19 Source : BlogArticleServiceImpl.java
with Apache License 2.0
from zhupanlinch

@Override
public Integer getArticleClick(Long articleId) {
    ValueOperations<String, Object> operations = redisTemplate.opsForValue();
    Integer count = (Integer) operations.get("article_click_id_" + articleId);
    if (count == null) {
        BlogArticle blogArticle = selectById(articleId);
        if (blogArticle.getClick() != null) {
            count = blogArticle.getClick();
        } else {
            count = 0;
        }
    }
    return count == null ? 0 : count;
}

19 Source : RedisTemplateTest.java
with Apache License 2.0
from zhuoqianmingyue

@Test
public void get() {
    String value = redisTemplate.opsForValue().get("a");
    log.info("key 为 a 的值是:{}", value);
}

19 Source : RedisTemplateTest.java
with Apache License 2.0
from zhuoqianmingyue

@Test
public void set() {
    redisTemplate.opsForValue().set("a", "1", 30, TimeUnit.MINUTES);
    log.info("设置 key 为 a 的值是:{}", 1);
}

19 Source : RedisAuthorizationCodeServices.java
with Apache License 2.0
from zhuangjinming16

/**
 * 替换JdbcAuthorizationCodeServices的存储策略 将存储code到redis,并设置过期时间,10分钟<br>
 */
@Override
protected void store(String code, OAuth2Authentication authentication) {
    redisTemplate.opsForValue().set(redisKey(code), authentication, 10, TimeUnit.MINUTES);
}

19 Source : RedisUtil.java
with Apache License 2.0
from zhuangjinming16

/**
 * 递减
 *
 * @param key 键
 * @param by  要减少几(小于0)
 * @return
 */
public long decr(String key, long delta) {
    if (delta < 0) {
        throw new RuntimeException("递减因子必须大于0");
    }
    return redisTemplate.opsForValue().increment(key, -delta);
}

19 Source : RedisUtil.java
with Apache License 2.0
from zhuangjinming16

/**
 * 普通缓存放入
 *
 * @param key   键
 * @param value 值
 * @return true成功 false失败
 */
public boolean set(String key, Object value) {
    try {
        redisTemplate.opsForValue().set(key, value);
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

19 Source : RedisUtil.java
with Apache License 2.0
from zhuangjinming16

/**
 * 普通缓存放入并设置时间
 *
 * @param key   键
 * @param value 值
 * @param time  时间(秒) time要大于0 如果time小于等于0 将设置无限期
 * @return true成功 false 失败
 */
public boolean set(String key, Object value, long time) {
    try {
        if (time > 0) {
            redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
        } else {
            set(key, value);
        }
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

19 Source : RedisUtil.java
with Apache License 2.0
from zhuangjinming16

/**
 * 递增
 *
 * @param key 键
 * @param by  要增加几(大于0)
 * @return
 */
public long incr(String key, long delta) {
    if (delta < 0) {
        throw new RuntimeException("递增因子必须大于0");
    }
    return redisTemplate.opsForValue().increment(key, delta);
}

19 Source : RedisController.java
with GNU General Public License v3.0
from zhshuixian

@RequestMapping("/delUser")
public User delUser(@RequestParam(value = "key") String key) {
    User user = redisTemplate.opsForValue().get(key);
    redisTemplate.delete(key);
    return user;
}

19 Source : RedisCacheTemplate.java
with Apache License 2.0
from zhouxx

private void putTtiOrTtlCacheMap(String postfix, Map<String, Duration> cacheMap) {
    redisTemplate.opsForValue().set(TTI_TTL_CONFIG_CACHE_NAME + "::" + postfix, cacheMap);
}

19 Source : RedisShiroSessionDAO.java
with GNU Affero General Public License v3.0
from zhouhuan751312

private void setShiroSession(String key, Session session) {
    redisTemplate.opsForValue().set(key, session);
    // 60分钟过期
    redisTemplate.expire(key, 60, TimeUnit.MINUTES);
}

19 Source : RedisRepository.java
with GNU General Public License v3.0
from zhonghuasheng

/**
 * 通过key获取value
 * @param key
 * @return
 */
public Object get(String key) {
    if (null == key) {
        return null;
    }
    return redisTemplate.opsForValue().get(key);
}

19 Source : SpringBoot2RedisCacheApplicationTests.java
with Apache License 2.0
from zheng-zy

@Test
public void contextLoads() {
    redisTemplate.opsForValue().set("redisTemplateA", "A");
    redisTemplateB.opsForValue().set("redisTemplateB", "B");
}

19 Source : RedisTest.java
with Apache License 2.0
from zhaoguhong

@Test
public void testRedisTemplate() {
    redisTemplate.opsForValue().set("test", "testValue");
    replacedert.replacedertEquals(redisTemplate.opsForValue().get("test"), "testValue");
    redisTemplate.delete("test");
    replacedert.replacedertEquals(redisTemplate.opsForValue().get("test"), null);
}

19 Source : RedisServiceImpl.java
with GNU General Public License v3.0
from zhangyd-c

@Override
public <T> void set(String key, T value) {
    redisTemplate.opsForValue().set(key, value);
}

19 Source : RedisServiceImpl.java
with GNU General Public License v3.0
from zhangyd-c

@Override
public void del(String key) {
    redisTemplate.opsForValue().getOperations().delete(key);
}

19 Source : SysGatewayRouteServiceImpl.java
with Apache License 2.0
from zhangdaiscott

@Override
public void clearRedis() {
    redisTemplate.opsForValue().set(CacheConstant.GATEWAY_ROUTES, null);
}

19 Source : TagServiceImpl.java
with Apache License 2.0
from Zephery

@Override
public String getBiaoqian() throws Exception {
    if (redisTemplate.opsForValue().get("biaoqian") == null) {
        updatetag(1);
    }
    return redisTemplate.opsForValue().get("biaoqian");
}

19 Source : ShiroCache.java
with MIT License
from Zealon159

@Override
public V put(K key, V value) throws CacheException {
    V old = get(key);
    redisTemplate.opsForValue().set(getCacheKey(key), value, globExpire, TimeUnit.MINUTES);
    return old;
}

19 Source : RedisUtil.java
with MIT License
from Zealon159

/**
 * 获取key值
 * @param key
 * @return
 */
public Object get(String key) {
    return redisTemplate.opsForValue().get(key);
}

19 Source : RedisUtil.java
with MIT License
from Zealon159

/**
 * 判断指定key是否存在
 * @param key
 * @return
 */
public boolean existKey(String key) {
    Long num = redisTemplate.opsForValue().size(key);
    return Long.valueOf(0) != null;
}

19 Source : RedisUtil.java
with MIT License
from Zealon159

/**
 * 存储key值
 * @param key
 * @param value
 */
public void set(String key, Object value) {
    redisTemplate.opsForValue().set(key, value);
}

19 Source : RedisUtil.java
with GNU General Public License v3.0
from zcbin

/**
 * 递增
 *
 * @param key   键
 * @param delta 要增加几(大于0)
 * @return
 */
public long incr(String key, long delta) {
    if (delta < 0) {
        throw new RuntimeException("递增因子必须大于0");
    }
    return redisTemplate.opsForValue().increment(key, delta);
}

19 Source : RedisUtil.java
with GNU General Public License v3.0
from zcbin

/**
 * 递减
 *
 * @param key   键
 * @param delta 要减少几(小于0)
 * @return
 */
public long decr(String key, long delta) {
    if (delta < 0) {
        throw new RuntimeException("递减因子必须大于0");
    }
    return redisTemplate.opsForValue().increment(key, -delta);
}

19 Source : RedisUtil.java
with Apache License 2.0
from ZainZhao

public Object getObj(String key) {
    return redisTemplate.opsForValue().get(key);
}

19 Source : RedisUtil.java
with Apache License 2.0
from ZainZhao

public void setObj(String key, Object value) {
    redisTemplate.opsForValue().set(key, value);
}

19 Source : DistributedLock.java
with Apache License 2.0
from yz-java

/**
 * @param key 锁标识
 * @param attempt 重试次数
 * @return
 */
public boolean lock(String key, int attempt) {
    Boolean absent = redisTemplate.opsForValue().setIfAbsent(key, System.currentTimeMillis());
    if (absent) {
        return true;
    }
    if (attempt > 0) {
        attempt--;
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return lock(key, attempt);
    }
    return false;
}

19 Source : TestController.java
with Apache License 2.0
from yx726843014

@RequestMapping(value = "/redisSelectTwo")
public String redisSelectTwo() {
    RedisTemplate template = RedisUtil.getSelect_1();
    ValueOperations ops = template.opsForValue();
    ops.set("test", "1");
    return "success";
}

19 Source : RedisUtil.java
with GNU General Public License v3.0
from ywhs

// -------------------- String ----------------------------
/**
 * 普通缓存放入
 * @param key 键值
 * @param value 值
 * @return true成功 要么异常
 */
public Boolean setString(String key, Object value) {
    try {
        redisTemplate.opsForValue().set(key, value);
        return true;
    } catch (Exception ex) {
        throw MyExceptionUtil.mxe("插入缓存失败!", ex);
    }
}

19 Source : RedisUtil.java
with GNU General Public License v3.0
from ywhs

/**
 *  设置缓存存在时间
 * @param key key值
 * @param value value值
 * @param time 时间 秒为单位
 * @return 成功返回true,失败返回异常信息
 */
public boolean setString(String key, Object value, long time) {
    try {
        redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
        return true;
    } catch (Exception ex) {
        throw MyExceptionUtil.mxe("插入缓存失败!", ex);
    }
}

19 Source : RedisUtils.java
with MIT License
from yuuki80code

/**
 * 递增
 *
 * @param key
 * @param delta
 * @return
 */
public long incr(String key, long delta) {
    if (delta < 0) {
        throw new RuntimeException("递增因子必须大于0");
    }
    return redisTemplate.opsForValue().increment(key, delta);
}

19 Source : RedisUtils.java
with MIT License
from yuuki80code

/**
 * 递减
 *
 * @param key
 * @param delta
 * @return
 */
public long decr(String key, long delta) {
    if (delta < 0) {
        throw new RuntimeException("递减因子必须大于0");
    }
    return redisTemplate.opsForValue().increment(key, -delta);
}

19 Source : RedisUtils.java
with MIT License
from yuuki80code

/**
 * 无过期时间缓存
 *
 * @param key
 * @param value
 * @return
 */
public boolean set(String key, Object value) {
    try {
        redisTemplate.opsForValue().set(key, value);
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

19 Source : RedisUtils.java
with MIT License
from yuuki80code

/**
 * 有过期时间缓存
 *
 * @param key
 * @param value
 * @param time
 * @return
 */
public boolean set(String key, Object value, long time) {
    try {
        redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

19 Source : RedisServiceImpl.java
with GNU General Public License v3.0
from YuJian95

/**
 * 自增操作
 *
 * @param key   键值
 * @param delta 自增步长
 * @return 步长数
 */
@Override
public Long increment(String key, long delta) {
    return redisTemplate.opsForValue().increment(key, delta);
}

19 Source : RedisServiceImpl.java
with GNU General Public License v3.0
from YuJian95

/**
 * 获取数据
 *
 * @param key 键值
 * @return 对应键值数据
 */
@Override
public Object get(String key) {
    if (hasKey(key)) {
        return redisTemplate.opsForValue().get(key);
    }
    return null;
}

See More Examples