Toy Redis in Kotlin in 120 lines
java -jar kredis-1.0.0.jar [PORT]
examples:
java -jar kredis-1.0.0.jar
java -jar kredis-1.0.0.jar 3000
nc [HOST] [PORT]
example
nc localhost 3000
java -cp kredis-1.0.0.jar main.SocketClient [HOST] [PORT]
examples
java -cp kredis-1.0.0.jar main.SocketClient
java -cp kredis-1.0.0.jar main.SocketClient 127.0.0.1
java -cp kredis-1.0.0.jar main.SocketClient localhost 3000
node client.js [HOST] [PORT]
examples
node client.js
node client.js 127.0.0.1
node client.js localhost 3000
kredis keeps it simple with just a handful of commands. Here’s the full list:
Stores a value under a key.
Keys must not contain spaces.
Example:
set hello world
Response: OK
Retrieves the value stored under a key.
Example:
get hello
Response: world
Deletes a key and its value.
Example:
del hello
Response: OK
Increments the numeric value of a key by the specified [value]. If the [value] is not provided, it defaults to 1. If the key doesn’t exist, it starts at 0.
Examples:
Increment by 1 (default):
incr counter
Response: 1
Increment by a specific value:
incr score 10
Response: 10
Decrements the numeric value of a key by the specified [value]. If the [value] is not provided, it defaults to 1. If the key doesn’t exist, it starts at 0.
Examples:
Decrement by 1 (default):
decr counter
Response: -1
Decrement by a specific value:
decr score 2
Response: 8
Closes the session and disconnects from HippieDB. Use this when you’re done sharing the vibes.
Example:
stop
Response: (connection closes)
Refactored from this based on this blog post https://blog.pjam.me/posts/toy-redis-go/