Skip to content

Commit bfa5aa0

Browse files
committed
switch to out params
1 parent d29b19f commit bfa5aa0

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

src/StackExchange.Redis/RedisDatabase.cs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -486,20 +486,22 @@ public Task<RedisValue[]> HashFieldGetAndDeleteAsync(RedisKey key, RedisValue[]
486486
return ExecuteAsync(msg, ResultProcessor.RedisValueArray, defaultValue: Array.Empty<RedisValue>());
487487
}
488488

489-
private delegate (RedisValue Precision, RedisValue Duration) CalculateExpiryArgs<T>(T expiry);
489+
private delegate void CalculateExpiryArgs<T>(T expiry, out RedisValue precision, out RedisValue time);
490490

491-
private (RedisValue Precision, RedisValue Time) CalculateExpiryValues(TimeSpan expiry)
491+
private void CalculateExpiryValues(TimeSpan expiry, out RedisValue precision, out RedisValue time)
492492
{
493493
long milliseconds = expiry.Ticks / TimeSpan.TicksPerMillisecond;
494494
var useSeconds = milliseconds % 1000 == 0;
495-
return useSeconds ? (RedisLiterals.EX, milliseconds / 1000) : (RedisLiterals.PX, milliseconds);
495+
precision = useSeconds ? RedisLiterals.EX : RedisLiterals.PX;
496+
time = useSeconds ? (milliseconds / 1000) : milliseconds;
496497
}
497498

498-
private (RedisValue Precision, RedisValue Time) CalculateExpiryValues(DateTime expiry)
499+
private void CalculateExpiryValues(DateTime expiry, out RedisValue precision, out RedisValue time)
499500
{
500501
long milliseconds = GetMillisecondsUntil(expiry);
501502
var useSeconds = milliseconds % 1000 == 0;
502-
return useSeconds ? (RedisLiterals.EXAT, milliseconds / 1000) : (RedisLiterals.PXAT, milliseconds);
503+
precision = useSeconds ? RedisLiterals.EXAT : RedisLiterals.PXAT;
504+
time = useSeconds ? (milliseconds / 1000) : milliseconds;
503505
}
504506

