从 mnesia 获取所有记录 table

Get all records from mnesia table

我正在使用 mnesia 为连接到某个 websocket 的用户存储 Pid。

-record(connection, {pid, name}).

handle_join(ServiceName, WebSocketId, State, EventName) ->
  mnesia:dirty_write(#connection{pid=WebSocketId, name=EventName}).

Pid 是关键,使用 tv:start() 应用程序我能够看到 Pid 被正确存储在连接 table 中。我现在希望能够向 table 中的所有 Pid 发送消息,并在 websocket 连接关闭时删除 Pid。

从该连接检索所有 Pid 的最佳方法是什么 table?

您可以使用 all_keys(Tab) -> KeyList | transaction abortdirty_all_keys(Tab) -> KeyList | exit({aborted, Reason}).

all_keys(Tab) -> KeyList | transaction abort

This function returns a list of all keys in the table named Tab. The semantics of this function is context sensitive. See mnesia:activity/4 for more information. In transaction context it acquires a read lock on the entire table.