Permalink
Browse files

update the readme

  • Loading branch information...
1 parent a46a60a commit 134a1d658f9cc996ffe6b217c2b4f1013946fbb5 @dialtone dialtone committed Jan 20, 2012
Showing with 28 additions and 12 deletions.
  1. +28 −12 README.md
View
@@ -6,15 +6,14 @@ Here's how you use this thing without using any macro help:
dinerl:put_item(<<"TestTable">>, [{<<"Key">>, [{<<"S">>, <<"jello">>}]}], []).
dinerl:get_item(<<"TestTable">>, [{<<"HashKeyElement">>, [{<<"S">>, <<"jello">>}]}], []).
-
put(Key, Value, TTL, Now) ->
dinerl:put_item(<<"Attributions">>, [{<<"UserKey">>, [{<<"S">>, Key}]},
{<<"Updated">>, [{<<"N">>, list_to_binary(integer_to_list(Now))}]},
{<<"TTL">>, [{<<"N">>, list_to_binary(integer_to_list(TTL))}]},
{<<"Value">>, [{<<"S">>, Value}]}], []).
get(Key, Now, Default) ->
- case dinerl:get_item(<<"Attributions">>, [{<<"HashKeyElement">>, [{<<"S">>, Key}]}], [{attrs, [<<"TTL">>, <<"Updated">>, <<"Value">>]}]) of
+ case dinerl:get_item(<<"Attributions">>, [{<<"HashKeyElement">>, [{<<"S">>, Key}]}], [{attrs, [<<"TTL">>, <<"Updated">>, <<"Value">>, <<"Visited">>]}]) of
{ok, Element} ->
ParsedResult = parsejson(Element),
return_if_not_expired(Key, ParsedResult, Now, Default);
@@ -24,16 +23,26 @@ Here's how you use this thing without using any macro help:
Default
end.
+ add(Key, Value, TTL, Now) ->
+ dinerl:update_item(<<"Attributions">>,
+ [{<<"HashKeyElement">>, [{<<"S">>, Key}]}],
+ [{update, [{<<"Visited">>, [{value, [{<<"SS">>, [Value]}]},
+ {action, add}]},
+ {<<"Updated">>, [{value, [{<<"N">>, list_to_binary(integer_to_list(Now))}]},
+ {action, put}]},
+ {<<"TTL">>, [{value, [{<<"N">>, list_to_binary(integer_to_list(TTL))}]},
+ {action, put}]}]}]).
- parsejson({struct, L}) ->
- parsejson(L, []).
- parsejson([], Acc) ->
- Acc;
- parsejson([{<<"Item">>, {struct, Fields}}|Rest], Acc) ->
- parsejsonfields(Fields, Acc);
- parsejson([H|T], Acc) ->
- parsejson(T, Acc).
+
+ parsejson([]) ->
+ [];
+ parsejson({struct, L}) ->
+ parsejson(L);
+ parsejson([{<<"Item">>, {struct, Fields}}|_Rest]) ->
+ parsejsonfields(Fields, []);
+ parsejson([_H|T]) ->
+ parsejson(T).
parsejsonfields([], Acc) ->
Acc;
@@ -42,9 +51,9 @@ Here's how you use this thing without using any macro help:
parsejsonfields([{Name, {struct, [{<<"S">>, Value}]}}|Rest], Acc) ->
parsejsonfields(Rest, [{Name, Value}|Acc]);
parsejsonfields([{Name, {struct, [{<<"NS">>, Value}]}}|Rest], Acc) ->
- parsejsonfields(Rest, Acc);
+ parsejsonfields(Rest, [{Name, all_to_int(Value)}|Acc]);
parsejsonfields([{Name, {struct, [{<<"SS">>, Value}]}}|Rest], Acc) ->
- parsejsonfields(Rest, Acc).
+ parsejsonfields(Rest, [{Name, Value}|Acc]).
return_if_not_expired(_, [], _, Default) ->
@@ -60,6 +69,13 @@ Here's how you use this thing without using any macro help:
Default
end.
+ all_to_int(L) ->
+ all_to_int(L, []).
+ all_to_int([], Acc) ->
+ lists:reverse(Acc);
+ all_to_int([H|T], Acc) ->
+ all_to_int(T, [list_to_integer(binary_to_list(H))|Acc]).
+
pytime() ->
pytime(erlang:now()).
pytime({MegaSecs, Secs, MicroSecs}) ->

0 comments on commit 134a1d6

Please sign in to comment.