505507
private Message HashFieldGetAndSetExpiryMessage<T>(RedisKey key, RedisValue hashField, T? expiry, CalculateExpiryArgs<T> calculateExpiryArgs, bool persist, CommandFlags flags) where T : struct
@@ -513,8 +515,8 @@ private Message HashFieldGetAndSetExpiryMessage<T>(RedisKey key, RedisValue hash
513515
case (_, true): // Case when persist is true (expiry is disregarded)
514516
return Message.Create(Database, flags, RedisCommand.HGETEX, key, RedisLiterals.PERSIST, RedisLiterals.FIELDS, 1, hashField);
515517
case (not null, _): // Case when expiry is not null
516-
var (precision, duration) = calculateExpiryArgs((T)expiry!);
517-
return Message.Create(Database, flags, RedisCommand.HGETEX, key, precision, duration, RedisLiterals.FIELDS, 1, hashField);
518+
calculateExpiryArgs((T)expiry!, out RedisValue precision, out RedisValue time);
519+
return Message.Create(Database, flags, RedisCommand.HGETEX, key, precision, time, RedisLiterals.FIELDS, 1, hashField);
518520
default: // Default case when both expiry and persist are default
519521
return Message.Create(Database, flags, RedisCommand.HGETEX, RedisLiterals.FIELDS, 1, hashField);
520522
}
@@ -533,8 +535,8 @@ private Message HashFieldGetAndSetExpiryMessage<T>(RedisKey key, RedisValue[] ha
533535
values = new List<RedisValue> { RedisLiterals.PERSIST, RedisLiterals.FIELDS, hashFields.Length };
534536
break;
535537
case (not null, _): // Case when expiry is not null
536-
var (precision, duration) = calculateExpiryArgs((T)expiry!);
537-
values = new List<RedisValue> { precision, duration, RedisLiterals.FIELDS, hashFields.Length };
538+
calculateExpiryArgs((T)expiry!, out RedisValue precision, out RedisValue time);
539+
values = new List<RedisValue> { precision, time, RedisLiterals.FIELDS, hashFields.Length };
538540
break;
539541
default: // Default case when both expiry and persist are default
540542
values = new List<RedisValue> { RedisLiterals.FIELDS, hashFields.Length };
@@ -636,8 +638,8 @@ private Message HashFieldSetAndSetExpiryMessage<T>(RedisKey key, RedisValue hash
636638
return Message.Create(Database, flags, RedisCommand.HSETEX, key, RedisLiterals.KEEPTTL, RedisLiterals.FIELDS, 1, hashField);
637639
case (When.Always, not null, _): // Case when expiry is not null
638640
{
639-
var (precision, duration) = calculateExpiryArgs((T)expiry!);
640-
return Message.Create(Database, flags, RedisCommand.HSETEX, key, precision, duration, RedisLiterals.FIELDS, 1, hashField);
641+
calculateExpiryArgs((T)expiry!, out RedisValue precision, out RedisValue time);
642+
return Message.Create(Database, flags, RedisCommand.HSETEX, key, precision, time, RedisLiterals.FIELDS, 1, hashField);
641643
}
642644
case (When.Always, _, _): // Default case when both expiry and keepTtl are default
643645
return Message.Create(Database, flags, RedisCommand.HSETEX, RedisLiterals.FIELDS, 1, hashField);
@@ -651,9 +653,9 @@ private Message HashFieldSetAndSetExpiryMessage<T>(RedisKey key, RedisValue hash
651653
case (When.Exists, not null, _): // Case when expiry is not null
652654
case (When.NotExists, not null, _):
653655
{
654-
var (precision, duration) = calculateExpiryArgs((T)expiry!);
656+
calculateExpiryArgs((T)expiry!, out RedisValue precision, out RedisValue time);
655657
var existance = when == When.Exists ? RedisLiterals.FXX : RedisLiterals.FNX;
656-
return Message.Create(Database, flags, RedisCommand.HSETEX, key, existance, precision, duration, RedisLiterals.FIELDS, 1, hashField);
658+
return Message.Create(Database, flags, RedisCommand.HSETEX, key, existance, precision, time, RedisLiterals.FIELDS, 1, hashField);
657659
}
658660
default: // Only existance is specified
659661
{
@@ -677,8 +679,8 @@ private Message HashFieldSetAndSetExpiryMessage<T>(RedisKey key, RedisValue[] ha
677679
break;
678680
case (When.Always, not null, _): // Case when expiry is not null
679681
{
680-
var (precision, duration) = calculateExpiryArgs((T)expiry!);
681-
values = new List<RedisValue> { precision, duration, RedisLiterals.FIELDS, hashFields.Length };
682+
calculateExpiryArgs((T)expiry!, out RedisValue precision, out RedisValue time);
683+
values = new List<RedisValue> { precision, time, RedisLiterals.FIELDS, hashFields.Length };
682684
}
683685
break;
684686
case (When.Always, _, _): // Default case when both expiry and keepTtl are default
@@ -694,9 +696,9 @@ private Message HashFieldSetAndSetExpiryMessage<T>(RedisKey key, RedisValue[] ha
694696
case (When.Exists, not null, _): // Case when expiry is not null
695697
case (When.NotExists, not null, _):
696698
{
697-
var (precision, duration) = calculateExpiryArgs((T)expiry!);
699+
calculateExpiryArgs((T)expiry!, out RedisValue precision, out RedisValue time);
698700
var existance = when == When.Exists ? RedisLiterals.FXX : RedisLiterals.FNX;
699-
values = new List<RedisValue> { existance, precision, duration, RedisLiterals.FIELDS, hashFields.Length };
701+
values = new List<RedisValue> { existance, precision, time, RedisLiterals.FIELDS, hashFields.Length };
700702
}
701703
break;
702704
default: // Only existance is specified

0 commit comments

Comments
 (0)