/** * 缓存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; }
/** * 缓存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; }
@Override public boolean serverOnline(String server) { SetOperations<String, String> ops = redis.opsForSet(); ops.add(RedisKeys.CLUSTER_SERVERS_ONLINE, server); ops.remove(RedisKeys.CLUSTER_SERVERS_OFFLINE, server); return Boolean.TRUE; }
@Override public boolean serverOffline(String server) { SetOperations<String, String> ops = redis.opsForSet(); ops.remove(RedisKeys.CLUSTER_SERVERS_ONLINE, server); ops.add(RedisKeys.CLUSTER_SERVERS_OFFLINE, server); return Boolean.TRUE; }
/** * 获取缓存set数据 * * @param k key * @return set */ @Override public Set<String> getSet(String k) { try { SetOperations<String, String> setOps = redisTemplate.opsForSet(); return setOps.members(KEY_PREFIX_SET + k); } catch (Throwable t) { LOGGER.error("获取set缓存失败key[" + KEY_PREFIX_SET + k + ", Codeor[" + t + "]"); } return null; }
@Before public void setUp() throws Exception { redisTemplate = mock(RedisTemplate.class); setOperations = mock(SetOperations.class); redisConnection = mock(RedisConnection.class); redisConnectionFactory = mock(RedisConnectionFactory.class); when(redisTemplate.opsForSet()).thenReturn(setOperations); when(redisTemplate.getConnectionFactory()).thenReturn(redisConnectionFactory); when(redisTemplate.getConnectionFactory().getConnection()).thenReturn(redisConnection); idempotentRepository = RedisIdempotentRepository.redisIdempotentRepository(redisTemplate, REPOSITORY); }
@Override public SetOperations<K, V> opsForSet() { try { return redisTemplate.opsForSet(); } catch (Exception ex) { throw new RedisBaoException(ex); } }
@SuppressWarnings("unchecked") protected void _init() { principalService = mock(PrincipalService.class); followersService = mock(FollowersService.class); twitterService = mock(TwitterService.class); featureRedisTemplate = mock(RedisTemplate.class); featureSetOperations = mock(SetOperations.class); }
@Override public String popSet(final String key) { final SetOperations<String, String> operation = redisTemplate.opsForSet(); final String value = operation.pop(getKey(key)); return value; }
@Override public void pushSet(final String key, final String... values) { final SetOperations<String, String> operation = redisTemplate.opsForSet(); operation.add(getKey(key), values); }
@Override public Set<String> rangeSet(final String key) { final SetOperations<String, String> operation = redisTemplate.opsForSet(); final Set<String> value = operation.members(getKey(key)); return value; }
@Override public SetOperations<K, V> opsForSet() { int dbIndex = RedisApplication.redisConnectionDbIndex.get(); return new DefaultSetOperations<K, V>(this, dbIndex); }
public SetOperations<String, String> setOps() { return redisTemplate.opsForSet(); }
@Before public void setUp() throws Exception { redisTemplate = mock(RedisTemplate.class); setOperations = mock(SetOperations.class); super.setUp(); }
/** * 设置Set缓存 * @param key * @param t */ public void cacheSet(String key,T t){ SetOperations<String,T> opsForSet = redisTemplate.opsForSet(); opsForSet.add(key,t); }
/** * 删除Set缓存 * @param key * @param t */ public void deleteSet(String key,T t){ SetOperations<String,T> opsForSet = redisTemplate.opsForSet(); opsForSet.remove(key,t); }
/** * 判断Set是否存在value * @param key * @param t * @return */ public boolean setHasValue(String key, T t){ SetOperations<String,T> opsForSet = redisTemplate.opsForSet(); return opsForSet.isMember(key, t); }
public SetOperations<String, Object> opsForSet(){ return redisTemplate.opsForSet(); }
SetOperations<K, V> opsForSet();