-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (37 loc) · 1.01 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"fmt"
"log/slog"
"net"
"os"
"github.com/OmkarPh/redis-lite/config"
"github.com/OmkarPh/redis-lite/core"
"github.com/OmkarPh/redis-lite/store"
)
func main() {
fmt.Println("Redis-lite server v0.2")
fmt.Println("Port:", config.PORT, ", PID:", os.Getpid())
fmt.Println("Visit - https://github.com/OmkarPh/redis-server-lite")
fmt.Println()
slog.SetLogLoggerLevel(config.DefaultLoggerLevel)
listener, err := net.Listen("tcp", fmt.Sprintf(":%d", config.PORT))
if err != nil {
slog.Error("Error starting server", err)
return
}
defer listener.Close()
redisConfig := config.NewRedisConfig()
kvStore := store.NewKvStore(redisConfig)
go core.CleanExpiredKeys(kvStore)
fmt.Println()
for {
conn, err := listener.Accept()
if err != nil {
slog.Error("Error accepting connection", err)
return
}
slog.Debug(fmt.Sprint("Accept connection from", conn.RemoteAddr().String()))
// Handle the connection in a new goroutine.
go core.HandleConnection(conn, redisConfig, kvStore)
}
}