Last active
August 29, 2015 14:01
-
-
Save benjamintanweihao/9cc843b5e32963008007 to your computer and use it in GitHub Desktop.
DiCE Ruby Client.
This file contains hidden or 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
| #!/usr/bin/env ruby | |
| require 'json' | |
| require 'socket' | |
| class DiceClient | |
| def initialize(host, port) | |
| @host = host | |
| @port = port | |
| puts "Connecting to server..." | |
| end | |
| def put(key, value) | |
| op({"op" => "put", "key" => key, "value" => value}) | |
| end | |
| def get(key) | |
| op({"op" => "get", "key" => key}) | |
| end | |
| def remove(key) | |
| op({"op" => "remove", "key" => key}) | |
| end | |
| def op(data) | |
| @socket = TCPSocket.new(@host, @port) | |
| @socket.write(JSON.generate(data)) | |
| @socket.read.to_json | |
| end | |
| end | |
| client = DiceClient.new('localhost', 1155) | |
| puts "=== PUT" | |
| puts client.put("elixir", "awesome sauce") | |
| puts client.put("php", "lolwut") | |
| puts "=== GET" | |
| puts client.get("elixir") | |
| puts client.get("php") | |
| puts "=== REMOVE" | |
| puts client.remove("elixir") | |
| puts "=== PUT" | |
| puts client.put("elixir", "really awesome sauce") | |
| puts "=== GET" | |
| puts client.get("elixir") | |
| puts client.get("php") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment