Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. await this.executionPolicy.ExecuteAsync(
  2. async () =>
  3. {
  4. using (var connection = this.PooledConnection)
  5. {
  6. var multiplexers = new List<RedLockMultiplexer> { new RedLockMultiplexer(connection.Value) };
  7.  
  8. using (var redlockFactory = RedLockFactory.Create(multiplexers))
  9. {
  10. const string Resource = "the-thing-we-are-locking-on";
  11. var lockExpiry = TimeSpan.FromSeconds(20);
  12.  
  13. using (var redLock = await redlockFactory.CreateLockAsync(Resource, lockExpiry))
  14. {
  15. if (redLock.IsAcquired)
  16. {
  17. return await connection.Value.GetDatabase()
  18. .HashGetAsync(hashKey, hashField, GetRedisCommandFlags(commandFlag))
  19. .ConfigureAwait(false);
  20. }
  21.  
  22. return new RedisValue();
  23. }
  24. }
  25. }
  26. })
  27. .ConfigureAwait(false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement