badger-cli is a simple command-line interface for interacting with Badger DB,
a fast key-value database written in Go.
- Connect to an existing Badger DB
- Get, set, and delete key-value pairs
- List keys with optional glob pattern matching
- Read-only mode for safe database inspection
Install using homebrew:
brew install lovromazgon/tap/badger-cliOr build it from source using Go:
go install github.com/lovromazgon/badger-cliOr download the binary manually from the latest release.
$ badger-cli -h
Usage: badger-cli [options] <database_path>
A command-line interface for a Badger key-value database.
Options:
-r, --readonly Open database in read-only mode
-h, --help Show help
Examples:
badger-cli /path/to/db
badger-cli --readonly /path/to/dbTo open the database in read-only mode (useful for inspecting production databases safely):
badger-cli --readonly /path/to/your/badger/db
# or
badger-cli -r /path/to/your/badger/dbIn read-only mode:
- The prompt will show
[READONLY] > - Only
getandlistcommands are available setanddeletecommands are disabled- The database is opened with read-only permissions
- The database must already exist (will not create new databases)
- If the database is already in use by another process, you may need to run without -readonly first to ensure proper initialization
Once the CLI is running, you can use the following commands:
get <key>: Retrieve the value for a given keyset <key> <value>: Set a value for a given key (not available in read-only mode)delete <key>: Delete a key-value pair (not available in read-only mode)list [pattern]: List all keys, optionally filtered by a glob patternexit: Exit the CLI
Normal mode:
> set mykey myvalue
Value set successfully
> get mykey
myvalue
> list my*
mykey
> delete mykey
Value deleted successfully
> list
No matching keys found
> exitRead-only mode:
[READONLY] > get mykey
myvalue
[READONLY] > list my*
mykey
[READONLY] > set newkey newvalue
Error: Cannot set values in read-only mode
[READONLY] > delete mykey
Error: Cannot delete values in read-only mode
[READONLY] > exitThe list command supports glob pattern matching:
*: Matches any sequence of characters?: Matches any single character[abc]: Matches any character in the set[a-z]: Matches any character in the range
Examples:
list app_*: Lists all keys starting with "app_"list *_config: Lists all keys ending with "_config"list user_??: Lists all keys starting with "user_" followed by exactly two characters
The initial version of this CLI was developed with assistance from an AI language model. The code has since been modified and expanded.
