mirror of
				https://github.com/HDT3213/godis.git
				synced 2025-10-31 20:12:51 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			59 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			59 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package main
 | |
| 
 | |
| import (
 | |
| 	"fmt"
 | |
| 	"github.com/hdt3213/godis/config"
 | |
| 	"github.com/hdt3213/godis/lib/logger"
 | |
| 	RedisServer "github.com/hdt3213/godis/redis/server"
 | |
| 	"github.com/hdt3213/godis/tcp"
 | |
| 	"os"
 | |
| )
 | |
| 
 | |
| var banner = `
 | |
|    ______          ___
 | |
|   / ____/___  ____/ (_)____
 | |
|  / / __/ __ \/ __  / / ___/
 | |
| / /_/ / /_/ / /_/ / (__  )
 | |
| \____/\____/\__,_/_/____/
 | |
| `
 | |
| 
 | |
| var defaultProperties = &config.ServerProperties{
 | |
| 	Bind:           "0.0.0.0",
 | |
| 	Port:           6399,
 | |
| 	AppendOnly:     false,
 | |
| 	AppendFilename: "",
 | |
| 	MaxClients:     1000,
 | |
| }
 | |
| 
 | |
| func fileExists(filename string) bool {
 | |
| 	info, err := os.Stat(filename)
 | |
| 	return err == nil && !info.IsDir()
 | |
| }
 | |
| 
 | |
| func main() {
 | |
| 	print(banner)
 | |
| 	logger.Setup(&logger.Settings{
 | |
| 		Path:       "logs",
 | |
| 		Name:       "godis",
 | |
| 		Ext:        ".log",
 | |
| 		TimeFormat: "2006-01-02",
 | |
| 	})
 | |
| 	configFilename := os.Getenv("CONFIG")
 | |
| 	if configFilename == "" {
 | |
| 		if fileExists("redis.conf") {
 | |
| 			config.SetupConfig("redis.conf")
 | |
| 		} else {
 | |
| 			config.Properties = defaultProperties
 | |
| 		}
 | |
| 	} else {
 | |
| 		config.SetupConfig(configFilename)
 | |
| 	}
 | |
| 
 | |
| 	err := tcp.ListenAndServeWithSignal(&tcp.Config{
 | |
| 		Address: fmt.Sprintf("%s:%d", config.Properties.Bind, config.Properties.Port),
 | |
| 	}, RedisServer.MakeHandler())
 | |
| 	if err != nil {
 | |
| 		logger.Error(err)
 | |
| 	}
 | |
| }
 | 
