diff --git a/config/config.go b/config/config.go index b35881384..00a76897e 100644 --- a/config/config.go +++ b/config/config.go @@ -47,33 +47,33 @@ func init() { var Config *DiceDBConfig type DiceDBConfig struct { - Host string `mapstructure:"host" default:"0.0.0.0" description:"the host address to bind to"` - Port int `mapstructure:"port" default:"7379" description:"the port to bind to"` - - Username string `mapstructure:"username" default:"dicedb" description:"the username to use for authentication"` - Password string `mapstructure:"password" default:"" description:"the password to use for authentication"` - - LogLevel string `mapstructure:"log-level" default:"info" description:"the log level"` - - EnableWatch bool `mapstructure:"enable-watch" default:"false" description:"enable support for .WATCH commands and real-time reactivity"` - MaxClients int `mapstructure:"max-clients" default:"20000" description:"the maximum number of clients to accept"` - NumShards int `mapstructure:"num-shards" default:"-1" description:"number of shards to create. defaults to number of cores"` - - Engine string `mapstructure:"engine" default:"ironhawk" description:"the engine to use, values: ironhawk"` - - EnableWAL bool `mapstructure:"enable-wal" default:"false" description:"enable write-ahead logging"` - WALDir string `mapstructure:"wal-dir" default:"/var/log/dicedb" description:"the directory to store WAL segments"` - WALMode string `mapstructure:"wal-mode" default:"buffered" description:"wal mode to use, values: buffered, unbuffered"` - WALWriteMode string `mapstructure:"wal-write-mode" default:"default" description:"wal file write mode to use, values: default, fsync"` - WALBufferSizeMB int `mapstructure:"wal-buffer-size-mb" default:"1" description:"the size of the wal write buffer in megabytes"` - WALRotationMode string `mapstructure:"wal-rotation-mode" default:"segment-size" description:"wal rotation mode to use, values: segment-size, time"` - WALMaxSegmentSizeMB int `mapstructure:"wal-max-segment-size-mb" default:"16" description:"the maximum size of a wal segment file in megabytes before rotation"` - WALMaxSegmentRotationTimeSec int `mapstructure:"wal-max-segment-rotation-time-sec" default:"60" description:"the time interval (in seconds) after which wal a segment is rotated"` - WALBufferSyncIntervalMillis int `mapstructure:"wal-buffer-sync-interval-ms" default:"200" description:"the interval (in milliseconds) at which the wal write buffer is synced to disk"` - WALRetentionMode string `mapstructure:"wal-retention-mode" default:"num-segments" description:"the new horizon for wal segment post cleanup. values: num-segments, time, checkpoint"` - WALMaxSegmentCount int `mapstructure:"wal-max-segment-count" default:"10" description:"the maximum number of segments to retain, if the retention mode is 'num-segments'"` - WALMaxSegmentRetentionDurationSec int `mapstructure:"wal-max-segment-retention-duration-sec" default:"600" description:"the maximum duration (in seconds) for wal segments retention"` - WALRecoveryMode string `mapstructure:"wal-recovery-mode" default:"strict" description:"wal recovery mode in case of a corruption, values: strict, truncate, ignore"` + Host string `mapstructure:"host" default:"0.0.0.0" description:"The host address to bind to"` + Port int `mapstructure:"port" default:"7379" description:"The port to bind to"` + + Username string `mapstructure:"username" default:"dicedb" description:"The username to use for authentication"` + Password string `mapstructure:"password" default:"" description:"The password to use for authentication"` + + LogLevel string `mapstructure:"log-level" default:"info" description:"The log level"` + + EnableWatch bool `mapstructure:"enable-watch" default:"false" description:"Enable support for .WATCH commands and real-time reactivity"` + MaxClients int `mapstructure:"max-clients" default:"20000" description:"The maximum number of clients to accept"` + NumShards int `mapstructure:"num-shards" default:"-1" description:"Number of shards to create. defaults to number of cores"` + + Engine string `mapstructure:"engine" default:"ironhawk" description:"The engine to use" values:"ironhawk"` + + EnableWAL bool `mapstructure:"enable-wal" default:"false" description:"Enable write-ahead logging"` + WALDir string `mapstructure:"wal-dir" default:"/var/log/dicedb" description:"The directory to store WAL segments"` + WALMode string `mapstructure:"wal-mode" default:"buffered" description:"WAL mode to use" values:"buffered, unbuffered"` + WALWriteMode string `mapstructure:"wal-write-mode" default:"default" description:"WAL write mode to use" values:"default, fsync"` + WALBufferSizeMB int `mapstructure:"wal-buffer-size-mb" default:"1" description:"The size of the WAL write buffer in megabytes"` + WALRotationMode string `mapstructure:"wal-rotation-mode" default:"segment-size" description:"WAL rotation mode to use" values:"segment-size, time"` + WALMaxSegmentSizeMB int `mapstructure:"wal-max-segment-size-mb" default:"16" description:"The maximum size of a WAL segment file in megabytes before rotation"` + WALMaxSegmentRotationTimeSec int `mapstructure:"wal-max-segment-rotation-time-sec" default:"60" description:"The time interval (in seconds) after which WAL a segment is rotated"` + WALBufferSyncIntervalMillis int `mapstructure:"wal-buffer-sync-interval-ms" default:"200" description:"The interval (in milliseconds) at which The WAL write buffer is synced to disk"` + WALRetentionMode string `mapstructure:"wal-retention-mode" default:"num-segments" description:"The new horizon for WAL segment post cleanup" values:"num-segments, time, checkpoint"` + WALMaxSegmentCount int `mapstructure:"wal-max-segment-count" default:"10" description:"The maximum number of segments to retain, if the retention mode is 'num-segments'"` + WALMaxSegmentRetentionDurationSec int `mapstructure:"wal-max-segment-retention-duration-sec" default:"600" description:"The maximum duration (in seconds) for WAL segments retention"` + WALRecoveryMode string `mapstructure:"wal-recovery-mode" default:"strict" description:"WAL recovery mode in case of a corruption" values:"strict, truncate, ignore"` } func Load(flags *pflag.FlagSet) { diff --git a/docs/astro.config.mjs b/docs/astro.config.mjs index 32f8e5bd8..60dc14356 100644 --- a/docs/astro.config.mjs +++ b/docs/astro.config.mjs @@ -33,6 +33,10 @@ export default defineConfig({ label: "Get started", autogenerate: { directory: "get-started" }, }, + { + label: "Server Configurations", + autogenerate: { directory: "server-configs" }, + }, { label: "SDK", autogenerate: { directory: "sdk" }, diff --git a/docs/src/content/docs/commands/GETSET.md b/docs/src/content/docs/commands/GETSET.md new file mode 100644 index 000000000..a2c494d12 --- /dev/null +++ b/docs/src/content/docs/commands/GETSET.md @@ -0,0 +1,34 @@ +--- +title: GETSET +description: GETSET sets the value for the key and returns the old value +--- + + + +#### Syntax + +``` +GETSET key value +``` + + +GETSET sets the value for the key and returns the old value. + +The command returns (nil) if the key does not exist. + + +#### Examples + +``` + +localhost:7379> SET k1 v1 +OK OK +localhost:7379> GETSET k1 v2 +OK v1 +localhost:7379> GET k1 +OK v2 + +``` diff --git a/docs/src/content/docs/commands/HANDSHAKE.md b/docs/src/content/docs/commands/HANDSHAKE.md index c19528f75..6dec6e603 100644 --- a/docs/src/content/docs/commands/HANDSHAKE.md +++ b/docs/src/content/docs/commands/HANDSHAKE.md @@ -14,6 +14,7 @@ description: HANDSHAKE tells the server the purpose of the connection HANDSHAKE client_id execution_mode ``` + HANDSHAKE is used to tell the DiceDB server the purpose of the connection. It registers the client_id and execution_mode. @@ -27,6 +28,7 @@ The execution_mode is the mode of the connection, it can be one of the following If you use DiceDB SDK or CLI then this HANDSHAKE command is automatically sent when the connection is established or when you establish a subscription. + #### Examples @@ -34,5 +36,5 @@ or when you establish a subscription. localhost:7379> HANDSHAKE 4c9d0411-6b28-4ee5-b78a-e7e258afa52f command OK OK - + ``` diff --git a/docs/src/content/docs/commands/HGET.WATCH.md b/docs/src/content/docs/commands/HGET.WATCH.md new file mode 100644 index 000000000..ea817641a --- /dev/null +++ b/docs/src/content/docs/commands/HGET.WATCH.md @@ -0,0 +1,43 @@ +--- +title: HGET.WATCH +description: HGET.WATCH creates a query subscription over the HGET command +--- + + + +#### Syntax + +``` +HGET.WATCH key field +``` + + +HGET.WATCH creates a query subscription over the HGET command. The client invoking the command +will receive the output of the HGET command (not just the notification) whenever the value against +the key and field is updated. + +You can update the key in any other client. The HGET.WATCH client will receive the updated value. + + +#### Examples + +``` + +client1:7379> HSET k1 f1 v1 +OK 1 +client1:7379> HGET.WATCH k1 f1 +entered the watch mode for HGET.WATCH k1 f1 + + +client2:7379> HSET k1 f1 v2 +OK 0 + + +client1:7379> ... +entered the watch mode for HGET.WATCH k1 f1 +OK [fingerprint=3432795955] v2 + +``` diff --git a/docs/src/content/docs/commands/KEYS.md b/docs/src/content/docs/commands/KEYS.md new file mode 100644 index 000000000..f9d958b75 --- /dev/null +++ b/docs/src/content/docs/commands/KEYS.md @@ -0,0 +1,50 @@ +--- +title: KEYS +description: KEYS returns all keys matching the pattern +--- + + + +#### Syntax + +``` +KEYS pattern +``` + + +KEYS returns all keys matching the pattern. + +The pattern can contain the following special characters to match multiple keys. +Supports glob-style patterns: +- *: matches any sequence of characters +- ?: matches any single character + +#### Examples + +``` + +localhost:7379> SET k1 v1 +OK OK +localhost:7379> SET k2 v2 +OK OK +localhost:7379> SET k33 v33 +OK OK +localhost:7379> KEYS k? +OK +1) "k1" +2) "k2" +localhost:7379> KEYS k* +OK +1) "k1" +2) "k2" +3) "k33" +localhost:7379> KEYS * +OK +1) "k1" +2) "k2" +3) "k33" + +``` diff --git a/docs/src/content/docs/commands/SET.md b/docs/src/content/docs/commands/SET.md index 8f0320122..e40441792 100644 --- a/docs/src/content/docs/commands/SET.md +++ b/docs/src/content/docs/commands/SET.md @@ -11,7 +11,7 @@ description: SET puts or updates an existing pair #### Syntax ``` -SET key value [EX seconds] [PX milliseconds] [EXAT timestamp] [PXAT timestamp] [XX] [NX] [KEEPTTL] +SET key value [EX seconds] [PX milliseconds] [EXAT timestamp] [PXAT timestamp] [XX] [NX] [KEEPTTL] [GET] ``` diff --git a/docs/src/content/docs/commands/ZADD.md b/docs/src/content/docs/commands/ZADD.md new file mode 100644 index 000000000..bb4b6a912 --- /dev/null +++ b/docs/src/content/docs/commands/ZADD.md @@ -0,0 +1,47 @@ +--- +title: ZADD +description: ZADD adds all the specified members with the specified scores to the sorted set stored at key +--- + + + +#### Syntax + +``` +ZADD key [NX | XX] [GT | LT] [CH] [INCR] score member [score member...] +``` + + +ZADD adds all the specified members with the specified scores to the sorted set stored at key + +- NX: Only add new elements and do not update existing elements +- XX: Only update existing elements and do not add new elements +- GT: Only add new elements if the score is greater than the existing score +- LT: Only add new elements if the score is less than the existing score +- CH: Modify the return value from the number of new elements added to the total number of elements changed +- INCR: When this option is specified, the scores provided are treated as increments to the score of the existing elements + +The command by default returns the number of elements added to the sorted set. + + +#### Examples + +``` + +localhost:7379> ZADD users 10 u1 +OK 1 +localhost:7379> ZADD users 5 u2 +OK 1 +localhost:7379> ZADD users 15 u3 +OK 1 +localhost:7379> ZADD users 12 u4 +OK 1 +localhost:7379> ZADD users 10 u1 +OK 0 +localhost:7379> ZADD users CH 11 u1 +OK 1 + +``` diff --git a/docs/src/content/docs/commands/ZCOUNT.md b/docs/src/content/docs/commands/ZCOUNT.md new file mode 100644 index 000000000..c83c9684d --- /dev/null +++ b/docs/src/content/docs/commands/ZCOUNT.md @@ -0,0 +1,47 @@ +--- +title: ZCOUNT +description: ZCOUNT counts the number of members in a sorted set between min and max (both inclusive) +--- + + + +#### Syntax + +``` +ZCOUNT key min max +``` + + +ZCOUNT counts the number of members in a sorted set between min and max (both inclusive) + +If you want to use unbounded ranges, use -inf and +inf for min and max respectively. +The command returns the count of members in a sorted set between min and max (both inclusive). Returns 0 if the key does not exist. + + +#### Examples + +``` + +localhost:7379> ZADD k 10 k1 +OK 1 +localhost:7379> ZADD k 20 k2 +OK 1 +localhost:7379> ZADD k 30 k3 +OK 1 +localhost:7379> ZCOUNT k 10 20 +OK 2 +localhost:7379> ZCOUNT k 10 30 +OK 3 +localhost:7379> ZCOUNT k 10 40 +OK 3 +localhost:7379> ZCOUNT k 1 2 +OK 0 +localhost:7379> ZCOUNT k -inf +inf +OK 3 +localhost:7379> ZCOUNT k 10 10 +OK 1 + +``` diff --git a/docs/src/content/docs/commands/ZRANGE.md b/docs/src/content/docs/commands/ZRANGE.md new file mode 100644 index 000000000..9873f0a85 --- /dev/null +++ b/docs/src/content/docs/commands/ZRANGE.md @@ -0,0 +1,31 @@ +--- +title: ZRANGE +description: Returns the specified range of elements in the sorted set stored at . +--- + + + +#### Syntax + +``` +ZRANGE key start stop [REV] [WITHSCORES] +``` + + +Returns the specified range of elements in the sorted set stored at key. +The elements are considered to be ordered from the lowest to the highest score. +Both start and stop are 0-based indexes, where 0 is the first element, 1 is the next element and so on. +These indexes can also be negative numbers indicating offsets from the end of the sorted set, with -1 being the last element of the sorted set, -2 the penultimate element and so on. +Returns the specified range of elements in the sorted set. + + +#### Examples + +``` + +localhost:7379> ZRANGE mySortedSet 1 3 + +``` diff --git a/docs/src/content/docs/server-configs/Configuration.md b/docs/src/content/docs/server-configs/Configuration.md new file mode 100644 index 000000000..b2f43f206 --- /dev/null +++ b/docs/src/content/docs/server-configs/Configuration.md @@ -0,0 +1,58 @@ +--- +title: Configuration +description: Configuration options for the server. +--- + + + +#### Server Config + +``` + EnableWAL = mapstructure:"enable-wal" default:"false" description:"Enable write-ahead logging" + + EnableWatch = mapstructure:"enable-watch" default:"false" description:"Enable support for .WATCH commands and real-time reactivity" + + Engine = mapstructure:"engine" default:"ironhawk" description:"The engine to use" values:"ironhawk" + + Host = mapstructure:"host" default:"0.0.0.0" description:"The host address to bind to" + + LogLevel = mapstructure:"log-level" default:"info" description:"The log level" + + MaxClients = mapstructure:"max-clients" default:"20000" description:"The maximum number of clients to accept" + + NumShards = mapstructure:"num-shards" default:"-1" description:"Number of shards to create. defaults to number of cores" + + Password = mapstructure:"password" default:"" description:"The password to use for authentication" + + Port = mapstructure:"port" default:"7379" description:"The port to bind to" + + Username = mapstructure:"username" default:"dicedb" description:"The username to use for authentication" + + WALBufferSizeMB = mapstructure:"wal-buffer-size-mb" default:"1" description:"The size of the WAL write buffer in megabytes" + + WALBufferSyncIntervalMillis = mapstructure:"wal-buffer-sync-interval-ms" default:"200" description:"The interval (in milliseconds) at which The WAL write buffer is synced to disk" + + WALDir = mapstructure:"wal-dir" default:"/var/log/dicedb" description:"The directory to store WAL segments" + + WALMaxSegmentCount = mapstructure:"wal-max-segment-count" default:"10" description:"The maximum number of segments to retain, if the retention mode is 'num-segments'" + + WALMaxSegmentRetentionDurationSec = mapstructure:"wal-max-segment-retention-duration-sec" default:"600" description:"The maximum duration (in seconds) for WAL segments retention" + + WALMaxSegmentRotationTimeSec = mapstructure:"wal-max-segment-rotation-time-sec" default:"60" description:"The time interval (in seconds) after which WAL a segment is rotated" + + WALMaxSegmentSizeMB = mapstructure:"wal-max-segment-size-mb" default:"16" description:"The maximum size of a WAL segment file in megabytes before rotation" + + WALMode = mapstructure:"wal-mode" default:"buffered" description:"WAL mode to use" values:"buffered, unbuffered" + + WALRecoveryMode = mapstructure:"wal-recovery-mode" default:"strict" description:"WAL recovery mode in case of a corruption" values:"strict, truncate, ignore" + + WALRetentionMode = mapstructure:"wal-retention-mode" default:"num-segments" description:"The new horizon for WAL segment post cleanup" values:"num-segments, time, checkpoint" + + WALRotationMode = mapstructure:"wal-rotation-mode" default:"segment-size" description:"WAL rotation mode to use" values:"segment-size, time" + + WALWriteMode = mapstructure:"wal-write-mode" default:"default" description:"WAL write mode to use" values:"default, fsync" + +``` diff --git a/scripts/generate-docs/main.go b/scripts/generate-docs/main.go index 10199ddd9..0416d3163 100644 --- a/scripts/generate-docs/main.go +++ b/scripts/generate-docs/main.go @@ -6,12 +6,15 @@ package main import ( "fmt" "os" + "reflect" "text/template" + "github.com/dicedb/dice/config" "github.com/dicedb/dice/internal/cmd" ) const DocsCommandsDirectory = "docs/src/content/docs/commands" +const ServerConfigDirectory = "docs/src/content/docs/server-configs" func generateDocs(tmpl *template.Template, c *cmd.CommandMeta) { docFile, err := os.Create(fmt.Sprintf("%s/%s.md", DocsCommandsDirectory, c.Name)) @@ -26,13 +29,36 @@ func generateDocs(tmpl *template.Template, c *cmd.CommandMeta) { } } +func generateServerParamtersDocs(tmpl *template.Template) { + typeOf := reflect.TypeOf(&config.DiceDBConfig{}).Elem() + serverConifigMeta := make(map[string]string) + for i := 0; i < typeOf.NumField(); i++ { + field := typeOf.Field(i) + serverConifigMeta[field.Name] = string(field.Tag) + } + + docFile, err := os.Create(fmt.Sprintf("%s/%s.md", ServerConfigDirectory, "Configuration")) + if err != nil { + fmt.Printf("ERR: error creating file: %v\n", err) + } + defer docFile.Close() + + err = tmpl.Execute(docFile, serverConifigMeta) + if err != nil { + fmt.Printf("ERR: error executing template: %v\n", err) + } +} + + + func main() { tmpl := template.Must(template.ParseFiles("scripts/generate-docs/doc.tmpl")) for _, c := range cmd.CommandRegistry.CommandMetas { if c.HelpLong == "" { continue } - generateDocs(tmpl, c) } + sctmpl := template.Must(template.ParseFiles("scripts/generate-docs/server-config.tmpl")) + generateServerParamtersDocs(sctmpl) } diff --git a/scripts/generate-docs/server-config.tmpl b/scripts/generate-docs/server-config.tmpl new file mode 100644 index 000000000..2306963f8 --- /dev/null +++ b/scripts/generate-docs/server-config.tmpl @@ -0,0 +1,17 @@ +--- +title: Configuration +description: Configuration options for the server. +--- + + + +#### Server Config + +``` +{{- range $key, $value := . }} + {{$key}} = {{$value}} +{{end}} +```