Add gRPC server implementation and database integration for marketplace and products
This commit is contained in:
36
internal/redis/client.go
Normal file
36
internal/redis/client.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package redis
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/redis/rueidis"
|
||||
"os"
|
||||
)
|
||||
|
||||
var Client *rueidis.Client
|
||||
|
||||
func InitClient(ctx context.Context) error {
|
||||
var err error
|
||||
host := os.Getenv("REDIS_HOST")
|
||||
port := os.Getenv("REDIS_PORT")
|
||||
password := os.Getenv("REDIS_PASSWORD")
|
||||
|
||||
client, err := rueidis.NewClient(rueidis.ClientOption{
|
||||
InitAddress: []string{host + ":" + port},
|
||||
Password: password,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = client.Do(ctx, client.B().Ping().Build()).Error()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
Client = &client
|
||||
return nil
|
||||
}
|
||||
|
||||
func CloseClient() {
|
||||
if Client != nil {
|
||||
(*Client).Close()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user