redisTemplate.opsForHash()【redis hash类型缓存类型使用配置】

redisTemplate.opsForHash()【redis hash类型缓存类型使用配置】,第1张

redisTemplate.opsForHash()【redis hash类型缓存类型使用配置】

1.hashSet(String key, Object hashKey, Object value)

   
    public boolean hashSet(String key, Object hashKey, Object value) {
        try {
            redisTemplate.opsForHash().put(key, hashKey, value);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

2. hashSetIfAbsent(String key, Object hashKey, Object value)

	 
    public boolean hashSetIfAbsent(String key, Object hashKey, Object value) {
        return redisTemplate.opsForHash().putIfAbsent(key, hashKey, value);
    }

3.hashGet(String key, Object hashKey)

    
    public Object hashGet(String key, Object hashKey) {
        return key == null ? null : redisTemplate.opsForHash().get(key, hashKey);
    }

4. hashKeys(String key)

 	
    public Set hashKeys(String key) {
        return redisTemplate.opsForHash().keys(key);
    }

5. hashGetAll(String key)

	 
    public Map hashGetAll(String key) {
        return redisTemplate.opsForHash().entries(key);
    }

6.hashExists(String key, String hashKey)

 	 
    public boolean hashExists(String key, String hashKey) {
        return redisTemplate.opsForHash().hasKey(key, hashKey);
    }

7.hashDelete(String key, Object… hashKey)

 	
    public Long hashDelete(String key, Object... hashKey) {
        return redisTemplate.opsForHash().delete(key, hashKey);
    }

8.hashIncr(String key, Object hashKey, long delta)

    public long hashIncr(String key, Object hashKey, long delta) {
        if (delta < 0) {
            throw new RuntimeException("递增因子必须大于0");
        }
        return redisTemplate.opsForHash().increment(key, hashKey, delta);
    }

9.hashDecr(String key, Object hashKey, long delta)

   
    public long hashDecr(String key, Object hashKey, long delta) {
        if (delta < 0) {
            throw new RuntimeException("递减因子必须大于0");
        }
        return redisTemplate.opsForHash().increment(key, hashKey, -delta);
    }

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5637191.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存