daniel1171
daniel1171

Reputation: 11

Configure TTL on Semaphores in Redis using Redisson

I am trying to acquire a distributed lock using Redisson. I have narrowed it down to an RSemaphore since the critical section is sitting in a Reactive stream and Java's contract of a single thread owning and releasing a lock doesn't work here. The situation I am running into is that the lock Objects in Redis have a TTL of -1 (never expire). This semaphore is for locking around objects so our service cluster remains coordinated and will be creating thousands of semaphores with no reentrant requirement.

I cannot for the life of me find a way to set a TTL on the Semaphore Object. I see options for permit expiry but not for the semaphore itself. Zookeeper is not an option in this environment, but I know ZK has multiple options for solving this problem (ChildReapers and CreateMode.CONTAINER). This seems like an extremely basic requirement of the RSemaphore API.

Upvotes: 0

Views: 1185

Answers (1)

daniel1171
daniel1171

Reputation: 11

I upgraded my Redisson library version to be able to access the expire() method. Apparently versions starting at 3.11.0 (?) have thos method inherited from RExpirable.

Upvotes: 1

Related Questions