Class RedisLockProvider
java.lang.Object
net.javacrumbs.shedlock.provider.redis.spring.RedisLockProvider
- All Implemented Interfaces:
LockProvider
public class RedisLockProvider extends Object implements LockProvider
Uses Redis's `SET resource-name anystring NX PX max-lock-ms-time` as locking mechanism.
See https://redis.io/commands/set
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRedisLockProvider.Builder -
Constructor Summary
Constructors Constructor Description RedisLockProvider(org.springframework.data.redis.connection.RedisConnectionFactory redisConn)RedisLockProvider(org.springframework.data.redis.connection.RedisConnectionFactory redisConn, String environment)Creates RedisLockProviderRedisLockProvider(org.springframework.data.redis.connection.RedisConnectionFactory redisConn, String environment, String keyPrefix)Creates RedisLockProviderRedisLockProvider(org.springframework.data.redis.core.StringRedisTemplate redisTemplate, String environment, String keyPrefix)Create RedisLockProvider -
Method Summary
Modifier and Type Method Description Optional<SimpleLock>lock(LockConfiguration lockConfiguration)
-
Constructor Details
-
RedisLockProvider
public RedisLockProvider(org.springframework.data.redis.connection.RedisConnectionFactory redisConn) -
RedisLockProvider
public RedisLockProvider(org.springframework.data.redis.connection.RedisConnectionFactory redisConn, String environment)Creates RedisLockProvider- Parameters:
redisConn- RedisConnectionFactoryenvironment- environment is part of the key and thus makes sure there is not key conflict between multiple ShedLock instances running on the same Redis
-
RedisLockProvider
public RedisLockProvider(org.springframework.data.redis.connection.RedisConnectionFactory redisConn, String environment, String keyPrefix)Creates RedisLockProvider- Parameters:
redisConn- RedisConnectionFactoryenvironment- environment is part of the key and thus makes sure there is not key conflict between multiple ShedLock instances running on the same RediskeyPrefix- prefix of the key in Redis.
-
RedisLockProvider
public RedisLockProvider(org.springframework.data.redis.core.StringRedisTemplate redisTemplate, String environment, String keyPrefix)Create RedisLockProvider- Parameters:
redisTemplate- StringRedisTemplateenvironment- environment is part of the key and thus makes sure there is not key conflict between multiple ShedLock instances running on the same RediskeyPrefix- prefix of the key in Redis.
-
-
Method Details
-
lock
- Specified by:
lockin interfaceLockProvider
-