Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions db/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ type Config struct {

// MaxMemory is the maximum memory limit in bytes. 0 means unlimited.
MaxMemory int64

// Port is the TCP port the server is listening on. Set once at startup from
// the --port flag; read-only at runtime (changing it would require a rebind).
Port int
}

// ServerConfig is the package-level config instance used across the server.
var ServerConfig = &Config{
Hz: 1,
ActiveExpireEnabled: true,
MaxMemory: 0,
Port: 6378,
}

// CleanupInterval returns the active expiry ticker interval derived from Hz.
Expand All @@ -50,6 +55,8 @@ func (c *Config) Get(param string) (string, bool) {
return boolToYesNo(c.ActiveExpireEnabled), true
case "maxmemory":
return itoa64(c.MaxMemory), true
case "port":
return itoa(c.Port), true
}
return "", false
}
Expand Down
15 changes: 10 additions & 5 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ CONFIG SET parameter value

## Supported parameters

| Parameter | Type | Default | Description |
|-------------------------|---------|---------|----------------------------------------------------------|
| `hz` | integer | `1` | Number of active expiry cycles per second. Must be > 0. |
| `active-expire-enabled` | yes/no | `yes` | Enable or disable the active expiry background job. |
| `maxmemory` | integer | `0` | Max memory in bytes. `0` means unlimited. |
| Parameter | Type | Default | Writable | Description |
|-------------------------|---------|---------|----------|----------------------------------------------------------|
| `hz` | integer | `1` | yes | Number of active expiry cycles per second. Must be > 0. |
| `active-expire-enabled` | yes/no | `yes` | yes | Enable or disable the active expiry background job. |
| `maxmemory` | integer | `0` | yes | Max memory in bytes. `0` means unlimited. |
| `port` | integer | `6378` | no | TCP port the server is listening on. Set via `--port` flag at startup. |

## Return value

Expand Down Expand Up @@ -74,4 +75,8 @@ maxmemory

> CONFIG SET maxmemory 1073741824
OK

> CONFIG GET port
port
6378
```
12 changes: 10 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@ package main
import (
"HelixDB/db"
"HelixDB/resp"
"flag"
"fmt"
"net"
"os"
)

func main() {
l, err := net.Listen("tcp", "0.0.0.0:6378")
port := flag.Int("port", 6378, "Port to listen on")
flag.IntVar(port, "p", *port, "Port to listen on (shorthand)")
flag.Parse()

db.ServerConfig.Port = *port

addr := fmt.Sprintf("0.0.0.0:%d", *port)
l, err := net.Listen("tcp", addr)
if err != nil {
fmt.Println("Failed to bind to port 6378")
fmt.Printf("Failed to bind to port %d\n", *port)
os.Exit(1)
}
defer l.Close()
Expand Down
Loading