Explorar el Código

Add function 'get_counters/1'

Feng Lee hace 6 años
padre
commit
609f442ea9
Se han modificado 1 ficheros con 11 adiciones y 5 borrados
  1. 11 5
      src/emqx_pd.erl

+ 11 - 5
src/emqx_pd.erl

@@ -19,27 +19,33 @@
 
 -include("types.hrl").
 
--export([ update_counter/2
+-export([ get_counters/1
         , get_counter/1
+        , update_counter/2
         , reset_counter/1
         ]).
 
 -compile({inline,
-          [ update_counter/2
+          [ get_counters/1
           , get_counter/1
+          , update_counter/2
           , reset_counter/1
           ]}).
 
 -type(key() :: term()).
 
--spec(update_counter(key(), number()) -> maybe(number())).
-update_counter(Key, Inc) ->
-    put(Key, get_counter(Key) + Inc).
+-spec(get_counters(list(key())) -> list({key(), number()})).
+get_counters(Keys) when is_list(Keys) ->
+    [{Key, emqx_pd:get_counter(Key)} || Key <- Keys].
 
 -spec(get_counter(key()) -> number()).
 get_counter(Key) ->
     case get(Key) of undefined -> 0; Cnt -> Cnt end.
 
+-spec(update_counter(key(), number()) -> maybe(number())).
+update_counter(Key, Inc) ->
+    put(Key, get_counter(Key) + Inc).
+
 -spec(reset_counter(key()) -> number()).
 reset_counter(Key) ->
     case put(Key, 0) of undefined -> 0; Cnt -> Cnt end.