Skip to content

Instantly share code, notes, and snippets.

@argv0
Created March 9, 2010 18:54
Show Gist options
  • Save argv0/326942 to your computer and use it in GitHub Desktop.
Save argv0/326942 to your computer and use it in GitHub Desktop.
-module(session_deref).
-compile(export_all).
run() ->
{ok, FP} = file:open("/tmp/session_mapping.txt", [write]),
{ok, R} = riak_ring_manager:get_my_ring(),
VNodes = riak_ring:my_indices(R),
fold_vnodes(VNodes, FP).
fold_vnodes([], FP) ->
file:close(FP);
fold_vnodes([VNode|T], FP) ->
gen_server2:call(riak_vnode_master,
{fold, {VNode, fun folder/3, {FP, 0}}},
infinity),
fold_vnodes(T, FP).
folder({<<"session">>,K}, V, {FP, Count}) ->
Obj = binary_to_term(V),
Data = hd(riak_object:get_values(Obj)),
{struct, JSON} = mochijson2:decode(Data),
UserName = proplists:get_value(<<"username">>, JSON),
file:write(FP, [UserName, "\n"]),
{FP, Count};
folder({_,_K}, _V, {FP, Count}) ->
{FP, Count}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment