jwsinner

jwsinner

Can I get some clarification on why Registry is written the way it is?

From what I can gather, Registry is a way to localize keys to make using OTP stuff a bit easier. This is especially important when you want to use a binary key for a GenServer or Agent instead of an atom or setting it to {:global, key}.

That said, and I’m chalking this up to my own ignorance, it seems to be HIGHLY unintuitive to use. In my mind Registry is basically a supervised key/value store (like a map, but backed by an ets table) where the key responds to a {pid, init_value} tuple (or list of tuples if :duplicate is used). So when we have a function called keys, it makes sense that I’m looking for the keys within that Registry, especially since Registry.count/1 takes in the name of the Registry and returns the number of keys… Instead, we’re expected to also pass along the pid, to get the key(s) associated with it? If I’m using Registry as a way to make GenServer or Agent easier to use (not having to know the pid to pass along), why do I need to know the pid to pass along?

Similarly, Registry.values requires the registry name, a pid, AND the key? Does Map.values/1 require anything other than the map?

I understand there needs to be a difference in usages based on :unique vs :duplicate, but that seems like it could be solved via pattern matching. I like the idea of Registry, but it seems VERY clunky to use for what it’s trying to do. Am I just super ignorant of the underlying mechanisms? If so, I’d love some clarification so I can better understand where I’m falling short.

Most Liked

josevalim

josevalim

Creator of Elixir

It is a key-value process storage. So you can think of it having three dimensions (key, value, pid), instead of two, and, it also allows duplicate keys with a single process. The process bit is crucial, it is not simply a key-value storage. :slight_smile: If that’s your goal, :ets tables are most likely a better choice.

LostKobrakai

LostKobrakai

I think the part you’re missing here is that it’s generally expected that both ends – registered processes and processes interested in registered processes – know what keys they’re interested in. That would be the very same as with other registries – local atom names or :global.

Registry.keys and Registry.values are not meant as general tools to finding all keys or all values that are currently registered – besides the fact that this could potentially be quite an expensive operation. They’re much rather helpers for figuring out how a process in question is related in the registry, but you generally wouldn’t used them to interact with registered processes.

Registry.lookup, Registry.match, Registry.select are the APIs you’re expected to use to query the registry (in order of complexity).

entone

entone

I think one other use case that you are missing is the ability to use multiple Registries, which would require knowing the registered name or pid of that individual Registry. So the design of Registry is specifically to allow multiple Registries.

Where Next?

Popular in Discussions Top

pillaiindu
In django there is a cache framework backed by memcached. Rails also puts a lot of emphasis on caching, and even the idea of russian-doll...
New
ricklove
I was just introduced to Elixir and Phoenix. I was told about the 2 million websocket test that was done 2 years ago. From my research, t...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39297 209
New
IVR
Hi all, I’ve seen a number of related threads in the past, but I’d still be very curious to hear an up-to-date opinion on this topic. I...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
PragTob
Hey everyone, this has been on my mind for some time and I’d love your input on it! TLDR: I feel like maps are superioer for storing and...
New
AstonJ
I’ve just started the Phoenix part of the utterly brilliant online course by @pragdave. On generating the Phoenix app he uses the --no-ec...
New
chulkilee
Here are the list of HTTP client libraries/wrappers, and some thoughts on HTTP client in general. I’d like to hear from others how they w...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New

Other popular topics Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36128 110
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New

We're in Beta

About us Mission Statement