How do I design the path to get the following data #201
-
Uid1 = 1, Uid2 = 2, DType1 = <<"ios">>, DType2 = <<"andriod">>.
DID1 = <<"did1">>, DID2 = <<"did2">>.
Pid1 = self(). Pid2 = self().
Uid1Bin = integer_to_binary(Uid1).
Path1 = <<"/:s/", Uid1Bin/binary, "/", DType1/binary>>.
khepri:put(Path1, {Uid1, DType1, Pid1, DID1}).
Path2 = <<"/:s/", Uid1Bin/binary, "/", DType2/binary>>.
khepri:put(Path2, {Uid1, DType2, Pid2, DID2}).
(imboy@127.0.0.1)171> khepri:get(Path1).
{ok,{1,<<"ios">>,<0.11996.0>,<<"did11">>}}
(imboy@127.0.0.1)172> khepri:get(Path2).
{ok,{1,<<"andriod">>,<0.11820.1>,<<"did2">>}} How do I design the path to get the following data: khepri:get({s, Uid})
{ok, [
{1,<<"ios">>,<0.11996.0>,<<"did11">>},
{1,<<"andriod">>,<0.11820.1>,<<"did2">>}
]}
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
You can lookup many paths in the store using > khepri:get_many("/:s/1/*").
{ok,#{[s,<<"1">>,<<"andriod">>] =>
{1,<<"andriod">>,<0.249.0>,<<"did2">>},
[s,<<"1">>,<<"ios">>] =>
{1,<<"ios">>,<0.249.0>,<<"did1">>}}}
> khepri:get_many("/:s/**").
{ok,#{[s,<<"1">>,<<"andriod">>] =>
{1,<<"andriod">>,<0.249.0>,<<"did2">>},
[s,<<"1">>,<<"ios">>] =>
{1,<<"ios">>,<0.249.0>,<<"did1">>}}}
|
Beta Was this translation helpful? Give feedback.
-
In the example data above, there are two Uids and two device ids (did). May I ask, how to write the method to count the total number of user ids and the number of device ids? The way I know how to do this is to query all the data and then iterate through the list, but that's obviously not efficient (it's a problem if you have a million users online at the same time).以上翻译结果来自有道神经网络翻译(YNMT)· 通用场景 在上面的示例数据中,有两个uid,两个设备ID(did)。 请问,统计用户ID总数量,统计设备ID中数量的 方法如何编写? 我知道的方法是把所有数据查询出来在遍历列表,但是这样显然效率不高(有一百万用户同时在线就麻烦了) |
Beta Was this translation helpful? Give feedback.
-
It would be even better if khepri could retain mnesia's syntax, or support SQL syntax! 如果 khepri 能够保留 mnesia 的语法,或者支持SQL语法,那就更完美了! |
Beta Was this translation helpful? Give feedback.
You can lookup many paths in the store using
khepri:get_many/3
with path patterns:*
matches any tree node and**
matches any path in the tree node. Also see the docs forkhepri:get_many/3
andkhepri_path:unix_pattern()
in the documentation (https://rabbitmq.github.io/khepri/).