Java Code Examples for org.springframework.data.redis.core.SetOperations#add()

The following examples show how to use org.springframework.data.redis.core.SetOperations#add() . 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: RedisCacheUtils.java    From sophia_scaffolding with Apache License 2.0 6 votes vote down vote up
public void setSet(String k, T value, long time) {
    String key = GlobalsConstants.KEY_SET_PREFIX + k;
    logger.debug("setSet key [{}]", key);
    try {
        SetOperations<String, T> valueOps = redisTemplate.opsForSet();
        valueOps.add(key, value);
        if (time > 0) {
            redisTemplate.expire(key, time, TimeUnit.SECONDS);
        }
    } catch (Throwable t) {
        logger.error("setSet key [{}] exception!", key, t);
        throw new CommonException(t);
    }
}
 
Example 2
Source File: CommonRedisDaoImpl.java    From SpringBootUnity with MIT License 6 votes vote down vote up
/**
 * 缓存set操作
 *
 * @param k    key
 * @param v    value
 * @param time time
 * @return boolean
 */
@Override
public boolean cacheSet(String k, String v, long time) {
    String key = KEY_PREFIX_SET + k;
    try {
        SetOperations<String, String> valueOps = redisTemplate.opsForSet();
        valueOps.add(key, v);
        if (time > 0) {
            redisTemplate.expire(key, time, TimeUnit.SECONDS);
        }
        return true;
    } catch (Throwable t) {
        LOGGER.error("缓存[" + key + "]失败, value[" + v + "]", t);
    }
    return false;
}
 
Example 3
Source File: CommonRedisDaoImpl.java    From SpringBootUnity with MIT License 6 votes vote down vote up
/**
 * 缓存set
 *
 * @param k    key
 * @param v    value
 * @param time time
 * @return boolean
 */
@Override
public boolean cacheSet(String k, Set<String> v, long time) {
    String key = KEY_PREFIX_SET + k;
    try {
        SetOperations<String, String> setOps = redisTemplate.opsForSet();
        setOps.add(key, v.toArray(new String[v.size()]));
        if (time > 0) {
            redisTemplate.expire(key, time, TimeUnit.SECONDS);
        }
        return true;
    } catch (Throwable t) {
        LOGGER.error("缓存[" + key + "]失败, value[" + v + "]", t);
    }
    return false;
}
 
Example 4
Source File: RedisCacheUtils.java    From sophia_scaffolding with Apache License 2.0 5 votes vote down vote up
public void setSet(String k, T value, long time) {
    String key = GlobalsConstants.KEY_SET_PREFIX + k;
    logger.debug("setSet key [{}]", key);
    try {
        SetOperations<String, T> valueOps = redisTemplate.opsForSet();
        valueOps.add(key, value);
        if (time > 0) {
            redisTemplate.expire(key, time, TimeUnit.SECONDS);
        }
    } catch (Throwable t) {
        logger.error("setSet key [{}] exception!", key, t);
        throw new CommonException(t);
    }
}
 
Example 5
Source File: RedisCacheUtils.java    From sophia_scaffolding with Apache License 2.0 5 votes vote down vote up
public void setSet(String k, Set<T> v, long time) {
    String key = GlobalsConstants.KEY_SET_PREFIX + k;
    logger.debug("setSet key [{}]", key);
    try {
        SetOperations<String, T> setOps = redisTemplate.opsForSet();
        setOps.add(key, (T[]) v.toArray());
        if (time > 0) {
            redisTemplate.expire(key, time, TimeUnit.SECONDS);
        }
    } catch (Throwable t) {
        logger.error("setSet key [{}] exception!", key, t);
        throw new CommonException(t);
    }
}
 
Example 6
Source File: RedisCacheUtils.java    From sophia_scaffolding with Apache License 2.0 5 votes vote down vote up
public void setSet(String k, T value, long time) {
    String key = GlobalsConstants.KEY_SET_PREFIX + k;
    logger.debug("setSet key [{}]", key);
    try {
        SetOperations<String, T> valueOps = redisTemplate.opsForSet();
        valueOps.add(key, value);
        if (time > 0) {
            redisTemplate.expire(key, time, TimeUnit.SECONDS);
        }
    } catch (Throwable t) {
        logger.error("setSet key [{}] exception!", key, t);
        throw new CommonException(t);
    }
}
 
Example 7
Source File: RedisCacheUtils.java    From sophia_scaffolding with Apache License 2.0 5 votes vote down vote up
public void setSet(String k, Set<T> v, long time) {
    String key = GlobalsConstants.KEY_SET_PREFIX + k;
    logger.debug("setSet key [{}]", key);
    try {
        SetOperations<String, T> setOps = redisTemplate.opsForSet();
        setOps.add(key, (T[]) v.toArray());
        if (time > 0) {
            redisTemplate.expire(key, time, TimeUnit.SECONDS);
        }
    } catch (Throwable t) {
        logger.error("setSet key [{}] exception!", key, t);
        throw new CommonException(t);
    }
}
 
Example 8
Source File: RedisCacheUtils.java    From sophia_scaffolding with Apache License 2.0 5 votes vote down vote up
public void setSet(String k, Set<T> v, long time) {
    String key = GlobalsConstants.KEY_SET_PREFIX + k;
    logger.debug("setSet key [{}]", key);
    try {
        SetOperations<String, T> setOps = redisTemplate.opsForSet();
        setOps.add(key, (T[]) v.toArray());
        if (time > 0) {
            redisTemplate.expire(key, time, TimeUnit.SECONDS);
        }
    } catch (Throwable t) {
        logger.error("setSet key [{}] exception!", key, t);
        throw new CommonException(t);
    }
}
 
Example 9
Source File: RedisSetServiceImpl.java    From paascloud-master with Apache License 2.0 5 votes vote down vote up
@Override
public Long add(String key, String... value) {
	SetOperations<String, String> setOps = rt.opsForSet();
	Long result = setOps.add(key, value);
	log.info("add - 向key里面添加元素, key={}, value={}, result={}", key, value, result);
	return result;
}
 
Example 10
Source File: CacheServiceProvider.java    From AsuraFramework with Apache License 2.0 4 votes vote down vote up
@Override
public void pushSet(final String key, final String... values) {
	final SetOperations<String, String> operation = redisTemplate.opsForSet();
	operation.add(getKey(key), values);
}
 
Example 11
Source File: RedisService.java    From JavaQuarkBBS with Apache License 2.0 2 votes vote down vote up
/**
 * 设置Set缓存
 * @param key
 * @param t
 */
public void cacheSet(String key,T t){
    SetOperations<String,T> opsForSet = redisTemplate.opsForSet();
    opsForSet.add(key,t);
}
 
Example 12
Source File: RedisService.java    From JavaQuarkBBS with Apache License 2.0 2 votes vote down vote up
/**
 * 设置Set缓存
 * @param key
 * @param t
 */
public void cacheSet(String key,T t){
    SetOperations<String,T> opsForSet = redisTemplate.opsForSet();
    opsForSet.add(key,t);
}