Skip to content

Commit 327dce6

Browse files
author
Vytautas Kasparavičius
committed
Fix regarding #63
1 parent 1fbaf90 commit 327dce6

File tree

3 files changed

+389
-5
lines changed

3 files changed

+389
-5
lines changed

src/Hangfire.PostgreSql/Hangfire.PostgreSql.csproj

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
<PackageReleaseNotes>https://github.com/frankhommers/Hangfire.PostgreSql/releases</PackageReleaseNotes>
1515
<PackageProjectUrl>http://hmm.rs/Hangfire.PostgreSql</PackageProjectUrl>
1616
<PackageLicenseUrl>https://raw.github.com/frankhommers/Hangfire.PostgreSql/master/LICENSE.md</PackageLicenseUrl>
17-
<Version>1.4.7</Version>
17+
<Version>1.4.7.1</Version>
18+
<FileVersion>1.4.7.1</FileVersion>
19+
<AssemblyVersion>1.4.7.1</AssemblyVersion>
1820
</PropertyGroup>
1921

2022
<ItemGroup>

src/Hangfire.PostgreSql/PostgreSqlWriteOnlyTransaction.cs

+99-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using System.Collections.Generic;
2424
using System.Data;
2525
using System.Globalization;
26+
using System.Linq;
2627
using Dapper;
2728
using Hangfire.Common;
2829
using Hangfire.States;
@@ -336,13 +337,107 @@ public override void RemoveHash(string key)
336337
if (key == null) throw new ArgumentNullException(nameof(key));
337338

338339
QueueCommand((con, trx) => con.Execute(
339-
@"
340-
DELETE FROM """ + _options.SchemaName + @""".""hash""
341-
WHERE ""key"" = @key;
342-
",
340+
$@"DELETE FROM ""{_options.SchemaName}"".""hash"" WHERE ""key"" = @key",
343341
new {key}, trx));
344342
}
345343

344+
public override void ExpireSet(string key, TimeSpan expireIn)
345+
{
346+
if (key == null) throw new ArgumentNullException(nameof(key));
347+
348+
string query = $@"UPDATE ""{_options.SchemaName}"".""set"" SET ""expireat"" = @expireAt WHERE ""key"" = @key";
349+
350+
QueueCommand((connection, transaction) => connection.Execute(
351+
query,
352+
new { key, expireAt = DateTime.UtcNow.Add(expireIn) },
353+
transaction));
354+
}
355+
356+
public override void ExpireList(string key, TimeSpan expireIn)
357+
{
358+
if (key == null) throw new ArgumentNullException(nameof(key));
359+
360+
string query = $@"UPDATE ""{_options.SchemaName}"".""list"" SET ""expireat"" = @expireAt WHERE ""key"" = @key";
361+
362+
QueueCommand((connection, transaction) => connection.Execute(
363+
query,
364+
new { key, expireAt = DateTime.UtcNow.Add(expireIn) },
365+
transaction));
366+
}
367+
368+
public override void ExpireHash(string key, TimeSpan expireIn)
369+
{
370+
if (key == null) throw new ArgumentNullException(nameof(key));
371+
372+
string query = $@"UPDATE ""{_options.SchemaName}"".""hash"" SET expireat = @expireAt WHERE ""key"" = @key";
373+
374+
QueueCommand((connection, transaction) => connection.Execute(
375+
query,
376+
new { key, expireAt = DateTime.UtcNow.Add(expireIn) },
377+
transaction));
378+
}
379+
380+
public override void PersistSet(string key)
381+
{
382+
if (key == null) throw new ArgumentNullException(nameof(key));
383+
384+
string query = $@"UPDATE ""{_options.SchemaName}"".""set"" SET expireat = null WHERE ""key"" = @key";
385+
386+
QueueCommand((connection, transaction) => connection.Execute(
387+
query,
388+
new { key },
389+
transaction));
390+
}
391+
392+
public override void PersistList(string key)
393+
{
394+
if (key == null) throw new ArgumentNullException(nameof(key));
395+
396+
string query = $@"UPDATE ""{_options.SchemaName}"".""list"" SET expireat = null WHERE ""key"" = @key";
397+
398+
QueueCommand((connection, transaction) => connection.Execute(
399+
query,
400+
new { key },
401+
transaction));
402+
}
403+
404+
public override void PersistHash(string key)
405+
{
406+
if (key == null) throw new ArgumentNullException(nameof(key));
407+
408+
string query = $@"UPDATE ""{_options.SchemaName}"".""hash"" SET expireat = null WHERE ""key"" = @key";
409+
410+
QueueCommand((connection, transaction) => connection.Execute(
411+
query,
412+
new { key },
413+
transaction));
414+
}
415+
416+
public override void AddRangeToSet(string key, IList<string> items)
417+
{
418+
if (key == null) throw new ArgumentNullException(nameof(key));
419+
if (items == null) throw new ArgumentNullException(nameof(items));
420+
421+
string query = $@"INSERT INTO ""{_options.SchemaName}"".""set"" (""key"", ""value"", ""score"") VALUES (@key, @value, 0.0)";
422+
423+
QueueCommand((connection, transaction) => connection.Execute(
424+
query,
425+
items.Select(value => new { key, value }).ToList(),
426+
transaction));
427+
}
428+
429+
public override void RemoveSet(string key)
430+
{
431+
if (key == null) throw new ArgumentNullException(nameof(key));
432+
433+
string query = $@"DELETE FROM ""{_options.SchemaName}"".""set"" WHERE ""key"" = @key";
434+
435+
QueueCommand((connection, transaction) => connection.Execute(
436+
query,
437+
new { key },
438+
transaction));
439+
}
440+
346441
internal void QueueCommand(Action<NpgsqlConnection, NpgsqlTransaction> action)
347442
{
348443
_commandQueue.Enqueue(action);

0 commit comments

Comments
 (0)