@@ -55,83 +55,50 @@ public void disableScan() {
5555 }
5656
5757 public Future <BidsScanResult > submitBids (RedisBidsData bids ) {
58- final Promise <BidsScanResult > scanResult = Promise .promise ();
59-
6058 final RedisAPI readRedisNodeAPI = this .readRedisNode .getRedisAPI ();
61- final boolean shouldSubmit = !isScanDisabled
62- && readRedisNodeAPI != null && !bids .getBresps ().isEmpty ();
63-
64- if (shouldSubmit ) {
65- readRedisNodeAPI .get ("function_submit_bids" , submitHash -> {
66- final Object submitHashResult = submitHash .result ();
67- if (submitHashResult != null ) {
68- final List <String > readArgs = List .of (
69- submitHashResult .toString (),
70- "0" ,
71- toBidsAsJson (bids ),
72- apiKey ,
73- "true" );
74-
75- readRedisNodeAPI .evalsha (readArgs , response -> {
76- if (response .result () != null ) {
77- final BidsScanResult parserResult = redisParser
78- .parseBidsScanResult (response .result ().toString ());
79- final boolean isAnyRoSkipped = parserResult .getBidScanResults ()
80- .stream ().anyMatch (BidScanResult ::isRoSkipped );
81-
82- if (isAnyRoSkipped ) {
83- reSubmitBidsToWriteNode (readArgs , scanResult );
84- } else {
85- scanResult .complete (parserResult );
86- }
87- } else {
88- scanResult .complete (getEmptyScanResult ());
89- }
90- });
91- } else {
92- scanResult .complete (getEmptyScanResult ());
93- }
94- });
95-
96- return scanResult .future ();
59+ if (isScanDisabled || readRedisNodeAPI == null || bids .getBresps ().isEmpty ()) {
60+ return Future .succeededFuture (getEmptyScanResult ());
9761 }
9862
99- return Future .succeededFuture (getEmptyScanResult ());
63+ return readRedisNodeAPI .get ("function_submit_bids" )
64+ .map (Response ::toString )
65+ .map (response -> List .of (response , "0" , toBidsAsJson (bids ), apiKey , "true" ))
66+ .compose (args -> scanBids (args , readRedisNodeAPI ))
67+ .otherwise (ignored -> getEmptyScanResult ());
68+ }
69+
70+ private Future <BidsScanResult > scanBids (List <String > args , RedisAPI redisAPI ) {
71+ return redisAPI .evalsha (args )
72+ .map (Response ::toString )
73+ .map (redisParser ::parseBidsScanResult )
74+ .compose (parsedResult -> parsedResult .getBidScanResults ()
75+ .stream ().anyMatch (BidScanResult ::isRoSkipped )
76+ ? reSubmitBidsToWriteNode (args )
77+ : Future .succeededFuture (parsedResult ));
10078 }
10179
102- private void reSubmitBidsToWriteNode (List <String > readArgs , Promise < BidsScanResult > scanResult ) {
80+ private Future < BidsScanResult > reSubmitBidsToWriteNode (List <String > readArgs ) {
10381 final RedisAPI writeRedisAPI = this .writeRedisNode .getRedisAPI ();
104- if (writeRedisAPI != null ) {
105- final List <String > writeArgs = readArgs .stream ().limit (4 ).toList ();
106- writeRedisAPI .evalsha (writeArgs , response -> {
107- if (response .result () != null ) {
108- final BidsScanResult parserResult = redisParser
109- .parseBidsScanResult (response .result ().toString ());
110-
111- scanResult .complete (parserResult );
112- } else {
113- scanResult .complete (getEmptyScanResult ());
114- }
115- });
116- } else {
117- scanResult .complete (getEmptyScanResult ());
82+ if (writeRedisAPI == null ) {
83+ return Future .succeededFuture (getEmptyScanResult ());
11884 }
85+
86+ final List <String > writeArgs = readArgs .stream ().limit (4 ).toList ();
87+ return writeRedisAPI .evalsha (writeArgs )
88+ .map (Response ::toString )
89+ .map (redisParser ::parseBidsScanResult );
11990 }
12091
12192 public Future <Boolean > isScanDisabledFlag () {
12293 final RedisAPI redisAPI = this .readRedisNode .getRedisAPI ();
123- final Promise <Boolean > isDisabled = Promise .promise ();
124-
125- if (redisAPI != null ) {
126- redisAPI .get ("scan-disabled" , scanDisabledValue -> {
127- final Response scanDisabled = scanDisabledValue .result ();
128- isDisabled .complete (scanDisabled != null && "true" .equals (scanDisabled .toString ()));
129- });
130-
131- return isDisabled .future ();
94+ if (redisAPI == null ) {
95+ return Future .succeededFuture (true );
13296 }
13397
134- return Future .succeededFuture (true );
98+ return redisAPI .get ("scan-disabled" )
99+ .map (Response ::toString )
100+ .map (Boolean ::parseBoolean )
101+ .otherwise (false );
135102 }
136103
137104 private String toBidsAsJson (RedisBidsData bids ) {
0 commit comments