@@ -511,8 +511,9 @@ defmodule Registry do
511511 :error
512512 end
513513
514- { kind , _ , _ , _ } ->
515- raise ArgumentError , "Registry.update_value/3 is not supported for #{ kind } registries"
514+ { kind , _ , _ } ->
515+ raise ArgumentError ,
516+ "Registry.update_value/3 is not supported for #{ inspect ( kind ) } registries"
516517 end
517518 end
518519
@@ -843,16 +844,35 @@ defmodule Registry do
843844 @ spec keys ( registry , pid ) :: [ key ]
844845 def keys ( registry , pid ) when is_atom ( registry ) and is_pid ( pid ) do
845846 { kind , partitions , _ , pid_ets , _ } = info! ( registry )
846- { _ , pid_ets } = pid_ets || pid_ets! ( registry , pid , partitions )
847847
848- keys =
849- try do
850- spec = [ { { pid , :"$1" , :"$2" , :_ } , [ ] , [ { { :"$1" , :"$2" } } ] } ]
851- :ets . select ( pid_ets , spec )
852- catch
853- :error , :badarg -> [ ]
848+ pid_etses =
849+ if pid_ets do
850+ { _ , pid_ets } = pid_ets
851+ [ pid_ets ]
852+ else
853+ case kind do
854+ { :duplicate , :key } ->
855+ for partition <- 0 .. ( partitions - 1 ) do
856+ { _ , pid_ets } = pid_ets! ( registry , partition )
857+ pid_ets
858+ end
859+
860+ _ ->
861+ { _ , pid_ets } = pid_ets! ( registry , pid , partitions )
862+ [ pid_ets ]
863+ end
854864 end
855865
866+ keys =
867+ Enum . flat_map ( pid_etses , fn pid_ets ->
868+ try do
869+ spec = [ { { pid , :"$1" , :"$2" , :_ } , [ ] , [ { { :"$1" , :"$2" } } ] } ]
870+ :ets . select ( pid_ets , spec )
871+ catch
872+ :error , :badarg -> [ ]
873+ end
874+ end )
875+
856876 # Handle the possibility of fake keys
857877 keys = gather_keys ( keys , [ ] , false )
858878
0 commit comments