示例#1
0
 private static void UnlockSafe(
     this IRedlockInstance instance,
     ILogger logger,
     string resource,
     string nonce
     )
 {
     try
     {
         instance.Unlock(resource, nonce);
     }
     catch (Exception e)
     {
         logger.LogError(e, "Unable to unlock ['{}'] = '{}' on [{}]", resource, nonce, instance);
     }
 }
示例#2
0
 private static async Task UnlockSafeAsync(
     this IRedlockInstance instance,
     ILogger logger,
     string resource,
     string nonce
     )
 {
     try
     {
         await instance.UnlockAsync(resource, nonce).ConfigureAwait(false);
     }
     catch (Exception e)
     {
         logger.LogError(e, "Unable to unlock ['{}'] = '{}' on [{}]", resource, nonce, instance);
     }
 }
示例#3
0
 private static async Task <bool> TryExtendSafeAsync(
     this IRedlockInstance instance,
     ILogger logger,
     string resource,
     string nonce,
     TimeSpan lockTimeToLive
     )
 {
     try
     {
         return((await instance.TryExtendAsync(resource, nonce, lockTimeToLive).ConfigureAwait(false)).IsSuccess());
     }
     catch (Exception e)
     {
         logger.LogError(e, "Unable to extend lock ['{}'] = '{}' on [{}]", resource, nonce, instance);
         return(false);
     }
 }
示例#4
0
 private static bool TryExtendSafe(
     this IRedlockInstance instance,
     ILogger logger,
     string resource,
     string nonce,
     TimeSpan lockTimeToLive
     )
 {
     try
     {
         return(instance.TryExtend(resource, nonce, lockTimeToLive).IsSuccess());
     }
     catch (Exception e)
     {
         logger.LogError(e, "Unable to extend lock ['{}'] = '{}' on [{}]", resource, nonce, instance);
         return(false);
     }
 }
示例#5
0
 private static async Task <bool> TryLockSafeAsync(
     this IRedlockInstance instance,
     ILogger logger,
     string resource,
     string nonce,
     TimeSpan lockTimeToLive,
     IReadOnlyDictionary <string, string>?metadata = null
     )
 {
     try
     {
         return(await instance.TryLockAsync(resource, nonce, lockTimeToLive, metadata).ConfigureAwait(false));
     }
     catch (Exception e)
     {
         logger.LogError(e, "Unable to acquire lock ['{}'] = '{}' on [{}]", resource, nonce, instance);
         return(false);
     }
 }