chenjiahe
2022-03-31 a84b57832d20053cd5bc5a41f5284f7108d9a722
src/main/java/com/hx/redis/RedisUtil.java
@@ -4,7 +4,7 @@
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@@ -127,5 +127,84 @@
    }
}
    /**
     * hash 删除操作
     *
     * @param key   键
     * @param valueKey 值
     * @return true成功 false 失败
     */
    public boolean hashDel(String key, Object... valueKey) {
        try {
            redisTemplate.opsForHash().delete(key,valueKey);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    /**
     * hash 设置hashMapt操作
     *
     * @param key   键
     * @return true成功 false 失败
     */
    public boolean hashSetMap(String key, Map<String,Object> map) {
        try {
            redisTemplate.opsForHash().putAll(key, map);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    /**
     * hash 设置单个hashMap操作
     *
     * @param key   键
     * @return true成功 false 失败
     */
    public boolean hashSet(String hashKey, String key, Object value) {
        try {
            redisTemplate.opsForHash().put(hashKey,key,value);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    /**
     * hash 获取整个hashKey数据
     *
     * @param hashKey   键
     * @return true成功 false 失败
     */
    public Map<Object, Object> hashGetAll(String hashKey) {
        try {
            return redisTemplate.opsForHash().entries(hashKey);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    /**
     * hash 获取单个hashKey
     *
     * @param hashKey   键
     * @return true成功 false 失败
     */
    public Object hashGet(String hashKey,String key) {
        try {
            return redisTemplate.opsForHash().get(hashKey,key);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}