edis_proto

Allow erlang/BEAM applications to expose a Redis compatible protocol


License
Apache-2.0

Documentation

edis_proto

A Library extracted from edis to allow applications exposing a Redis compatible protocol.

Usage

In your supervisor add this two

  ListenerOpts = #{min_port => MinPort, max_port => MaxPort},
  ListenerSup = {edis_listener_sup, {edis_listener_sup, start_link, [ListenerOpts]},
                 permanent, 1000, supervisor, [edis_listener_sup]},
  ClientOpts = #{command_runner_mod => my_command_runner},
  ClientSup = {edis_client_sup, {edis_client_sup, start_link, [ClientOpts]},
               permanent, 1000, supervisor, [edis_client_sup]},

  {ok, {{one_for_one, 5, 10}, [..., ListenerSup, ClientSup]}}.

where my_command_runner is a module that exports run_command/2:

run_command(Command, Args) ->
    do_stuff_here.

Where Command is a binary with the command name in uppercase and args is a list of binaries with the arguments.

The result from run_command can be:

{ok, _} ->
    replies OK to client

{ok, _, nil} ->
    replies nil to client

{ok, _, Value} ->
    replies Value to client (Value can be integer, string)

no_reply ->
    doesn't send a reply to the client

{error, _, {ErrorCode, ErrorReason, ErrorDetails}} ->
    replies an error with Reason as text to client

License

Apache Public License 2.0