Created
August 2, 2016 23:07
-
-
Save timothypage/4197d78775f480af1ece2735ad228e33 to your computer and use it in GitHub Desktop.
Shitty Redis
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
require 'socket' | |
server = TCPServer.new 2000 | |
data = {} | |
loop do | |
client = server.accept | |
client.puts "Welcome to the key-value server" | |
loop do | |
command = client.gets.strip | |
method, key, value = command.split " " | |
puts method | |
if method == "PUT" | |
data[key] = value | |
client.puts "STORED" | |
elsif method == "GET" | |
client.puts data[key] | |
elsif method == "DELETE" | |
data.delete key | |
client.puts "DELETED" | |
else | |
client.puts "METHOD NOT SUPPORTED" | |
client.close | |
break | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment