@Override @SuppressWarnings("unchecked") public boolean add(E e) { Long result = boundSetOps.add(e); checkResult(result); return result == 1; }
@Override public Iterator<E> iterator() { Set<E> members = boundSetOps.members(); checkResult(members); return new DefaultRedisSetIterator(members.iterator()); }
@Test public void onExpirationUpdatedDeleteOnZero() throws Exception { String sessionKey = this.policy.getSessionKey("expires:" + this.session.getId()); long originalExpirationTimeInMs = ONE_MINUTE_AGO; this.session.setMaxInactiveInterval(Duration.ZERO); this.policy.onExpirationUpdated(originalExpirationTimeInMs, this.session); // verify the original is removed verify(this.setOperations).remove("expires:" + this.session.getId()); verify(this.setOperations).add("expires:" + this.session.getId()); verify(this.sessionRedisOperations).delete(sessionKey); verify(this.setOperations).expire( this.session.getMaxInactiveInterval().plusMinutes(5).getSeconds(), TimeUnit.SECONDS); }
/** * Constructs a new {@link DefaultRedisSet} instance. * * @param boundOps {@link BoundSetOperations} for the value type of this set. */ public DefaultRedisSet(BoundSetOperations<String, E> boundOps) { super(boundOps.getKey(), boundOps.getOperations()); this.boundSetOps = boundOps; }
@Override public RedisSet<E> diffAndStore(RedisSet<?> set, String destKey) { boundSetOps.diffAndStore(set.getKey(), destKey); return new DefaultRedisSet<>(boundSetOps.getOperations().boundSetOps(destKey)); }
this.originalPrincipalName); RedisOperationsSessionRepository.this.sessionRedisOperations .boundSetOps(originalPrincipalRedisKey).remove(sessionId); String principalRedisKey = getPrincipalKey(principal); RedisOperationsSessionRepository.this.sessionRedisOperations .boundSetOps(principalRedisKey).add(sessionId);
@Test public void onExpirationUpdatedAddsExpirationTimeRoundedUp() throws Exception { long expirationTimeInMs = RedisSessionExpirationPolicy .expiresInMillis(this.session); long expirationRoundedUpInMs = RedisSessionExpirationPolicy .roundUpToNextMinute(expirationTimeInMs); String expectedExpireKey = this.policy.getExpirationKey(expirationRoundedUpInMs); this.policy.onExpirationUpdated(null, this.session); verify(this.sessionRedisOperations).boundSetOps(expectedExpireKey); verify(this.setOperations).add("expires:" + this.session.getId()); verify(this.setOperations).expire( this.session.getMaxInactiveInterval().plusMinutes(5).getSeconds(), TimeUnit.SECONDS); }
@Override public boolean remove(Object o) { Long result = boundSetOps.remove(o); checkResult(result); return result == 1; }
@Override public Set<E> diff(RedisSet<?> set) { return boundSetOps.diff(set.getKey()); }
@Test public void saveJavadocSummary() { RedisSession session = this.redisRepository.createSession(); String sessionKey = "spring:session:sessions:" + session.getId(); String backgroundExpireKey = "spring:session:expirations:" + RedisSessionExpirationPolicy.roundUpToNextMinute( RedisSessionExpirationPolicy.expiresInMillis(session)); String destroyedTriggerKey = "spring:session:sessions:expires:" + session.getId(); given(this.redisOperations.boundHashOps(sessionKey)) .willReturn(this.boundHashOperations); given(this.redisOperations.boundSetOps(backgroundExpireKey)) .willReturn(this.boundSetOperations); given(this.redisOperations.boundValueOps(destroyedTriggerKey)) .willReturn(this.boundValueOperations); this.redisRepository.save(session); // the actual data in the session expires 5 minutes after expiration so the data // can be accessed in expiration events // if the session is retrieved and expired it will not be returned since // findById checks if it is expired long fiveMinutesAfterExpires = session.getMaxInactiveInterval().plusMinutes(5) .getSeconds(); verify(this.boundHashOperations).expire(fiveMinutesAfterExpires, TimeUnit.SECONDS); verify(this.boundSetOperations).expire(fiveMinutesAfterExpires, TimeUnit.SECONDS); verify(this.boundSetOperations).add("expires:" + session.getId()); verify(this.boundValueOperations).expire(1800L, TimeUnit.SECONDS); verify(this.boundValueOperations).append(""); }
private void cleanupPrincipalIndex(RedisSession session) { String sessionId = session.getId(); String principal = PRINCIPAL_NAME_RESOLVER.resolvePrincipal(session); if (principal != null) { this.sessionRedisOperations.boundSetOps(getPrincipalKey(principal)) .remove(sessionId); } }
@Override public RedisSet<E> diffAndStore(Collection<? extends RedisSet<?>> sets, String destKey) { boundSetOps.diffAndStore(CollectionUtils.extractKeys(sets), destKey); return new DefaultRedisSet<>(boundSetOps.getOperations().boundSetOps(destKey)); }
/** * Constructs a new {@link DefaultRedisSet} instance. * * @param boundOps {@link BoundSetOperations} for the value type of this set. */ public DefaultRedisSet(BoundSetOperations<String, E> boundOps) { super(boundOps.getKey(), boundOps.getOperations()); this.boundSetOps = boundOps; }
@Override public Set<E> diff(Collection<? extends RedisSet<?>> sets) { return boundSetOps.diff(CollectionUtils.extractKeys(sets)); }
@SuppressWarnings("unchecked") private void writeToSet(final RedisSet<Object> set, Message<?> message) { final Object payload = message.getPayload(); if (this.extractPayloadElements && payload instanceof Collection<?>) { BoundSetOperations<String, Object> ops = (BoundSetOperations<String, Object>) this.redisTemplate.boundSetOps(set.getKey()); processInPipeline(() -> { for (Object object : ((Collection<?>) payload)) { ops.add(object); } }); } else { set.add(payload); } }
if (toExpire != originalRoundedUp) { String expireKey = getExpirationKey(originalRoundedUp); this.redis.boundSetOps(expireKey).remove(keyToExpire); BoundSetOperations<Object, Object> expireOperations = this.redis .boundSetOps(expireKey); expireOperations.add(keyToExpire); expireOperations.expire(fiveMinutesAfterExpires, TimeUnit.SECONDS); if (sessionExpireInSeconds == 0) { this.redis.delete(sessionKey);
@Override public Map<String, RedisSession> findByIndexNameAndIndexValue(String indexName, String indexValue) { if (!PRINCIPAL_NAME_INDEX_NAME.equals(indexName)) { return Collections.emptyMap(); } String principalKey = getPrincipalKey(indexValue); Set<Object> sessionIds = this.sessionRedisOperations.boundSetOps(principalKey) .members(); Map<String, RedisSession> sessions = new HashMap<>( sessionIds.size()); for (Object id : sessionIds) { RedisSession session = findById((String) id); if (session != null) { sessions.put(session.getId(), session); } } return sessions; }
public void onDelete(Session session) { long toExpire = roundUpToNextMinute(expiresInMillis(session)); String expireKey = getExpirationKey(toExpire); this.redis.boundSetOps(expireKey).remove(session.getId()); }
@Override public RedisSet<E> diffAndStore(Collection<? extends RedisSet<?>> sets, String destKey) { boundSetOps.diffAndStore(CollectionUtils.extractKeys(sets), destKey); return new DefaultRedisSet<>(boundSetOps.getOperations().boundSetOps(destKey)); }
/** * Constructs a new {@link DefaultRedisSet} instance. * * @param boundOps {@link BoundSetOperations} for the value type of this set. */ public DefaultRedisSet(BoundSetOperations<String, E> boundOps) { super(boundOps.getKey(), boundOps.getOperations()); this.boundSetOps = boundOps; }