#
Junjie
7 小时以前 b6428016edf3de843020bc95fd1708d3bb1961e5
src/main/java/com/zy/common/utils/RedisUtil.java
@@ -6,6 +6,7 @@
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -23,6 +24,9 @@
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    public RedisUtil(RedisTemplate redisTemplate) {
        this.redisTemplate = redisTemplate;
@@ -90,6 +94,11 @@
    //============================ String =============================
    public Set<String> searchKeys(String key) {
        Set<String> keys = redisTemplate.keys(key + "*");
        return keys;
    }
    /**
     * 普通缓存获取
     *
@@ -98,6 +107,21 @@
     */
    public Object get(String key) {
        return key == null ? null : redisTemplate.opsForValue().get(key);
    }
    /**
     * 获取全部数据
     * @return
     */
    public HashMap<Object, Object> getRedis() {
        Set<String> keys = redisTemplate.keys("*");
        HashMap<Object, Object> map = new HashMap<>();
        for (String key : keys) {
            Object value = redisTemplate.opsForValue().get(key);
            map.put(key, value);
        }
        return map;//返回全部数据集合
    }
    /**
@@ -110,6 +134,17 @@
    public boolean set(String key, Object value) {
        try {
            redisTemplate.opsForValue().set(key, value);
            long start = System.currentTimeMillis();
            while (System.currentTimeMillis() - start < 10000) {//有效期10s
                Object o = redisTemplate.opsForValue().get(key);
                if (o == null) {
                    continue;
                }
                if (o.equals(value)) {
                    break;
                }
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();