The is a command-line utility that allows you to interact with a simple in-memory key-value database through a TCP server.
You must have Go(1.18) installed on your machine. Follow the steps below to install and set up the tool:
-
Clone the repository.
-
Run the following command in the project directory to build the CLI tool:
go build -o db
This will create an executable file named
dbin the project directory.
To start the TCP server, follow these steps:
-
Create a
.envfile in the root directory and set the required values to the below environment variables. We have provided a.env.examplefile in the root directory for reference.-
Ensure the environment variable
TCP_PORTis set to the desired port number on which the TCP server should listen. For example, you can set it to8003by running:export APP_PORT=8003 -
Set the environment variable to set the number of in-memory databases (
DB_COUNT). For example:export DB_COUNT=16
-
-
Run the following command to start the TCP server:
./db
-
The TCP server will start and display a message indicating it running.
-
Open another terminal and use a tool like
ncortelnetto connect to the TCP server. For example:nc localhost 8003
-
Once connected, you can interact with the CLI tool by entering commands. A
>symbol denotes the command prompt. -
The available commands are case-insensitive and can be entered in the following format:
COMMAND [argument1] [argument2] ...Replace
COMMANDwith a supported command and provide the necessary arguments. -
The CLI tool supports the following commands:
SET key value: Sets the value of the specified key in the current database.GET key: Retrieves the value of the specified key from the current database.DEL key: Deletes the specified key from the current database.INCR key: Increments the value of the specified key by 1.INCRBY key increment: Increments the value of the specified key by the specified increment.MULTI: Starts a transaction block.EXEC: Executes all commands in a transaction block.DISCARD: Discards all commands in a transaction block.COMPACT: Compacts the database by removing expired keys.SELECTindex: Switches to the specified database index (0-based).DISCONNECTdisconnect the connected client from the TCP server.
Replace key, value, index, and increment with the appropriate values.
-
After entering a command, the CLI tool will display the command result.
-
To exit the CLI tool, close the
ncconnection or terminate the terminal session or use theDISCONNECTcommand.
- The
ui.getDbIndex(result any)function may return a wrong database index (i.e zero)result any = []domain.DBResultand that slice is empty.
- Fix ISSUE #1
- Add fast persistent storage, not just in-memory.
This project is licensed under the MIT License