Skip to content

Commit

Permalink
增加延时队列文档
Browse files Browse the repository at this point in the history
  • Loading branch information
d4ilys committed Jul 2, 2024
1 parent 14dce45 commit a8c154c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 54 deletions.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ FreeRedis is a redis client based on .NET, supports .NET Core 2.1+, .NET Framewo
<span>English</span> |
<a href="README.zh-CN.md">中文</a>
</p>

</div>

- 🌈 RedisClient Keep all method names consistent with redis-cli
Expand Down Expand Up @@ -224,6 +223,28 @@ foreach (var keys in cli.Scan("*", 10, null))
}
```

### 🍡DelayQueue

```c#
var delayQueue = cli.DelayQueue("TestDelayQueue");

//Add queue
delayQueue.Enqueue($"Execute in 5 seconds.", TimeSpan.FromSeconds(5));
delayQueue.Enqueue($"Execute in 10 seconds.", DateTime.Now.AddSeconds(10));
delayQueue.Enqueue($"Execute in 15 seconds.", DateTime.Now.AddSeconds(15));
delayQueue.Enqueue($"Execute in 20 seconds.", TimeSpan.FromSeconds(20));
delayQueue.Enqueue($"Execute in 25 seconds.", DateTime.Now.AddSeconds(25));
delayQueue.Enqueue($"Execute in 2024-07-02 14:30:15", DateTime.Parse("2024-07-02 14:30:15"));

//Consumption queue
await delayQueue.DequeueAsync(s =>
{
output.WriteLine($"{DateTime.Now}:{s}");

return Task.CompletedTask;
});
```

## 👯 Contributors

<a href="https://github.com/2881099/FreeRedis/graphs/contributors">
Expand Down
21 changes: 21 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,27 @@ foreach (var keys in cli.Scan("*", 10, null))
}
```

### 🍡DelayQueue (延时队列)

```c#
var delayQueue = cli.DelayQueue("TestDelayQueue");

//添加队列
delayQueue.Enqueue($"Execute in 5 seconds.", TimeSpan.FromSeconds(5));
delayQueue.Enqueue($"Execute in 10 seconds.", DateTime.Now.AddSeconds(10));
delayQueue.Enqueue($"Execute in 15 seconds.", DateTime.Now.AddSeconds(15));
delayQueue.Enqueue($"Execute in 20 seconds.", TimeSpan.FromSeconds(20));
delayQueue.Enqueue($"Execute in 25 seconds.", DateTime.Now.AddSeconds(25));
delayQueue.Enqueue($"Execute in 2024-07-02 14:30:15", DateTime.Parse("2024-07-02 14:30:15"));

//消费延时队列
await delayQueue.DequeueAsync(s =>
{
output.WriteLine($"{DateTime.Now}:{s}");

return Task.CompletedTask;
});
```

## 👯 Contributors (贡献者)

Expand Down
56 changes: 3 additions & 53 deletions test/Unit/FreeRedis.Tests/RedisClientTests/DelayQueueTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,62 +11,13 @@ namespace FreeRedis.Tests.RedisClientTests
{
public class DelayQueueTest(ITestOutputHelper output)
{
static readonly RedisClient _client = new RedisClient(
new ConnectionStringBuilder[]
{
new()
{
Host = "192.168.1.114:6381",
Password = "111111",
MaxPoolSize = 5,
MinPoolSize = 1
},
new()
{
Host = "192.168.1.113:6381",
Password = "111111",
MaxPoolSize = 5,
MinPoolSize = 1
},
new()
{
Host = "192.168.1.113:6382",
Password = "111111",
MaxPoolSize = 1,
MinPoolSize = 1
},

new()
{
Host = "192.168.1.114:6382",
Password = "111111",
MaxPoolSize = 5,
MinPoolSize = 1
},
new()
{
Host = "192.168.1.116:6381",
Password = "111111",
MaxPoolSize = 5,
MinPoolSize = 1
},
new()
{
Host = "192.168.1.116:6382",
Password = "111111",
MaxPoolSize = 5,
MinPoolSize = 1
},
}
);

private readonly ITestOutputHelper _output = output;
static readonly RedisClient _client = new RedisClient("127.0.0.1:6379,password=123");

[Fact]
public async Task Test()
{
var delayQueue = _client.DelayQueue("TestDelayQueue");

//添加队列
delayQueue.Enqueue($"Execute in 5 seconds.", TimeSpan.FromSeconds(5));
delayQueue.Enqueue($"Execute in 10 seconds.", DateTime.Now.AddSeconds(10));
Expand All @@ -79,11 +30,10 @@ public async Task Test()
//消费延时队列
await delayQueue.DequeueAsync(s =>
{
_output.WriteLine($"{DateTime.Now}{s}");
output.WriteLine($"{DateTime.Now}{s}");

return Task.CompletedTask;
});

}
}
}

0 comments on commit a8c154c

Please sign in to comment.