-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathRedisLock.cs
More file actions
30 lines (27 loc) · 793 Bytes
/
RedisLock.cs
File metadata and controls
30 lines (27 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System;
using System.Threading.Tasks;
using StackExchange.Redis;
namespace Gofer.NET
{
public class RedisLock : IBackendLock
{
private readonly IDatabase _db;
private readonly string _key;
private readonly string _token;
public RedisLock(IDatabase db, string key, string token)
{
_db = db;
_key = key;
_token = token;
}
public async Task Release()
{
var success = await _db.LockReleaseAsync(_key, _token);
if (!success)
{
throw new Exception("Unable to release redis lock. " +
"Usually this means that the lock itself timed out and was auto-released.");
}
}
}
}