You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bit4sat/db/db.go

53 lines
847 B
Go

package db
import (
"fmt"
"log"
"os"
"strconv"
"strings"
"github.com/mediocregopher/radix/v3"
"github.com/mediocregopher/radix/v3/resp/resp2"
)
const (
RedisHost = "redis"
RedisHostEnv = "REDIS_HOST"
RedisPort = 6379
)
var (
RuntimeRedisHost string
DB *radix.Pool
)
func RedisMarshal(v interface{}) string {
data := resp2.Any{
I: v,
MarshalBulkString: true,
MarshalNoArrayHeaders: true,
}
marshalled := &strings.Builder{}
data.MarshalRESP(marshalled)
return marshalled.String()
}
func init() {
var err error
RuntimeRedisHost, set := os.LookupEnv(RedisHostEnv)
if !set {
RuntimeRedisHost = RedisHost
}
redisLoc := fmt.Sprintf("%s:%s", RuntimeRedisHost, strconv.Itoa(RedisPort))
DB, err = radix.NewPool("tcp", redisLoc, 10)
if err != nil {
log.Fatal(err)
}
}