-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from peillis/socket
Socket lib
- Loading branch information
Showing
11 changed files
with
90 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
language: elixir | ||
|
||
elixir: | ||
- 1.5.1 | ||
|
||
otp_release: | ||
- 20.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
use Mix.Config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
use Mix.Config | ||
|
||
config :elasticachex, | ||
socket_module: Elasticachex.SocketTest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
defmodule Elasticachex.Socket do | ||
@doc """ | ||
Connects to the service | ||
""" | ||
def connect(host, port, timeout) do | ||
Socket.TCP.connect(host, port, timeout: timeout) | ||
end | ||
|
||
@doc """ | ||
Sends a command to the socket connection and returns the response. | ||
## Example | ||
iex> send_and_recv(socket, "version\n", 5000) | ||
{:ok, VERSION 1.4.34\r\n"} | ||
""" | ||
def send_and_recv(socket, command, timeout) do | ||
socket |> Socket.Stream.send!(command) | ||
socket |> Socket.Stream.recv(timeout: timeout) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
%{"earmark": {:hex, :earmark, "1.2.0", "bf1ce17aea43ab62f6943b97bd6e3dc032ce45d4f787504e3adf738e54b42f3a", [:mix], []}, | ||
"ex_doc": {:hex, :ex_doc, "0.15.1", "d5f9d588fd802152516fccfdb96d6073753f77314fcfee892b15b6724ca0d596", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, optional: false]}]}} | ||
%{"earmark": {:hex, :earmark, "1.2.0", "bf1ce17aea43ab62f6943b97bd6e3dc032ce45d4f787504e3adf738e54b42f3a", [:mix], [], "hexpm"}, | ||
"ex_doc": {:hex, :ex_doc, "0.15.1", "d5f9d588fd802152516fccfdb96d6073753f77314fcfee892b15b6724ca0d596", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, | ||
"socket": {:hex, :socket, "0.3.12", "4a6543815136503fee67eff0932da1742fad83f84c49130c854114153cc549a6", [], [], "hexpm"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
defmodule Elasticachex.SocketTest do | ||
|
||
def connect("version>1.4.14", _port, _timeout) do | ||
{:ok, :socket_1} | ||
end | ||
def connect("version<1.4.14", _port, _timeout) do | ||
{:ok, :socket_2} | ||
end | ||
|
||
def send_and_recv(:socket_1, command, _timeout) do | ||
case command do | ||
"version\n" -> {:ok, "VERSION 1.4.14\r\n"} | ||
"config get cluster\n" -> {:ok, "CONFIG cluster 0 74\r\n1\nmemcached-cluster.xlttkm.0001.euw1.cache.amazonaws.com|10.0.9.238|11211\n\r\nEND\r\n"} | ||
end | ||
end | ||
def send_and_recv(:socket_2, command, _timeout) do | ||
case command do | ||
"version\n" -> {:ok, "VERSION 1.4.13\r\n"} | ||
"get AmazonElastiCache:cluster\n" -> {:ok, "CONFIG cluster 0 74\r\n1\nmemcached-cluster.xlttkm.0001.euw1.cache.amazonaws.com|10.0.9.238|11211\n\r\nEND\r\n"} | ||
end | ||
end | ||
|
||
end |