Example usage for org.springframework.data.redis.core BoundSetOperations add

List of usage examples for org.springframework.data.redis.core BoundSetOperations add

Introduction

In this page you can find the example usage for org.springframework.data.redis.core BoundSetOperations add.

Prototype

@Nullable
Long add(V... values);

Source Link

Document

Add given values to set at the bound key.

Usage

From source file:org.springframework.integration.redis.outbound.RedisCollectionPopulatingMessageHandler.java

@SuppressWarnings("unchecked")
private void handleSet(final RedisSet<Object> set, Message<?> message) {
    final Object payload = message.getPayload();
    if (this.extractPayloadElements && payload instanceof Collection<?>) {
        final BoundSetOperations<String, Object> ops = (BoundSetOperations<String, Object>) this.redisTemplate
                .boundSetOps(set.getKey());

        this.processInPipeline(new PipelineCallback() {
            public void process() {
                for (Object object : ((Collection<?>) payload)) {
                    ops.add(object);
                }//from w w w  .j  av  a2s.  co  m
            }
        });
    } else {
        set.add(payload);
    }
}

From source file:org.springframework.integration.redis.outbound.RedisStoreWritingMessageHandler.java

@SuppressWarnings("unchecked")
private void writeToSet(final RedisSet<Object> set, Message<?> message) {
    final Object payload = message.getPayload();
    if (this.extractPayloadElements && payload instanceof Collection<?>) {
        final BoundSetOperations<String, Object> ops = (BoundSetOperations<String, Object>) this.redisTemplate
                .boundSetOps(set.getKey());

        this.processInPipeline(new PipelineCallback() {
            public void process() {
                for (Object object : ((Collection<?>) payload)) {
                    ops.add(object);
                }/*from  www.  j  a v a 2 s.  c o  m*/
            }
        });
    } else {
        set.add(payload);
    }
}

From source file:org.springframework.session.data.redis.RedisSessionExpirationPolicy.java

public void onExpirationUpdated(Long originalExpirationTimeInMilli, ExpiringSession session) {
    String keyToExpire = "expires:" + session.getId();
    long toExpire = roundUpToNextMinute(expiresInMillis(session));

    if (originalExpirationTimeInMilli != null) {
        long originalRoundedUp = roundUpToNextMinute(originalExpirationTimeInMilli);
        if (toExpire != originalRoundedUp) {
            String expireKey = getExpirationKey(originalRoundedUp);
            this.redis.boundSetOps(expireKey).remove(keyToExpire);
        }/*from www  .  j  a  va2  s .  c om*/
    }

    long sessionExpireInSeconds = session.getMaxInactiveIntervalInSeconds();
    String sessionKey = getSessionKey(keyToExpire);

    if (sessionExpireInSeconds < 0) {
        this.redis.boundValueOps(sessionKey).append("");
        this.redis.boundValueOps(sessionKey).persist();
        this.redis.boundHashOps(getSessionKey(session.getId())).persist();
        return;
    }

    String expireKey = getExpirationKey(toExpire);
    BoundSetOperations<Object, Object> expireOperations = this.redis.boundSetOps(expireKey);
    expireOperations.add(keyToExpire);

    long fiveMinutesAfterExpires = sessionExpireInSeconds + TimeUnit.MINUTES.toSeconds(5);

    expireOperations.expire(fiveMinutesAfterExpires, TimeUnit.SECONDS);
    if (sessionExpireInSeconds == 0) {
        this.redis.delete(sessionKey);
    } else {
        this.redis.boundValueOps(sessionKey).append("");
        this.redis.boundValueOps(sessionKey).expire(sessionExpireInSeconds, TimeUnit.SECONDS);
    }
    this.redis.boundHashOps(getSessionKey(session.getId())).expire(fiveMinutesAfterExpires, TimeUnit.SECONDS);
}