Skip to content

Instantly share code, notes, and snippets.

@timothypage
Created August 2, 2016 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timothypage/4197d78775f480af1ece2735ad228e33 to your computer and use it in GitHub Desktop.
Save timothypage/4197d78775f480af1ece2735ad228e33 to your computer and use it in GitHub Desktop.
Shitty Redis
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