You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
KeyMajority: 1, // Use KeyMajority=1 if you have only one Redis instance. Also make sure that all your `Locker`s share the same KeyMajority.
18
+
NoLoopTracking: true, // Enable this to have better performance if all your Redis are >= 7.0.5.
18
19
})
19
20
if err != nil {
20
21
panic(err)
@@ -37,21 +38,90 @@ func main() {
37
38
38
39
## Features backed by the Redis Client Side Caching
39
40
* The returned `ctx` will be canceled automatically and immediately once the `KeyMajority` is not held anymore, for example:
40
-
* Redis down.
41
-
*Related keys has been deleted by other program or administrator.
42
-
* The waiting `Locker.WithContext` will try acquiring the lock again automatically and immediately once it has been released by someone even from other program.
41
+
* Redis are down.
42
+
*Acquired keys has been deleted by other programs or administrators.
43
+
* The waiting `Locker.WithContext` will try acquiring the lock again automatically and immediately once it has been released by someone or by another program.
43
44
44
45
## How it works
45
46
46
47
When the `locker.WithContext` is invoked, it will:
47
48
48
-
1. Try acquiring 3 keys (given that `KeyMajority` is 2), which are `rueidislock:0:my_lock`, `rueidislock:1:my_lock` and `rueidislock:2:my_lock`, by sending redis command `SET NX PXAT` or `SET NX PX` if `FallbackSETPX` is set.
49
+
1. Try acquiring 3 keys (given that the default `KeyMajority` is 2), which are `rueidislock:0:my_lock`, `rueidislock:1:my_lock` and `rueidislock:2:my_lock`, by sending redis command `SET NX PXAT` or `SET NX PX` if `FallbackSETPX` is set.
49
50
2. If the `KeyMajority` is satisfied within the `KeyValidity` duration, the invocation is successful and a `ctx` is returned as the lock.
50
-
3. If the invocation is not successful, it will wait for client-side caching notification to retry again.
51
-
4. If the invocation is successful, the `Locker` will extend the `ctx` validity periodically and also watch client-side caching notification for canceling the `ctx` if the `KeyMajority` is not held anymore.
51
+
3. If the invocation is not successful, it will wait for client-side caching notifications to retry again.
52
+
4. If the invocation is successful, the `Locker` will extend the `ctx` validity periodically and also watch client-side caching notifications for canceling the `ctx` if the `KeyMajority` is not held anymore.
52
53
53
54
### Disable Client Side Caching
54
55
55
56
Some Redis provider doesn't support client-side caching, ex. Google Cloud Memorystore.
56
57
You can disable client-side caching by setting `ClientOption.DisableCache` to `true`.
57
-
Please note that when the client-side caching is disabled, rueidislock will only try to re-acquire locks for every ExtendInterval.
58
+
Please note that when the client-side caching is disabled, rueidislock will only try to re-acquire locks for every ExtendInterval.
0 commit comments