All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jn.agileway.redis.locks.RedisLocks Maven / Gradle / Ivy

Go to download

Provides a large number of convenient redis tools: distributed locks, distributed count, distributed cache, distributed id generator, jdk collection implements, the enhanced RedisTemplate based on a specified key prefix and the agileway-codec module

There is a newer version: 5.0.4
Show newest version
package com.jn.agileway.redis.locks;

import com.jn.agileway.redis.core.RedisTemplate;
import com.jn.langx.Builder;
import com.jn.langx.annotation.NonNull;
import com.jn.langx.annotation.Nullable;
import com.jn.langx.util.Preconditions;

public class RedisLocks {

    public static ExclusiveLock newExclusiveLock(@NonNull RedisTemplate redisTemplate, @NonNull String resourceKey) {
        return newExclusiveLock(redisTemplate, resourceKey, null);
    }

    public static ExclusiveLock newExclusiveLock(@NonNull RedisTemplate redisTemplate, @NonNull String resourceKey, @Nullable Builder randomValueBuilder) {
        Preconditions.checkNotNull(redisTemplate, "the redisTemplate is null");
        Preconditions.checkNotNull(resourceKey, "the resource is null");
        ExclusiveLock lock = new ExclusiveLock();
        lock.setRedisTemplate(redisTemplate);
        lock.setResource(resourceKey);
        if (randomValueBuilder != null) {
            lock.setLockRandomValueBuilder(randomValueBuilder);
        }
        return lock;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy