### Install SugarDB Server via Homebrew Source: https://github.com/echovault/sugardb/blob/main/docs/docs/intro.md Provides the command-line steps to install the SugarDB server using Homebrew, including tapping the repository and installing the package. This is the recommended method for client-server setup on macOS and Linux systems. ```Shell brew tap echovault/sugardb brew install echovault/echovault/sugardb ``` -------------------------------- ### Install SugarDB Go Module Source: https://github.com/echovault/sugardb/blob/main/docs/docs/intro.md Command to install the SugarDB Go module as an embedded library using `go get`. This makes the SugarDB package available for use in Go projects, enabling direct integration into applications. ```Shell go get github.com/echovault/sugardb ``` -------------------------------- ### GET Command Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/generic/get.mdx Provides practical examples demonstrating how to retrieve a value for a given key using the `GET` command, both through the Go embedded client and the command-line interface. ```Go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } value, err := db.Get("key") ``` ```CLI > GET key ``` -------------------------------- ### Run SugarDB Server Command Source: https://github.com/echovault/sugardb/blob/main/docs/docs/intro.md Command to start the SugarDB server, specifying the bind address and the data directory for persistence. This command is executed after installation for client-server mode, allowing the server to listen for connections and store data. ```Shell echovault --bind-addr=localhost --data-dir="path/to/persistence/directory" ``` -------------------------------- ### Initialize and Use Embedded SugarDB Source: https://github.com/echovault/sugardb/blob/main/docs/docs/intro.md Demonstrates how to create a new embedded SugarDB instance, set and retrieve a key-value pair, and optionally start listening for TCP connections. This example highlights the ergonomic API for basic database operations within a Go application. ```Go func main() { server, err := db.NewSugarDB() if err != nil { log.Fatal(err) } _, _, _ = server.Set("key", "Hello, world!", db.SETOptions{}) v, _ := server.Get("key") fmt.Println(v) // Hello, world! // (Optional): Listen for TCP connections on this SugarDB instance. server.Start() } ``` -------------------------------- ### Get Database Size Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/generic/dbsize.mdx Demonstrates how to retrieve the number of keys in the database using both the SugarDB Go client and the command-line interface. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } key, err := db.DBSize() ``` ```shell > DBSIZE ``` -------------------------------- ### Subscribe to Channels Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/pubsub/subscribe.mdx Practical examples demonstrating how to use the SUBSCRIBE command. The Go example illustrates initializing SugarDB, subscribing to channels, reading messages from the `MessageReader` (which returns JSON-marshalled byte arrays), and unmarshalling them. The CLI example shows the direct command line invocation. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } // Subscribe to multiple channel patterns, returs MessageReader. msgReader := db.Subscribe("subscribe_tag_1", "channel1", "channel2") // Read message into pre-defined buffer. msg := make([]byte, 1024) _, err := msgReader.Read(msg) // Trim all null bytes at the end of the message before unmarshalling. var message []string if err = json.Unmarshal(bytes.TrimRight(p, "\x00"), &message); err != nil { log.Fatalf("json unmarshal error: %+v", err) } ``` ```cli > SUBSCRIBE channel1 channel2 ``` -------------------------------- ### ZMPOP Command Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/sorted_set/zmpop.mdx Provides practical examples demonstrating how to use the ZMPOP command. It includes an example for Go (embedded) showing API usage with `sugardb.NewSugarDB()` and `vault.ZMPop()`, and a CLI example for direct command-line execution. ```Go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } sortedSets, err := vault.ZMPop([]string{"key1", "key2"}, db.ZMPopOptions{Min: true, Count: 2}) ``` ```CLI > ZMPOP key1 key2 MIN COUNT 2 ``` -------------------------------- ### Get SugarDB Command Count Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/admin/command_count.mdx Demonstrates how to retrieve the number of commands in a SugarDB instance using both the Go embedded client and the command-line interface. The Go example shows client initialization and method invocation, while the CLI example illustrates direct command execution. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } count, err := db.CommandCount() ``` ```cli > COMMAND COUNT ``` -------------------------------- ### PSUBSCRIBE Command Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/pubsub/psubscribe.mdx Practical examples demonstrating how to subscribe to pub/sub patterns using the `PSUBSCRIBE` command in both Go and CLI environments. ```Go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } // Subscribe to multiple channel patterns, returs MessageReader msgReader := db.PSubscribe("psubscribe_tag_1", "channel[12]", "pattern[12]") // Read message into pre-defined buffer msg := make([]byte, 1024) _, err := msgReader.Read(msg) // Trim all null bytes at the end of the message before unmarshalling. var message []string if err = json.Unmarshal(bytes.TrimRight(p, "\x00"), &message); err != nil { log.Fatalf("json unmarshal error: %+v", err) } ``` ```CLI PSUBSCRIBE pattern_[12] pattern_h[ae]llo ``` -------------------------------- ### List Loaded Modules Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/admin/module_list.mdx Examples demonstrating how to list all modules currently loaded in the server or instance, using both the Go (embedded) client library and the command-line interface. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } modules := db.ListModules() ``` ```CLI > MODULE LIST ``` -------------------------------- ### FLUSHDB Command Examples (Go and CLI) Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/generic/flushdb.mdx Illustrates how to execute the FLUSHDB command using an embedded Go instance and via the command-line interface. The Go example shows initializing SugarDB and flushing a specific database index, while the CLI example demonstrates flushing the current connection's database. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } db.Flush(0) ``` ```CLI FLUSHDB ``` -------------------------------- ### Get Key Access Frequency Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/generic/objectfreq.mdx Practical examples demonstrating how to use the OBJECTFREQ command to retrieve the access frequency of a key, shown for both Go (Embedded) and CLI environments. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } freq, err := db.ObjectFreq("key") ``` ```cli > OBJECTFREQ key ``` -------------------------------- ### Load Module - With Arguments Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/admin/module_load.mdx Examples demonstrating how to load a module while passing multiple arguments. This includes an embedded Go application example initializing SugarDB and calling `server.LoadModule` with additional string arguments, as well as a command-line interface example. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } err := server.LoadModule("/path/to/module.so", "arg1", "arg2", "arg3") ``` ```cli > MODULE LOAD path/to/module.so arg1 arg2 arg3 ``` -------------------------------- ### LPUSH Command Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/list/lpush.mdx Demonstrates how to use the LPUSH command to prepend elements to a list, creating the list if it doesn't exist, with examples for both Go (Embedded) and CLI interfaces. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } length, err := db.LPush("key", "element1", "element2") ``` ```cli > LPUSH key element1 element2 ``` -------------------------------- ### CLI - HELLO Command Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/connection/hello.mdx A collection of command-line interface examples showcasing various uses of the HELLO command, including basic client report fetching, full authentication and naming, authentication only, naming only, and switching to a specific protocol version with or without authentication. ```cli > HELLO ``` ```cli > HELLO 2 AUTH myuser mypass SETNAME myclient ``` ```cli > HELLO 2 AUTH myuser mypass ``` ```cli > HELLO 2 SETNAME myclient ``` ```cli > HELLO 3 ``` ```cli > HELLO 3 AUTH myuser mypass ``` -------------------------------- ### SDIFFSTORE Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/set/sdiffstore.mdx Illustrates how to use the SDIFFSTORE command to store the difference between two sets, providing examples for both Go (Embedded) and command-line interface (CLI) interactions. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } cardinality, err := db.SDiffStore("destination", "key1", "key2") ``` ```cli > SDIFFSTORE destination key1 key2 ``` -------------------------------- ### CLI AUTH Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/connection/auth.mdx Examples of using the AUTH command via the command-line interface, showing authentication against the default user and a specific user. ```cli > AUTH password ``` ```cli > AUTH username password ``` -------------------------------- ### Load Module - No Arguments Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/admin/module_load.mdx Examples demonstrating how to load a module without passing any arguments. This includes an embedded Go application example initializing SugarDB and calling `server.LoadModule`, as well as a command-line interface example. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } err := server.LoadModule("/path/to/module.so") ``` ```cli > MODULE LOAD path/to/module.so ``` -------------------------------- ### Set Value If Key Exists, Get Previous, and Expire (XX GET EX) Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/generic/set.mdx Demonstrates a more complex `SET` operation combining `XX` (set only if key exists), `GET` (return previous value), and `EX` (expire after seconds). This example updates an existing key, retrieves its old value, and sets an expiration time. Examples are provided for both the Go embedded API and the CLI. ```Go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } previousValue, err := db.Set("name", "SugarDB", db.SETOptions{WriteOpt: db.SETXX, ExpireOpt: db.SETEX, ExpireTime: 10, Get: true}) ``` ```CLI > SET name SugarDB XX GET EX 10 ``` -------------------------------- ### HGETALL Command Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/hash/hgetall.mdx Illustrates how to use the HGETALL command to fetch all fields and values from a hash, with examples for Go (embedded) and CLI. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } result, err := db.HGetAll("key") ``` ```cli > HGETALL key ``` -------------------------------- ### Build Project for Other Operating Systems Source: https://github.com/echovault/sugardb/blob/main/docs/docs/contribution.md General instructions for building the project on operating systems other than MacOS. This requires using the Go build command with system-specific flags. ```Shell go build ``` -------------------------------- ### REWRITEAOF Command Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/admin/rewriteaof.mdx Provides practical examples of how to use the `REWRITEAOF` command in SugarDB, demonstrating its invocation via the Go embedded client and the command-line interface (CLI). These examples illustrate the typical integration and execution of the command. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } count, err := db.RewriteAOF() ``` ```cli > REWRITEAOF ``` -------------------------------- ### Publish Message to Channel Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/pubsub/publish.mdx Demonstrates how to publish a message to a specified channel using the SugarDB client library in Go and via the command-line interface. Both examples achieve the same functionality of sending 'Hello, world!' to 'channel1'. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } ok, err := db.Publish("channel1", "Hello, world!") ``` ```cli > PUBLISH channel1 "Hello, world!" ``` -------------------------------- ### HSET Command Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/hash/hset.mdx Illustrates how to use the HSET command in different environments, including Go for embedded applications and a generic command-line interface. These examples demonstrate updating multiple fields of a hash simultaneously. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } noOfUpdatedFields, err := db.HSet("key", map[string]string{"field1": "value1", "field2": "value2"}) ``` ```cli > HSET key field1 value1 field2 value2 ``` -------------------------------- ### Go (Embedded) AUTH Example Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/connection/auth.mdx An example demonstrating the AUTH command in Go, noting that it is not available in embedded mode. ```go // Not available in embedded mode. ``` -------------------------------- ### EXPIRETIME Command Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/generic/expiretime.mdx Examples demonstrating how to retrieve the expiration time of a key using the EXPIRETIME command in both Go (embedded client) and the command-line interface (CLI). These examples show how to initialize the database connection and execute the command. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } expireTime, err := db.ExpireTime("key") ``` ```shell > EXPIRETIME key ``` -------------------------------- ### Set Value If Key Exists and Get Previous (XX GET) Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/generic/set.mdx Shows how to use the `XX` and `GET` options together. The value is set only if the key already exists, and the command returns the old value stored at that key. Examples are provided for both the Go embedded API and the CLI. ```Go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } previousValue, err := db.Set("name", "SugarDB", db.SETOptions{WriteOpt: db.SETXX, Get: true}) ``` ```CLI > SET name SugarDB XX GET ``` -------------------------------- ### Set Multiple Key-Value Pairs with MSET Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/generic/mset.mdx Illustrates practical usage of the MSET command to set multiple key-value pairs. Examples are provided for both Go (embedded) and command-line interface (CLI) environments. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } ok, err := db.MSet(map[string]string{"key1": "value1", "key2": "value2", "key3": "value3"}) ``` ```cli > MSET key1 value1 key2 value2 key3 value3 ``` -------------------------------- ### SugarDB SDIFF Command Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/set/sdiff.mdx Illustrates practical usage of the SDIFF command to find the difference between two sets. Examples are provided for both Go embedded database interaction and direct command-line interface execution. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } elements, err := db.SDiff("key1", "key2") ``` ```cli > SDIFF key1 key2 ``` -------------------------------- ### HVALS Command Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/hash/hvals.mdx Illustrates practical applications of the HVALS command to retrieve all values from a hash key, providing examples for both Go (embedded) and command-line interface (CLI) environments. ```Go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } values, err := db.HVals("key") ``` ```CLI > HVALS key ``` -------------------------------- ### Build and Run Development Container on MacOS Source: https://github.com/echovault/sugardb/blob/main/docs/docs/contribution.md Instructions for building the project and spinning up the development Docker container specifically for MacOS users. This command leverages a Makefile. ```Shell make run ``` -------------------------------- ### SINTER Command Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/set/sinter.mdx Examples demonstrating how to use the SINTER command to find the intersection of multiple sets, both programmatically with the Go embedded client and via the command-line interface. ```Go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } elements, err := db.SInter("key1", "key2") ``` ```Shell > SINTER key1 key2 ``` -------------------------------- ### RPUSHX Command Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/list/rpushx.mdx Demonstrates how to use the RPUSHX command to append elements to an existing list, with examples provided for both Go (embedded) and the command-line interface (CLI). ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } length, err := db.RPushX("key", "element1", "element2") ``` ```cli > RPUSHX key element1 element2 ``` -------------------------------- ### ZDIFFSTORE Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/sorted_set/zdiffstore.mdx Provides practical examples of how to use the ZDIFFSTORE command in both Go (embedded) and command-line interface (CLI) environments to compute and store the difference between sorted sets. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } cardinality, err := vault.ZDiffStore("destination", "key1", "key2") ``` ```cli > ZDIFFSTORE destination key1 key2 ``` -------------------------------- ### Get Hash Length via Command Line Interface Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/hash/hlen.mdx Provides a straightforward example of executing the HLEN command directly through the command-line interface. This demonstrates the simplest way to query the number of fields for a given hash 'key'. ```CLI > HLEN key ``` -------------------------------- ### CLI PubSub Channels Command Example Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/pubsub/pubsub_channels.mdx Illustrates how to execute the PUBSUB CHANNELS command directly from the command line to list channels matching a specified pattern. This example shows a common interactive shell usage. ```cli > PUBSUB CHANNELS channel* ``` -------------------------------- ### Configure Embedded SugarDB Instance Source: https://github.com/echovault/sugardb/blob/main/docs/docs/intro.md Shows how to retrieve the default configuration for an embedded SugarDB instance and modify properties like `ServerID` before initializing the database. This allows for fine-grained control over the instance's behavior and identification within a cluster. ```Go conf := db.DefaultConfig() conf.ServerID = "ServerInstance1" server, err := db.NewSugarDB( db.WithConfig(conf), ) if err != nil { log.Fatal(err) } ``` -------------------------------- ### List ACL Usernames Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/acl/acl_users.mdx Demonstrates how to list all configured ACL usernames using both the Go embedded client and the command-line interface. The Go example shows interaction with `sugardb.NewSugarDB()` and `db.ACLUsers()`. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } users, err := db.ACLUsers() ``` ```cli > ACL USERS ``` -------------------------------- ### ZINTER Command Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/sorted_set/zinter.mdx Illustrates practical applications of the ZINTER command using both Go (with the sugardb library) and command-line interface (CLI). Examples demonstrate basic intersection operations and advanced usage with weighted scores, custom aggregation, and score inclusion. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } sortedSet, err := db.ZInter([]string{"key1", "key2"}, db.ZInterOptions{}) ``` ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } sortedSet, err := db.ZInter( []string{"key1", "key2"}, db.ZInterOptions{Weights: []float64{2, 4}, Aggregate: "SUM", WithScores: true}, ) ``` ```cli > ZINTER key1 key2 ``` ```cli > ZINTER key1 key2 WEIGHTS 2 4 AGGREGATE SUM WITHSCORES ``` -------------------------------- ### PING Command Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/connection/ping.mdx Illustrates how to use the PING command in SugarDB, providing examples for both Go (embedded mode) and the command-line interface (CLI). ```Go // Not available in embedded mode. ``` ```CLI > PING > PING "Hello, world!" ``` -------------------------------- ### CLI PUNSUBSCRIBE Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/pubsub/punsubscribe.mdx Illustrates how to execute the `PUNSUBSCRIBE` command directly from a command-line interface. Examples cover unsubscribing from all patterns and specific patterns. ```cli > PUNSUBSCRIBE ``` ```cli > PUNSUBSCRIBE pattern_[12] pattern_h[ae]llo ``` -------------------------------- ### MGET Command Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/generic/mget.mdx Demonstrates how to use the MGET command in an embedded Go application and through the command-line interface to fetch values for multiple keys. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } values, err := db.MGet("key1", "key2", "key3") ``` ```cli > MGET key1 key2 key3 ``` -------------------------------- ### LPOP Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/list/lpop.mdx Provides practical examples of using the LPOP command to remove and retrieve the first element from a list. Includes implementations for Go (embedded database interaction) and direct CLI execution. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } element, err := db.LPop("key") ``` ```cli > LPOP key ``` -------------------------------- ### Go (Embedded) Example: Deleting All Keys with Flush Method Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/generic/flushall.mdx This Go example demonstrates how to use the `sugardb.NewSugarDB()` to initialize a database connection and then call the `Flush` method with `-1` to synchronously delete all keys in all existing databases. It includes error handling for database initialization. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } db.Flush(-1) ``` -------------------------------- ### Pull SugarDB Docker Image from GitHub Container Registry Source: https://github.com/echovault/sugardb/blob/main/docs/docs/intro.md Command to pull the SugarDB Docker image from GitHub Container Registry. This provides an alternative source for the container image, useful for specific CI/CD pipelines or environments that prefer GitHub's registry. ```Shell docker pull ghcr.io/echovault/sugardb ``` -------------------------------- ### Pull SugarDB Docker Image from Docker Hub Source: https://github.com/echovault/sugardb/blob/main/docs/docs/intro.md Command to pull the official SugarDB Docker image from Docker Hub. This allows users to run SugarDB as a containerized service easily, providing a portable and isolated environment for the database. ```Shell docker pull echovault/sugardb ``` -------------------------------- ### Get Hash Length with Go sugardb Client Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/hash/hlen.mdx Illustrates how to use the HLen method from the sugardb Go client to obtain the number of fields in a hash. The example includes database initialization, error handling, and demonstrates retrieving the length for a specified 'key'. ```Go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } length, err := db.HLen("key") ``` -------------------------------- ### ECHO Command Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/connection/echo.mdx Illustrates how to invoke the ECHO command in different SugarDB environments. This includes an example for the CLI, showing how to echo a string, and notes its unavailability in embedded Go mode. ```go // Not available in embedded mode. ``` ```cli > ECHO "Hello, World!" ``` -------------------------------- ### PERSIST Command Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/generic/persist.mdx Illustrates how to use the `PERSIST` command in different environments. Examples include Go (embedded) for programmatic interaction with SugarDB and CLI for direct command-line execution, demonstrating how to remove the TTL associated with a key. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } ok, err := db.Persist("key") ``` ```cli > PERSIST key ``` -------------------------------- ### GETDEL Command Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/generic/getdel.mdx Illustrates how to use the GETDEL command in Go (embedded) and via the command-line interface, demonstrating how to retrieve a value and simultaneously delete the key. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } value, err := db.GetDel("key") ``` ```cli > GETDEL key ``` -------------------------------- ### Retrieve Key Expiration Time Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/generic/ttl.mdx Examples demonstrating how to retrieve the remaining time to live for a key using different interfaces. The Go example shows programmatic access via `sugardb.NewSugarDB()` and `db.TTL()`, while the CLI example illustrates direct command execution. ```Go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } ttl, err := db.TTL("key") ``` ```CLI > TTL key ``` -------------------------------- ### Initialize Embedded SugarDB with Custom Context Source: https://github.com/echovault/sugardb/blob/main/docs/docs/intro.md Illustrates how to pass a custom `context.Context` to an embedded SugarDB instance during initialization using the `WithContext` option. This enables context-specific operations and data propagation within the database instance, useful for tracing or request-scoped data. ```Go ctx := context.WithValue(context.Background(), "name", "default") server, err := db.NewSugarDB( db.WithContext(ctx), ) if err != nil { log.Fatal(err) } ``` -------------------------------- ### CLI Example: Executing FLUSHALL Command Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/generic/flushall.mdx This example shows the direct command-line interface (CLI) execution of the `FLUSHALL` command. It synchronously deletes all keys across all databases without requiring any parameters. ```cli > FLUSHALL ``` -------------------------------- ### HTTL Command Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/hash/httl.mdx Illustrates how to use the HTTL command to retrieve the remaining TTL for specific fields within a hash key, providing examples for both Go (embedded) and CLI environments. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } TTLArray, err := db.HTTL("key", field1, field2) ``` ```cli > HTTL key FIELDS 2 field1 field2 ``` -------------------------------- ### Move Key to Database Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/generic/move.mdx Demonstrates moving a key from the current database to a specified destination database (database 1) using Go (embedded) and CLI. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } value, err := db.Move("key", 1) ``` ```cli > MOVE key 1 ``` -------------------------------- ### GET Command API Specification Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/generic/get.mdx Defines the syntax, module, and categories for the `GET` command in SugarDB, outlining its fundamental structure and classification. ```APIDOC Syntax: GET key Module: generic Categories: fast, keyspace, read ``` -------------------------------- ### CLI Examples for ACL Load Command Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/acl/acl_load.mdx Provides command-line interface examples for executing the `ACL LOAD` command. It shows how to use `ACL LOAD MERGE` to combine configurations from a file with the currently loaded ones, and `ACL LOAD REPLACE` to completely overwrite them. ```CLI > ACL LOAD MERGE ``` ```CLI > ACL LOAD REPLACE ``` -------------------------------- ### HEXISTS Command Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/hash/hexists.mdx Practical examples demonstrating how to use the `HEXISTS` command to check for the existence of a field within a hash, provided for both Go (Embedded) and CLI environments. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } exists, err := db.HExists ("key", "field1") ``` ```cli > HEXISTS key field1 ``` -------------------------------- ### LTRIM Command Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/list/ltrim.mdx Illustrates practical usage of the LTRIM command to trim a list named 'key' from index 2 to 6. Examples are provided for both Go (embedded) and command-line interface (CLI) environments. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } ok, err := db.LTrim("key", 2, 6) ``` ```cli > LTRIM key 2 6 ``` -------------------------------- ### RPUSH Command Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/list/rpush.mdx Illustrates practical usage of the RPUSH command in both Go (embedded) and command-line interface environments. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } length, err := db.RPush("key", "element1", "element2") ``` ```cli > RPUSH key element1 element2 ``` -------------------------------- ### ZPOPMAX Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/sorted_set/zpopmax.mdx Provides practical examples demonstrating how to use the ZPOPMAX command in both Go (embedded) and CLI environments to remove and retrieve members from a sorted set based on their scores. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } members, err := db.ZPopMax("key", 2) ``` ```cli > ZPOPMAX key 2 ``` -------------------------------- ### LMOVE Command Usage Example Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/list/lmove.mdx Illustrates how to use the LMOVE command to move an element from the beginning of a source list to the end of a destination list, providing examples for both Go (Embedded) and CLI environments. ```Go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } ok, err := db.LMove("source", "destination", "LEFT", "RIGHT") ``` ```CLI > LMOVE source destination LEFT RIGHT ``` -------------------------------- ### HRANDFIELD Command Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/hash/hrandfield.mdx Practical examples demonstrating how to use the HRANDFIELD command in both Go (embedded) and a generic command-line interface (CLI) to retrieve random fields from a hash. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } fields, err := db.HRandField("key", db.HRandFieldOptions{}) ``` ```CLI > HRANDFIELD key ``` -------------------------------- ### COMMANDS Command Reference Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/admin/commands.mdx Provides the basic syntax and an example for retrieving a list of all available commands on the SugarDB instance via the command-line interface. ```CLI COMMANDS ``` ```CLI > COMMAND ``` -------------------------------- ### Go (Embedded) PUNSUBSCRIBE Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/pubsub/punsubscribe.mdx Demonstrates how to use the `PUNSUBSCRIBE` command within a Go application using the `sugardb` client library. Examples include unsubscribing from all patterns and specific patterns. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } db.PUnsubscribe() ``` ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } db.PUnsubscribe("pattern_[12]", "pattern_h[ae]llo") ``` -------------------------------- ### Get String Length (STRLEN) Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/string/strlen.mdx Examples demonstrating how to use the STRLEN command in SugarDB to retrieve the length of a string value, shown for both Go (Embedded) and CLI interfaces. ```Go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } length, err := db.StrLen("key") ``` ```CLI > STRLEN key ``` -------------------------------- ### CLI HMGET Example Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/hash/hmget.mdx Illustrates the direct usage of the HMGET command via the command-line interface. This example shows how to retrieve the values of 'field1' and 'field2' from a hash named 'key' using the CLI. ```cli > HMGET key field1 field2 ``` -------------------------------- ### HINCRBY Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/hash/hincrby.mdx Illustrates how to use the HINCRBY command to increment a hash field's value, providing examples for both Go (embedded) and the command-line interface (CLI). ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } newValue, err := db.HIncrBy("key", "field", 7) ``` ```cli > HINCRBY key field 7 ``` -------------------------------- ### Retrieve Hash Field String Lengths Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/hash/hstrlen.mdx Illustrates how to use the `HSTRLEN` command to get the string lengths of multiple fields in a hash. Examples are provided for both Go (embedded client) and the command-line interface (CLI). ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } lengths, err := db.HStrLen("key", "field1", "field2", "field3") ``` ```cli > HSTRLEN key field1 field2 ``` -------------------------------- ### Get Last Snapshot Timestamp (LASTSAVE) Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/admin/lastsave.mdx Demonstrates how to retrieve the Unix timestamp of the latest database snapshot in milliseconds. The Go example shows integration with the sugardb client, while the CLI example shows direct command execution. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } count, err := db.LastSave() ``` ```shell > LASTSAVE ``` -------------------------------- ### LSET Command Examples in Go and CLI Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/list/lset.mdx Demonstrates how to use the LSET command to set the value of an element in a list by its index, with examples for both Go (using SugarDB) and the command-line interface. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } ok, err := db.LSet("key", 2, "element") ``` ```cli > LSET key 2 element ``` -------------------------------- ### HDEL Command Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/hash/hdel.mdx Illustrates how to use the HDEL command to delete specified fields from a hash, with examples provided for Go (embedded) and the command-line interface (CLI). ```Go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } deletedCount, err := db.HDel("key", "field1", "field2") ``` ```CLI > HDEL key field1 field2 ``` -------------------------------- ### CLI ZRANGESTORE Command Example Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/sorted_set/zrangestore.mdx Shows a command-line example of using ZRANGESTORE to retrieve elements within a score range, reverse the order, apply a limit, and include scores, storing them in a specified key. ```cli ZRANGESTORE key 11.55 15.66 BYSCORE REV LIMIT 0 2 WITHSCORES ``` -------------------------------- ### Get Single Random Member from Sorted Set Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/sorted_set/zrandmember.mdx Demonstrates how to retrieve a single random member from a sorted set. The Go example initializes SugarDB and handles potential errors, while the CLI example shows the direct command-line usage. ```Go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } members, err := vault.ZRandMember("key", 1, false) ``` ```CLI > ZRANDMEMBER key ``` -------------------------------- ### SUNION Command Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/set/sunion.mdx Illustrates how to use the SUNION command in both Go (embedded) and command-line interface (CLI) environments to obtain the union of specified sets. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } elements, err := db.SUnion("key1", "key2") ``` ```cli > SUNION key1 key2 ``` -------------------------------- ### Get ZRANGE by Score Example Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/sorted_set/zrange.mdx Demonstrates how to retrieve a range of elements from a sorted set using the ZRANGE command, applying score-based sorting, reverse order, limit, and score inclusion. Examples are provided for both Go (embedded) and CLI usage. ```Go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } sortedSet, err := vault.ZRange("key", "11.55", "15.66", db.ZRangeOptions{ ByScore: true, Rev: true, WithScores: true, Offset: 0, Count: 2, }) ``` ```CLI > ZRANGE key 11.55 15.66 BYSCORE REV LIMIT 0 2 WITHSCORES ``` -------------------------------- ### SugarDB Lua Module Definition Example Source: https://github.com/echovault/sugardb/blob/main/docs/docs/extension/lua.mdx This snippet provides a complete example of a Lua script module for SugarDB. It defines a custom command, its categories, description, and synchronization behavior. It also includes implementations for `keyExtractionFunc` to manage access control and `handlerFunc` to perform database operations like setting and retrieving values. ```lua -- The keyword to trigger the command command = "LUA.EXAMPLE" --[[ The string array of categories this command belongs to. This array can contain both built-in categories and new custom categories. ]] categories = {"generic", "write", "fast"} -- The description of the command description = "(LUA.EXAMPLE) Example lua command that sets various data types to keys" -- Whether the command should be synced across the RAFT cluster sync = true --[[ keyExtractionFunc is a function that extracts the keys from the command and returns them to SugarDB.keyExtractionFunc The returned data from this function is used in the Access Control Layer to determine if the current connection is authorized to execute this command. The function must return a table that specifies which keys in this command are read keys and which ones are write keys. Example return: ["readKeys"] = {"key1", "key2"}, ["writeKeys"] = {"key3", "key4", "key5"}} 1. "command" is a string array representing the command that triggered this key extraction function. 2. "args" is a string array of the modifier args that were passed when loading the module into SugarDB. These args are passed to the key extraction function everytime it's invoked. ]] function keyExtractionFunc (command, args) if (#command ~= 1) then error("wrong number of args, expected 0") end return { ["readKeys"] = {}, ["writeKeys"] = {} } end --[[ handlerFunc is the command's handler function. The function is passed some arguments that allow it to interact with SugarDB. The function must return a valid RESP response or throw an error. The handler function accepts the following args: 1. "context" is a table that contains some information about the environment this command has been executed in. Example: ["protocol"] = 2, ["database"] = 0} This object contains the following properties: i) protocol - the protocol version of the client that executed the command (either 2 or 3). ii) database - the active database index of the client that executed the command. 2. "command" is the string array representing the command that triggered this handler function. 3. "keyExists" is a function that can be called to check if a list of keys exists in the SugarDB store database. This function accepts a string array of keys to check and returns a table with each key having a corresponding boolean value indicating whether it exists. Examples: i) Example invocation: keyExists({"key1", "key2", "key3"}) ii) Example return: ["key1"] = true, ["key2"] = false, ["key3"] = true} 4. "getValues" is a function that can be called to retrieve values from the SugarDB store database. The function accepts a string array of keys whose values we would like to fetch, and returns a table with each key containing the corresponding value from the store. The possible data types for the values are: number, string, nil, hash, set, zset Examples: i) Example invocation: getValues({"key1", "key2", "key3"}) ii) Example return: ["key1"] = 3.142, ["key2"] = nil, ["key3"] = "Pi"} 5. "setValues" is a function that can be called to set values in the active database in the SugarDB store. This function accepts a table with keys and the corresponding values to set for each key in the active database in the store. The accepted data types for the values are: number, string, nil, hash, set, zset. The setValues function does not return anything. Examples: i) Example invocation: setValues({["key1"] = 3.142, ["key2"] = nil, ["key3"] = "Pi"}) 6. "args" is a string array of the modifier args passed to the module at load time. These args are passed to the handler everytime it's invoked. ]] function handlerFunc(ctx, command, keysExist, getValues, setValues, args) -- Set various data types to keys local keyValues = { ["numberKey"] = 42, ["stringKey"] = "Hello, SugarDB!", ["nilKey"] = nil, } -- Store the values in the database setValues(keyValues) -- Verify the values have been set correctly local keysToGet = {"numberKey", "stringKey", "nilKey"} local retrievedValues = getValues(keysToGet) -- Create a table to track mismatches local mismatches = {} for key, expectedValue in pairs(keyValues) do local retrievedValue = retrievedValues[key] if retrievedValue ~= expectedValue then table.insert(mismatches, string.format("Key '%s': expected '%s', got '%s'", key, tostring(expectedValue), tostring(retrievedValue))) end end -- If mismatches exist, return an error if #mismatches > 0 then error("values mismatch") end -- If all values match, return OK return "+OK\r\n" end ``` -------------------------------- ### Increment Key Value with INCRBY Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/generic/incrby.mdx Examples demonstrating how to use the INCRBY command to increment a key's value by a specified amount, both programmatically in Go and via the command-line interface. The Go example shows initialization of SugarDB and error handling. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } value, err := db.IncrBy("mykey", "5") ``` ```cli > INCRBY mykey 5 ``` -------------------------------- ### Get Two Unique Random Members from Sorted Set Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/sorted_set/zrandmember.mdx Illustrates how to fetch two distinct random members from a sorted set. The Go example includes SugarDB initialization and error handling, and the CLI example shows the command with a specified count. ```Go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } members, err := vault.ZRandMember("key", 2, false) ``` ```CLI > ZRANDMEMBER key 2 ``` -------------------------------- ### Get Four Non-Unique Random Members with Scores Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/sorted_set/zrandmember.mdx Shows how to retrieve four potentially non-unique random members along with their scores from a sorted set. The Go example includes SugarDB initialization and error handling, and the CLI example demonstrates the command with a negative count and WITHSCORES. ```Go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } members, err := vault.ZRandMember("key", -4, true) ``` ```CLI > ZRANDMEMBER key -4 WITHSCORES ``` -------------------------------- ### Get Set Cardinality with SCARD Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/set/scard.mdx Examples demonstrating how to retrieve the cardinality of a set using the SCARD command, provided for both Go (embedded client) and the command-line interface (CLI). ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } cardinality, err := db.SCard("key") ``` ```cli > SCARD key ``` -------------------------------- ### CLI SINTERSTORE Command Example Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/set/sinterstore.mdx Demonstrates the usage of the `SINTERSTORE` command directly via the command-line interface to compute and store the intersection of two sets. ```cli > SINTERSTORE destination key1 key2 ``` -------------------------------- ### Get Sorted Set Cardinality with ZCARD Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/sorted_set/zcard.mdx Examples demonstrating how to use the ZCARD command to retrieve the number of elements in a sorted set, both programmatically in Go and via the command-line interface. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } cardinality, err := db.ZCard("key") ``` ```cli > ZCARD key ``` -------------------------------- ### Unload a Module using Go and CLI Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/admin/module_unload.mdx Demonstrates how to unload a module using both the Go embedded client and the command-line interface. The Go example shows error handling, while the CLI example provides a direct command execution. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } err := server.UnloadModule("module-name") ``` ```shell > MODULE UNLOAD module-name ``` -------------------------------- ### Get Substring with CLI Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/string/getrange.mdx Illustrates the direct command-line interface usage of the GETRANGE command to extract a substring from a key's value, specifying the key and the start and end indexes. ```CLI > GETRANGE key 4 10 ``` -------------------------------- ### Get Random ZSet Members - JavaScript Source: https://github.com/echovault/sugardb/blob/main/docs/docs/extension/js.mdx Illustrates the `random` method, which retrieves a specified number of random members from the `ZSet`. The example shows fetching up to two random members. ```js var members = zset.random(2) // Returns up to 2 random members ``` -------------------------------- ### Get Sorted Set Member Score (CLI) Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/sorted_set/zscore.mdx Provides an example of executing the ZSCORE command directly via the command-line interface to fetch a member's score from a sorted set. ```cli > ZSCORE key member ``` -------------------------------- ### GETEX Command Usage Examples Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/generic/getex.mdx Illustrates how to use the GETEX command in both Go (embedded API) and CLI environments, demonstrating key retrieval and optional expiration setting. ```Go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } value, err := db.GetEx("key", nil, 0) // optionally set expiry value, err = db.GetEx("key", sugardb.EX, 10) ``` ```CLI > GETEX key EX 10 ``` -------------------------------- ### Calculate Set Intersection Cardinality (Go) Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/set/sintercard.mdx Illustrates how to use the `sugardb.SInterCard` function in Go to compute the cardinality of the intersection of multiple sets. Examples include getting the full cardinality and limiting the calculation. ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } cardinality, err := db.SInterCard([]string{"key1", "key2"}, 0) ``` ```go db, err := sugardb.NewSugarDB() if err != nil { log.Fatal(err) } cardinality, err := db.SInterCard([]string{"key1", "key2"}, 5) ``` -------------------------------- ### Get ZREVRANK via CLI Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/sorted_set/zrevrank.mdx This example illustrates how to execute the ZREVRANK command directly from the command line interface. It shows the basic syntax for retrieving the reverse rank of a member, including the WITHSCORE option. ```CLI > ZREVRANK key member WITHSCORE ``` -------------------------------- ### Go Example: Adding a Custom Command to SugarDB Source: https://github.com/echovault/sugardb/blob/main/docs/docs/extension/embedded.md This Go example demonstrates how to add a custom command named `COPYDEFAULT` to SugarDB. It includes defining a `myKeyExtractionFunc` for parsing command arguments and `myCommandHandler` for executing the command logic, then integrating them into a `main` function to register the new command with the SugarDB server. ```Go // Define the key extraction function func myKeyExtractionFunc(cmd []string) (db.CommandKeyExtractionFuncResult, error) { if len(cmd) != 3 { return db.CommandKeyExtractionFuncResult{}, errors.New("command must be length 3") } if cmd[1] == cmd[2] { return db.CommandKeyExtractionFuncResult{}, errors.New("keys must be different") } return db.CommandKeyExtractionFuncResult{ ReadKeys: []string{cmd[1]}, WriteKeys: []string{cmd[2]}, }, nil } // Define the command handler function func myCommandHandler(params db.CommandHandlerFuncParams) ([]byte, error) { // Extract keys keys, err := myKeyExtractionFunc(params.Command) if err != nil { return nil, err } // Get the write and read keys. readKey, writeKey := keys.ReadKeys[0], keys.WriteKeys[0] keysExist := params.KeysExist(params.Context, []string{writeKey, readKey}) // If readKey does not exist, return an error. if !keysExist[readKey] { return nil, fmt.Errorf("%s does not exist", readKey) } // If writeKey does not exist, set "default" value at the key. if !keysExist[writeKey] { err = params.SetValues(params.Context, map[string]interface{}{writeKey: "default"}) return []byte("+OK\r\n"), err } // Set the value from readKey to writeKey. err = params.SetValues(params.Context, map[string]interface{}{ writeKey: params.GetValues(params.Context, []string{readKey})[readKey], }) return []byte("+OK\r\n"), err } func main() { server, err := db.NewSugarDB() if err != nil { log.Fatal(err) } _, _ = server.MSet(map[string]string{ "key1": "value1", "key2": "value2", }) // Define the command options command := db.CommandOptions{ Command: "COPYDEFAULT", // Command keyword Module: "generic", // Add command to generic module, can be a new custom module. Categories: []string{"write", "fast"}, // Can be custom categories here. Description: `(COPYDEFAULT key1 key2) Copies the value from key1 to key2. If key1 does not exist, an error is returned. If key1 exists but key2 does not, the value "default" will be stored at key2. If both keys exist, the value from key1 will be copied to key2.`, Sync: true, KeyExtractionFunc: myKeyExtractionFunc, HandlerFunc: myCommandHandler, } // Add the command. err = server.AddCommand(command) if err != nil { fmt.Println("Error adding command:", err) } else { fmt.Println("Command added successfully") } } ``` -------------------------------- ### Pull SugarDB Docker Image Source: https://github.com/echovault/sugardb/blob/main/README.md Command to pull the SugarDB container image from the GitHub Container Registry. This allows users to quickly get started with SugarDB in a containerized environment. ```Shell docker pull ghcr.io/echovault/sugardb ``` -------------------------------- ### HELLO Command Syntax and Parameters Source: https://github.com/echovault/sugardb/blob/main/docs/docs/commands/connection/hello.mdx Defines the full syntax of the HELLO command, including optional parameters for protocol version, user authentication, and setting a client-specific connection name. It also lists the purpose of each parameter. ```APIDOC HELLO [protover [AUTH username password] [SETNAME clientname]] Options: - protover: The protocol version to switch to. The default is 2. - AUTH username password: Authenticate with the server using the specified username and password. - SETNAME clientname: Set the connection's name to the specified clientname. ```