• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Hyshmily / hotkey / 27856464831

20 Jun 2026 01:44AM UTC coverage: 93.742% (-0.9%) from 94.613%
27856464831

push

github

Hyshmily
feat: add distributed lock (tryLock/tryLockAndRun) with Redis-based AutoReleaseLock

Signed-off-by: Hyshmily <cxm8607@outlook.com>

1108 of 1235 branches covered (89.72%)

Branch coverage included in aggregate %.

69 of 97 new or added lines in 5 files covered. (71.13%)

2 existing lines in 2 files now uncovered.

3191 of 3351 relevant lines covered (95.23%)

4.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/common/src/main/java/io/github/hyshmily/hotkey/cache/distributedlock/LockProvider.java
1
/*
2
 * Copyright 2026 Hyshmily. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package io.github.hyshmily.hotkey.cache.distributedlock;
17

18
import java.util.concurrent.TimeUnit;
19

20
/**
21
 * Provider for distributed locks backed by a key-value store (typically Redis).
22
 *
23
 * <p>Two overloads of {@link #tryLock}: the basic variant uses provider-configured
24
 * defaults; the extended variant accepts explicit retry counts (the
25
 * implementation validates and falls back to defaults when parameters are
26
 * illegal).
27
 */
28
public interface LockProvider {
29
  /**
30
   * Attempt to acquire a distributed lock with the provider's default retry
31
   * counts.
32
   *
33
   * @param key    the lock key (never {@code null})
34
   * @param expire the time-to-live for the lock
35
   * @param unit   the time unit for {@code expire}
36
   * @return a {@link AutoReleaseLock} if acquired, or {@code null} if the
37
   *         lock is held by another caller or the provider is unavailable
38
   */
39
  AutoReleaseLock tryLock(String key, long expire, TimeUnit unit);
40

41
  /**
42
   * Attempt to acquire a distributed lock with explicit retry counts.
43
   *
44
   * <p>The default implementation ignores the extra parameters and delegates
45
   * to {@link #tryLock(String, long, TimeUnit)}.  Implementations that
46
   * support dynamic retry should override this method and apply their own
47
   * validation / fallback logic.
48
   *
49
   * @param key           the lock key (never {@code null})
50
   * @param expire        the time-to-live for the lock
51
   * @param unit          the time unit for {@code expire}
52
   * @param lockCount     the number of {@code SET NX} retries
53
   * @param inquiryCount  the number of {@code GET} inquiries after a transient failure
54
   * @param unlockCount   the number of {@code DEL} retries
55
   * @return a {@link AutoReleaseLock} if acquired, or {@code null} if the
56
   *         lock is held by another caller or the provider is unavailable
57
   */
58
  default AutoReleaseLock tryLock(String key, long expire, TimeUnit unit, int lockCount, int inquiryCount, int unlockCount) {
NEW
59
    return tryLock(key, expire, unit);
×
60
  }
61
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc