Infleare Cli

Infleare CLI Documentation

Overview

Infleare CLI is a command-line client designed for communicating with an Infleare in-memory server. It allows users to send commands, authenticate, and receive responses in a structured format.

Check infleare-cli is installed currently :

infleare --version

Response:

Version: Infleare version v1.0.0
Platform: linux/amd64

Command-Line Arguments

Authenticate

The CLI accepts the following command-line arguments:

Flag Description Default
-host Server host address 127.0.0.1
-port Server port 4775
-u Username for authentication Required
-p Password for authentication Required

Example usage:

infleare-cli -host 192.168.0.1 -port 4775 -u admin -p <secret>

Features

  • Authentication: Users must authenticate with a username and password.
  • Command Execution: Send commands to the server with parameters.
  • Response Parsing: Parses JSON responses from the server.
  • Command History: Stores command history in ~/.infleare_history.
  • Graceful Exit: Handles CTRL+C to prompt for an exit command.

Authentication

Once the CLI establishes a TCP connection with the server, it sends the username and password for authentication. If the authentication succeeds, the server responds with CONNECTED.

Command Reference

SET Command

The SET command stores a key-value pair in the database. It supports various data types such as strings, numbers, and JSON objects.

Usage Examples

Set a String

Stores a string value in the database with the specified key.

192.168.0.1:4775> SET -k "key:0100" -d "Hello.. This is a string"

Set a Number

Stores a numerical value under the given key.

192.168.0.1:4775> SET -k "number:0001" -d 102.44

Set a JSON Object

Stores a simple JSON object in the database.

192.168.0.1:4775> SET -k "user:0001" -d '{"name":"Alice"}'

Set a Complex JSON Object

Stores a detailed JSON object with nested values.

192.168.0.1:4775> SET -k "user:0002" -d '{"name":"Parash Maity","role":1001,"location": {"city":"Kolkata", "state":"West Bengal","pincode": "700102"}}'

SET Response

After successfully storing the data, the server returns the following response:

"DONE"

KEYS

Retrieves all keys

192.168.0.1:4775> KEYS

Return all keys within an array

[ "user:0001", "user:002", "key:0100", "workspace:01"]

GET

Example 1 > Object

Retrieves the value associated with a specified key.

192.168.0.1:4775> GET -k "user:0001"

Return object value associated with a specified key.

{
    "name": "Alice"
}

Example 2 > Complex JSON

Retrieves Complex JSON value associated with a specified key.

192.168.0.1:4775> GET -k "user:0002"

Return object value associated with a specified key.

{
    "location": {
        "city": "Kolkata",
        "pincode": "700102",
        "state": "West Bengal"
    },
    "name": "Parash Maity",
    "role": 1001
}

UPDATE

Add a key into json object

192.168.0.1:4775> UPDATE -k "user:0001" -p "skills" -d '["Node JS", "Java Script"]'

Get Response: GET -k "user:0001"

{
    "name": "Alice",
    "skills": {
        "projects": {
            "cost": 200000,
            "currency": "INR",
            "project_name": "User Management"
        }
    }
}

Inner json path

Add and update key into json object using inner path

192.168.0.1:4775> UPDATE -k "user:0001" -p "works.projects" -d '{"language":["Go Lang", "React Js"]}'

Get Response: GET -k "user:0001"

{
    "name": "Alice",
    "skills": [
        "Node JS",
        "Java Script"
    ],
    "works": {
        "projects": {
            "language": [
                "Go Lang",
                "React Js"
            ]
        }
    }
}

Update specific key

Add and update key into json object using specific key

192.168.0.1:4775> UPDATE -k "user:0001" -p "works.projects.location" -d "Kolkata"'

Get Response: GET -k "user:0001"

{
    "name": "Alice",
    "skills": [
        "Node JS",
        "Java Script"
    ],
    "works": {
        "projects": {
            "language": [
                "Go Lang",
                "React Js"
            ],
            "location": "Kolkata"
        }
    }
}

Map Commands Reference

This document provides a reference for map-related commands used to store, retrieve, and manage key-value pairs efficiently.

MAP.SET

Sets a value in a map at a specified key and path.

Syntax:

192.168.0.1:4775> MAP.SET -k "<key>" -p "<path>" -d "<data>"

Example:

192.168.0.1:4775> MAP.SET -k "config" -p "theme" -d '"dark"'

Response:

"DONE"

MAP.ADD

Adds a new key-value pair to a map.

Syntax:

192.168.0.1:4775> MAP.ADD -k "<key>" -p "<path>" -d "<data>"

Example:

192.168.0.1:4775> MAP.ADD -k "config" -p "newSetting" -d '"enabled"'

Response:

"DONE"

MAP.DELETE

Removes a key-value pair from a map.

Syntax:

192.168.0.1:4775> MAP.DELETE -k "<key>" -p "<path>"

Example:

192.168.0.1:4775> MAP.DELETE -k "config" -p "theme"

Response:

"DONE"

4. MAP.GET

Retrieves a value from a map at a given key and path.

Syntax:

192.168.0.1:4775> MAP.GET -k "<key>" -p "<path>"

Example: Fetching all key-value pairs within a map:

192.168.0.1:4775> MAP.GET -k "config"

Response:

{
    "newSetting": "enabled",
    "theme": "dark"
}

Fetching a specific value at a given path:

192.168.0.1:4775> MAP.GET -k "config" -p "theme"

Response:

"dark"

LIST.ADD

Adds an element to a list stored at the given key.

192.168.0.1:4775> LIST.ADD -k "tasks" -d '"New Task"'

LIST.GET

Example > Given key

Retrieves elements from a list based on a given key.

192.168.0.1:4775> LIST.GET -k "tasks"

Response:

[
    "New Task",
    "New Task 2",
    2000101.99,
    {
        "id": 1001,
        "name": "Tapas Maity"
    }
]

Example > Given key and index

Retrieves elements from a list based on a given key and index. Use -p "2" or -p "[2]"

192.168.0.1:4775> LIST.GET -k "tasks" -p "2"

Response:

[
    2000101.99
]

Example > Given key and path

Retrieves elements from a list based on a given key and path. If index is unknown use [*] filter and the field:value pair (if present)

192.168.0.1:4775> LIST.GET -k "tasks" -p "[*]>id:1001"

Response:

[
    {
        "id": 1001,
        "name": "Tapas Maity"
    }
]

LIST.DELETE

Deletes an element from a list at a specified index.

192.168.0.1:4775> LIST.DELETE -k "tasks" -p "2"

LIST.UPDATE

Updates an element in a list at a specified index.

192.168.0.1:4775> LIST.UPDATE -k "tasks" -p "1" -d '"Updated Task"'

Handling System Signals

  • Pressing CTRL+C prompts the user to use the exit command.
  • The CLI listens for termination signals to close the connection gracefully.

Contribution

Feel free to contribute to the development of Infleare CLI by submitting issues or pull requests.

License

Infleare CLI is open-source and distributed under the MIT License.

I have read this