Package com.github.ddth.dlock.impl.redis
Class BaseRedisDLock
- java.lang.Object
-
- com.github.ddth.dlock.impl.AbstractDLock
-
- com.github.ddth.dlock.impl.redis.BaseRedisDLock
-
- All Implemented Interfaces:
IDLock,AutoCloseable
- Direct Known Subclasses:
ClusteredRedisDLock,RedisDLock
public abstract class BaseRedisDLock extends AbstractDLock
- Since:
- 0.1.0
- Author:
- Thanh Ba Nguyen
-
-
Field Summary
Fields Modifier and Type Field Description static StringLOCK_PROP_REDIS_PASSWORDTo override thesetRedisPassword(String)setting.protected booleanmyOwnRedisFlag to mark if the Redis resource (e.g.-
Fields inherited from interface com.github.ddth.dlock.IDLock
DEFAULT_LOCK_DURATION_MS
-
-
Constructor Summary
Constructors Constructor Description BaseRedisDLock(String name)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract com.github.ddth.commons.redis.JedisConnectorbuildJedisConnector()Build aJedisConnectorinstance for my own use.voiddestroy()Cleanup method.com.github.ddth.commons.redis.JedisConnectorgetJedisConnector()StringgetRedisPassword()Password to connect to Redis server/cluster.protected StringgetScriptLock()protected StringgetScriptUnlock()protected StringgetZsetName()Get name of the ZSET to store clientId's score.BaseRedisDLockinit()Init method.BaseRedisDLocksetJedisConnector(com.github.ddth.commons.redis.JedisConnector jedisConnector)BaseRedisDLocksetRedisPassword(String redisPassword)Password to connect to Redis server/cluster.protected BaseRedisDLocksetScriptLock(String scriptLock)protected BaseRedisDLocksetScriptUnlock(String scriptUnlock)protected LockResultunlockResult(Object response)Convenient method to build result forIDLock.unlock(String)} method with result from Redis server.protected voidupdateLockHolder(redis.clients.jedis.commands.JedisClusterCommands jedisClusterCommands)Update current lock's holder info.protected voidupdateLockHolder(redis.clients.jedis.commands.JedisCommands jedisCommands)Update current lock's holder info.-
Methods inherited from class com.github.ddth.dlock.impl.AbstractDLock
close, getClientId, getLockProperties, getLockProperty, getName, getTimestampExpiry, lock, lock, lock, setClientId, setLockProperties, setName, setTimestampExpiry, toString, updateLockHolder
-
-
-
-
Field Detail
-
LOCK_PROP_REDIS_PASSWORD
public static final String LOCK_PROP_REDIS_PASSWORD
To override thesetRedisPassword(String)setting.- See Also:
- Constant Field Values
-
myOwnRedis
protected boolean myOwnRedis
Flag to mark if the Redis resource (e.g. Redis client pool) is created and handled by the lock instance.
-
-
Constructor Detail
-
BaseRedisDLock
public BaseRedisDLock(String name)
-
-
Method Detail
-
getJedisConnector
public com.github.ddth.commons.redis.JedisConnector getJedisConnector()
- Returns:
-
setJedisConnector
public BaseRedisDLock setJedisConnector(com.github.ddth.commons.redis.JedisConnector jedisConnector)
- Parameters:
jedisConnector-- Returns:
-
getRedisPassword
public String getRedisPassword()
Password to connect to Redis server/cluster.- Returns:
-
setRedisPassword
public BaseRedisDLock setRedisPassword(String redisPassword)
Password to connect to Redis server/cluster.- Parameters:
redisPassword-- Returns:
-
buildJedisConnector
protected abstract com.github.ddth.commons.redis.JedisConnector buildJedisConnector()
Build aJedisConnectorinstance for my own use.- Returns:
- Since:
- 0.1.1.2
-
init
public BaseRedisDLock init()
Init method.- Overrides:
initin classAbstractDLock- Returns:
-
destroy
public void destroy()
Cleanup method.- Overrides:
destroyin classAbstractDLock
-
getScriptLock
protected String getScriptLock()
-
setScriptLock
protected BaseRedisDLock setScriptLock(String scriptLock)
-
getScriptUnlock
protected String getScriptUnlock()
-
setScriptUnlock
protected BaseRedisDLock setScriptUnlock(String scriptUnlock)
-
updateLockHolder
protected void updateLockHolder(redis.clients.jedis.commands.JedisClusterCommands jedisClusterCommands)
Update current lock's holder info.- Parameters:
jedisClusterCommands-- Since:
- 1.0.0
-
updateLockHolder
protected void updateLockHolder(redis.clients.jedis.commands.JedisCommands jedisCommands)
Update current lock's holder info.- Parameters:
jedisCommands-- Since:
- 0.1.1
-
getZsetName
protected String getZsetName()
Get name of the ZSET to store clientId's score.- Returns:
- Since:
- 0.1.2
-
unlockResult
protected LockResult unlockResult(Object response)
Convenient method to build result forIDLock.unlock(String)} method with result from Redis server.- Parameters:
response-- Returns:
- Since:
- 1.0.0
-
-