github.com/Laplace-Game-Development/Laplace-Entangled-Environment@v0.0.3/internal/redis/redis.go (about) 1 package redis 2 3 import ( 4 "log" 5 6 "github.com/mediocregopher/radix/v3" 7 ) 8 9 //// Redis/DB Settings 10 11 // Redis IP Connecting Address 12 const RedisIpAddress string = "127.0.0.1" 13 14 // Redis Connection Port Number 15 const RedisPortNumber string = ":6379" 16 17 // The Maximum Length of a String Key Redis can receive 18 const RedisKeyMax int = 512000000 19 20 //// Global Variables | Singletons 21 22 // Global Reference for Redis -- Threadsafe 23 var MainRedis radix.Client = nil 24 25 // ServerTask Startup Function for Redis Database. Takes care of initialization. 26 func StartDatabase() (func(), error) { 27 // Ah yes! A Thread safe pool implementation. PERRRRFECT 28 pool, err := radix.NewPool("tcp", RedisIpAddress+RedisPortNumber, 10) 29 if err != nil { 30 return nil, err 31 } 32 33 MainRedis = pool 34 35 err = MainRedis.Do(radix.Cmd(log.Writer(), "PING", "REDIS HAS BEEN PINGED!\n")) 36 if err != nil { 37 return nil, err 38 } 39 40 return cleanUpDatabase, nil 41 } 42 43 // CleanUp Function returned by Startup function. Closes the Redis Client 44 func cleanUpDatabase() { 45 log.Println("Cleaning Up Database Logic") 46 MainRedis.Close() 47 }