@@ -113,6 +113,24 @@ export async function privateRefresh(privateKey){
113113 return redisData . expire ( dbKey , ttl ) ;
114114}
115115
116+ export async function privateStats ( privateKey ) {
117+ const publicKey = genPublicKey ( privateKey ) ;
118+ const dbKeyConsume = dbKeyPrefix . manyToOne + publicKey ;
119+ const dbKeyPublish = dbKeyPrefix . oneToMany + publicKey ;
120+ const countConsume = await redisData . llen ( dbKeyConsume ) ;
121+ const ttlConsume = await redisData . ttl ( dbKeyConsume ) ;
122+ const ttlPublish = await redisData . ttl ( dbKeyPublish ) ;
123+ return {
124+ consume : {
125+ count : countConsume ,
126+ ttl : ttlConsume < 0 ? 0 : ttlConsume
127+ } ,
128+ publish : {
129+ ttl : ttlPublish < 0 ? 0 : ttlPublish
130+ }
131+ } ;
132+ }
133+
116134export async function publicConsume ( publicKey ) {
117135 const dbKey = dbKeyPrefix . oneToMany + publicKey ;
118136 return redisData . get ( dbKey ) ;
@@ -132,14 +150,14 @@ export async function oneToOneConsume(publicKey, key){
132150 return redisData . hget ( dbKey , field ) . then ( redisData . hdel ( dbKey , field ) ) ;
133151}
134152
135- export async function oneToOneIsConsumed ( privateKey , key ) {
153+ export async function oneToOneTTL ( privateKey , key ) {
136154 const publicKey = genPublicKey ( privateKey ) ;
137155 const dbKey = dbKeyPrefix . oneToOne + publicKey ;
138156 const field = key ;
139157 const bool = await redisData . hexists ( dbKey , field ) ;
140158 if ( bool ) {
141- return "Not consumed yet." ;
159+ return { ttl : await redisData . ttl ( dbKey ) } ;
142160 } else {
143- return "Consumed." ;
161+ return { ttl : 0 } ;
144162 }
145163}
0 commit comments