Java Code Examples for org.redisson.api.RMap#isExists()

The following examples show how to use org.redisson.api.RMap#isExists() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiCache.java    From mPaaS with Apache License 2.0 5 votes vote down vote up
/** 读(Hash) */
@SuppressWarnings("unchecked")
public <T> Map<String, T> hget(String key) {
    Object map = null;
    /**
     * CACHE:key==NULL 表示key不存在<br>
     * CACHE:key==MAP 表示key存在
     */
    // 从线程中读
    Map<String, Object> cache = getThreadLocal();
    if (cache != null) {
        map = cache.get(key);
        if (map != null) {
            if (map == NULL) {
                // key不存在
                return null;
            }
        }
    }
    // 从redis读并回写线程
    RMap<String, Object> rmap = redisson.getMap(key,
            JsonJacksonCodec.INSTANCE);
    boolean exists = map != null || rmap.isExists();
    if (exists) {
        map = new HashMap<>(rmap);
    }
    if (cache != null) {
        cache.put(key, map == null ? NULL : map);
    }
    return (Map<String, T>) map;
}
 
Example 2
Source File: MultiCache.java    From mPaaS with Apache License 2.0 5 votes vote down vote up
/** key是否存在(Hash) */
public boolean hIsExists(String key) {
    Object map = null;
    /**
     * CACHE:key==NULL 表示key不存在<br>
     * CACHE:key==MAP 表示key存在
     */
    // 从线程中读
    Map<String, Object> cache = getThreadLocal();
    if (cache != null) {
        map = cache.get(key);
        if (map != null) {
            return map != NULL;
        }
    }
    // 从redis读并回写线程
    RMap<String, Object> rmap = redisson.getMap(key,
            JsonJacksonCodec.INSTANCE);
    boolean exists = rmap.isExists();
    if (cache != null) {
        if (exists) {
            cache.put(key, new HashMap<>(16));
        } else {
            cache.put(key, NULL);
        }
    }
    return exists;
}
 
Example 3
Source File: MultiCache.java    From mPaaS with Apache License 2.0 5 votes vote down vote up
/** 写,当key不存在时无效,并返回false */
@SuppressWarnings("unchecked")
public boolean hset(String key, String field, Object value) {
    Object map = null;
    /**
     * CACHE:key==NULL 表示key不存在<br>
     * CACHE:key==MAP 表示key存在
     */
    // 从线程中判断key是否存在
    Map<String, Object> cache = getThreadLocal();
    if (cache != null) {
        map = cache.get(key);
        if (map == NULL) {
            // key不存在,写失败
            return false;
        }
    }
    // 从redis读并回写线程
    RMap<String, Object> rmap = redisson.getMap(key,
            JsonJacksonCodec.INSTANCE);
    boolean exists = map != null || rmap.isExists();
    if (!exists) {
        if (cache != null) {
            cache.put(key, NULL);
        }
        return false;
    }
    // 写入数据
    rmap.put(field, value);
    if (cache != null) {
        if (map == null) {
            map = new HashMap<>(16);
            cache.put(key, map);
        }
        ((Map<String, Object>) map).put(field,
                value == null ? NULL : value);
    }
    return true;
}
 
Example 4
Source File: MultiCache.java    From mPass with Apache License 2.0 5 votes vote down vote up
/** 读(Hash) */
@SuppressWarnings("unchecked")
public <T> Map<String, T> hget(String key) {
    Object map = null;
    /**
     * CACHE:key==NULL 表示key不存在<br>
     * CACHE:key==MAP 表示key存在
     */
    // 从线程中读
    Map<String, Object> cache = getThreadLocal();
    if (cache != null) {
        map = cache.get(key);
        if (map != null) {
            if (map == NULL) {
                // key不存在
                return null;
            }
        }
    }
    // 从redis读并回写线程
    RMap<String, Object> rmap = redisson.getMap(key,
            JsonJacksonCodec.INSTANCE);
    boolean exists = map != null || rmap.isExists();
    if (exists) {
        map = new HashMap<>(rmap);
    }
    if (cache != null) {
        cache.put(key, map == null ? NULL : map);
    }
    return (Map<String, T>) map;
}
 
