File tree Expand file tree Collapse file tree
src/main/java/tech/smartboot/redisun Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55import java .util .concurrent .CompletableFuture ;
66import java .util .concurrent .ConcurrentLinkedQueue ;
7- import java .util .concurrent .atomic .AtomicInteger ;
87
98/**
109 * Redis会话管理类
@@ -35,7 +34,8 @@ final class RedisSession {
3534 */
3635 private RESP decodingResponse ;
3736
38- private final AtomicInteger load = new AtomicInteger ();
37+ private int offerCount = 0 ;
38+ private int pollCount = 0 ;
3939
4040 /**
4141 * 感知变化量,无需保障原子性
@@ -69,17 +69,19 @@ void setDecodingResponse(RESP decodingResponse) {
6969 }
7070
7171 public CompletableFuture <RESP > poll () {
72- load . decrementAndGet () ;
72+ pollCount ++ ;
7373 return pipeline .poll ();
7474 }
7575
7676 public void offer (CompletableFuture <RESP > future ) {
77- load . incrementAndGet () ;
77+ offerCount ++ ;
7878 pipeline .offer (future );
7979 }
8080
8181 int load () {
82- return load .get ();
82+ int size = offerCount - pollCount ;
83+ // System.out.println("load: " + size);
84+ return size >= 0 ? size : -size ;
8385 }
8486
8587}
You can’t perform that action at this time.
0 commit comments