@@ -11,7 +11,26 @@ internal abstract class IncrexMessageBase(
1111 protected RedisKey Key => key ;
1212 protected Expiration Expiry => expiry ;
1313
14- protected int GetArgCount ( int coreArgs ) => 1 + coreArgs + Expiry . GetTokenCount ( allowEnx : true ) ;
14+ public override int ArgCount
15+ {
16+ get
17+ {
18+ return 3 + BoundsArgCount + Expiry . GetTokenCount ( allowEnx : true ) ; // key, BYINT/BYFLOAT, value, bounds, expiry
19+ }
20+ }
21+
22+ protected abstract int BoundsArgCount { get ; }
23+ protected abstract void WriteIncrementKindAndValue ( PhysicalConnection physical ) ;
24+ protected abstract void WriteBounds ( PhysicalConnection physical ) ;
25+
26+ protected override void WriteImpl ( PhysicalConnection physical )
27+ {
28+ physical . WriteHeader ( Command , ArgCount ) ;
29+ physical . WriteBulkString ( Key ) ;
30+ WriteIncrementKindAndValue ( physical ) ;
31+ WriteBounds ( physical ) ;
32+ Expiry . WriteTo ( physical ) ;
33+ }
1534 }
1635
1736 internal sealed class IncrexInt64Message (
@@ -23,23 +42,16 @@ internal sealed class IncrexInt64Message(
2342 long ? upperBound ,
2443 Expiration expiry ) : IncrexMessageBase ( database , flags , key , expiry )
2544 {
26- public override int ArgCount
27- {
28- get
29- {
30- int coreArgs = 2 ; // BYINT value
31- if ( lowerBound . HasValue ) coreArgs += 2 ;
32- if ( upperBound . HasValue ) coreArgs += 2 ;
33- return GetArgCount ( coreArgs ) ;
34- }
35- }
45+ protected override int BoundsArgCount => ( lowerBound . HasValue ? 2 : 0 ) + ( upperBound . HasValue ? 2 : 0 ) ;
3646
37- protected override void WriteImpl ( PhysicalConnection physical )
47+ protected override void WriteIncrementKindAndValue ( PhysicalConnection physical )
3848 {
39- physical . WriteHeader ( Command , ArgCount ) ;
40- physical . WriteBulkString ( Key ) ;
4149 physical . WriteBulkString ( "BYINT"u8 ) ;
4250 physical . WriteBulkString ( value ) ;
51+ }
52+
53+ protected override void WriteBounds ( PhysicalConnection physical )
54+ {
4355 if ( lowerBound . HasValue )
4456 {
4557 physical . WriteBulkString ( "LBOUND"u8 ) ;
@@ -50,7 +62,6 @@ protected override void WriteImpl(PhysicalConnection physical)
5062 physical . WriteBulkString ( "UBOUND"u8 ) ;
5163 physical . WriteBulkString ( upperBound . GetValueOrDefault ( ) ) ;
5264 }
53- Expiry . WriteTo ( physical ) ;
5465 }
5566 }
5667
@@ -63,23 +74,16 @@ internal sealed class IncrexDoubleMessage(
6374 double ? upperBound ,
6475 Expiration expiry ) : IncrexMessageBase ( database , flags , key , expiry )
6576 {
66- public override int ArgCount
67- {
68- get
69- {
70- int coreArgs = 2 ; // BYFLOAT value
71- if ( lowerBound . HasValue ) coreArgs += 2 ;
72- if ( upperBound . HasValue ) coreArgs += 2 ;
73- return GetArgCount ( coreArgs ) ;
74- }
75- }
77+ protected override int BoundsArgCount => ( lowerBound . HasValue ? 2 : 0 ) + ( upperBound . HasValue ? 2 : 0 ) ;
7678
77- protected override void WriteImpl ( PhysicalConnection physical )
79+ protected override void WriteIncrementKindAndValue ( PhysicalConnection physical )
7880 {
79- physical . WriteHeader ( Command , ArgCount ) ;
80- physical . WriteBulkString ( Key ) ;
8181 physical . WriteBulkString ( "BYFLOAT"u8 ) ;
8282 physical . WriteBulkString ( value ) ;
83+ }
84+
85+ protected override void WriteBounds ( PhysicalConnection physical )
86+ {
8387 if ( lowerBound . HasValue )
8488 {
8589 physical . WriteBulkString ( "LBOUND"u8 ) ;
@@ -90,7 +94,6 @@ protected override void WriteImpl(PhysicalConnection physical)
9094 physical . WriteBulkString ( "UBOUND"u8 ) ;
9195 physical . WriteBulkString ( upperBound . GetValueOrDefault ( ) ) ;
9296 }
93- Expiry . WriteTo ( physical ) ;
9497 }
9598 }
9699}
0 commit comments