Example usage for org.springframework.data.redis.connection RedisConnection set

List of usage examples for org.springframework.data.redis.connection RedisConnection set

Introduction

In this page you can find the example usage for org.springframework.data.redis.connection RedisConnection set.

Prototype

@Nullable
Boolean set(byte[] key, byte[] value, Expiration expiration, SetOption option);

Source Link

Document

Set value for key applying timeouts from expiration if set and inserting/updating values depending on option .

Usage

From source file:com.zxy.commons.cache.RedisUtils.java

/**
 * Set {@code value} for {@code key} applying timeouts from {@code expiration} if set and inserting/updating values
 * depending on {@code option}.//from ww  w  .  ja v  a2 s  . c o  m
 * <p>
 * See http://redis.io/commands/set
 *
 * @param key must not be {@literal null}.
 * @param value must not be {@literal null}.
 * @param expiration can be {@literal null}. Defaulted to {@link Expiration#persistent()}.
 * @param option can be {@literal null}. Defaulted to {@link SetOption#UPSERT}.
 * @since 1.7
 */
public static void set(byte[] key, byte[] value, Expiration expiration, SetOption option) {
    redisTemplate.execute(new RedisCallback<Void>() {
        @Override
        public Void doInRedis(RedisConnection redis) throws DataAccessException {
            redis.set(key, value, expiration, option);
            return null;
        }
    });
}