Example 5
Source File: MultiCache.java    From mPass with Apache License 2.0 5 votes vote down vote up
/** key是否存在(Hash) */
public boolean hIsExists(String key) {
    Object map = null;
    /**
     * CACHE:key==NULL 表示key不存在<br>
     * CACHE:key==MAP 表示key存在
     */
    // 从线程中读
    Map<String, Object> cache = getThreadLocal();
    if (cache != null) {
        map = cache.get(key);
        if (map != null) {
            return map != NULL;
        }
    }
    // 从redis读并回写线程
    RMap<String, Object> rmap = redisson.getMap(key,
            JsonJacksonCodec.INSTANCE);
    boolean exists = rmap.isExists();
    if (cache != null) {
        if (exists) {
            cache.put(key, new HashMap<>(16));
        } else {
            cache.put(key, NULL);
        }
    }
    return exists;
}
 
Example 6
Source File: MultiCache.java    From mPass with Apache License 2.0 5 votes vote down vote up
/** 写,当key不存在时无效,并返回false */
@SuppressWarnings("unchecked")
public boolean hset(String key, String field, Object value) {
    Object map = null;
    /**
     * CACHE:key==NULL 表示key不存在<br>
     * CACHE:key==MAP 表示key存在
     */
    // 从线程中判断key是否存在
    Map<String, Object> cache = getThreadLocal();
    if (cache != null) {
        map = cache.get(key);
        if (map == NULL) {
            // key不存在,写失败
            return false;
        }
    }
    // 从redis读并回写线程
    RMap<String, Object> rmap = redisson.getMap(key,
            JsonJacksonCodec.INSTANCE);
    boolean exists = map != null || rmap.isExists();
    if (!exists) {
        if (cache != null) {
            cache.put(key, NULL);
        }
        return false;
    }
    // 写入数据
    rmap.put(field, value);
    if (cache != null) {
        if (map == null) {
            map = new HashMap<>(16);
            cache.put(key, map);
        }
        ((Map<String, Object>) map).put(field,
                value == null ? NULL : value);
    }
    return true;
}
 
Example 7
Source File: MultiCache.java    From mPaaS with Apache License 2.0 4 votes vote down vote up
/** 读(Hash) */
@SuppressWarnings("unchecked")
public <T> T hget(String key, String field) {
    Object map = null;
    Object value = null;
    /**
     * CACHE:key==NULL 表示key不存在<br>
     * CACHE:key==MAP 表示key存在
     */
    // 从线程中读
    Map<String, Object> cache = getThreadLocal();
    if (cache != null) {
        map = cache.get(key);
        if (map != null) {
            if (map == NULL) {
                // key不存在
                return null;
            }
            value = ((Map<String, Object>) map).get(field);
            if (value != null) {
                return value == NULL ? null : (T) value;
            }
        }
    }
    // 从redis读并回写线程
    RMap<String, Object> rmap = redisson.getMap(key,
            JsonJacksonCodec.INSTANCE);
    boolean exists = map != null || rmap.isExists();
    if (exists) {
        value = rmap.get(field);
    }
    if (cache != null) {
        if (exists) {
            if (map == null) {
                map = new HashMap<>(16);
                cache.put(key, map);
            }
            ((Map<String, Object>) map).put(field,
                    value == null ? NULL : value);
        } else {
            cache.put(key, NULL);
        }
    }
    return (T) value;
}
 
Example 8
Source File: MultiCache.java    From mPass with Apache License 2.0 4 votes vote down vote up
/** 读(Hash) */
@SuppressWarnings("unchecked")
public <T> T hget(String key, String field) {
    Object map = null;
    Object value = null;
    /**
     * CACHE:key==NULL 表示key不存在<br>
     * CACHE:key==MAP 表示key存在
     */
    // 从线程中读
    Map<String, Object> cache = getThreadLocal();
    if (cache != null) {
        map = cache.get(key);
        if (map != null) {
            if (map == NULL) {
                // key不存在
                return null;
            }
            value = ((Map<String, Object>) map).get(field);
            if (value != null) {
                return value == NULL ? null : (T) value;
            }
        }
    }
    // 从redis读并回写线程
    RMap<String, Object> rmap = redisson.getMap(key,
            JsonJacksonCodec.INSTANCE);
    boolean exists = map != null || rmap.isExists();
    if (exists) {
        value = rmap.get(field);
    }
    if (cache != null) {
        if (exists) {
            if (map == null) {
                map = new HashMap<>(16);
                cache.put(key, map);
            }
            ((Map<String, Object>) map).put(field,
                    value == null ? NULL : value);
        } else {
            cache.put(key, NULL);
        }
    }
    return (T) value;
}