Changed redis client

This commit is contained in:
Phil 2022-01-25 19:14:09 +01:00
parent 73e6312699
commit f811aeb827
8 changed files with 31 additions and 28 deletions

View file

@ -5,17 +5,17 @@ import (
)
func StatsIncreaseTotalLinks() (int, error) {
val, err := Client.Get(ctx, "total-links").Result()
val, err := Client_redis().Get(ctx, "total-links").Result()
if err != nil {
err := Client.Set(ctx, "total-links", "0", 0).Err()
err := Client_redis().Set(ctx, "total-links", "0", 0).Err()
if err != nil {
return 0, err
}
}
i, _ := strconv.Atoi(val)
i++
err = Client.Set(ctx, "total-links", i, 0).Err()
err = Client_redis().Set(ctx, "total-links", i, 0).Err()
if err != nil {
return 0, err
}

View file

@ -5,17 +5,17 @@ import (
)
func StatsIncreaseViewsLinks() (int, error) {
val, err := Client.Get(ctx, "total-views").Result()
val, err := Client_redis().Get(ctx, "total-views").Result()
if err != nil {
err := Client.Set(ctx, "total-views", "0", 0).Err()
err := Client_redis().Set(ctx, "total-views", "0", 0).Err()
if err != nil {
return 0, err
}
}
i, _ := strconv.Atoi(val)
i++
err = Client.Set(ctx, "total-views", i, 0).Err()
err = Client_redis().Set(ctx, "total-views", i, 0).Err()
if err != nil {
return 0, err
}

View file

@ -1,5 +1,5 @@
package db
func Get(input string) (string, error) {
return Client.Get(ctx, input).Result()
return Client_redis().Get(ctx, input).Result()
}

View file

@ -5,7 +5,7 @@ import (
)
func GetTotalLinks() int {
val1, err1 := Client.Get(ctx, "total-links").Result()
val1, err1 := Client_redis().Get(ctx, "total-links").Result()
if err1 != nil {
return 0
}
@ -17,7 +17,7 @@ func GetTotalLinks() int {
}
func GetTotalViews() int {
val1, err1 := Client.Get(ctx, "total-views").Result()
val1, err1 := Client_redis().Get(ctx, "total-views").Result()
if err1 != nil {
return 0
}

View file

@ -3,5 +3,5 @@ package db
import "time"
func Set(key string, value interface{}, time time.Duration) error {
return Client.Set(ctx, key, value, time).Err()
return Client_redis().Set(ctx, key, value, time).Err()
}

View file

@ -10,14 +10,17 @@ import (
var ctx = context.Background()
var Client *redis.Client = redis.NewClient(&redis.Options{
func Client_redis() *redis.Client {
var Client *redis.Client = redis.NewClient(&redis.Options{
Addr: utils.REDIS_URI, // use default Addr
Password: "", // no password set
DB: 0, // use default DB
})
})
return Client
}
func Init_redis() {
_, err := Client.Ping(ctx).Result()
_, err := Client_redis().Ping(ctx).Result()
if err != nil {
log.Fatal(err.Error())

View file

@ -4,12 +4,12 @@ services:
# build: . # Only if you want to Build the image on your own Server!
image: registry.ucode.space/phil/goshorly:latest
environment:
- HOST="127.0.0.1" # Domain or IP-Adress
- PORT="3000" # The Port you want to use
- HTTPS="true" # If you want to use HTTPS
- PROXY="true" # If you want to use a Reverse Proxy
- REDIS_URI="redis" # The Redis-URI (name of redis container OOTB)
- ENABLE_STATS="true" # Enables the /stats public frontend
- HOST=127.0.0.1 # Domain or IP-Adress
- PORT=3000 # The Port you want to use
- HTTPS=true # If you want to use HTTPS
- PROXY=true # If you want to use a Reverse Proxy
- REDIS_URI=redis # The Redis-URI (name of redis container OOTB)
- ENABLE_STATS=true # Enables the /stats public frontend
depends_on:
- redis
restart: always

View file

@ -4,12 +4,12 @@ services:
# build: . # Only if you want to Build the image on your own Server!
image: registry.ucode.space/phil/goshorly:latest
environment:
- HOST="127.0.0.1" # Domain or IP-Adress
- PORT="3000" # The Port you want to use
- HTTPS="false" # If you want to use HTTPS
- PROXY="false" # If you want to use a Reverse Proxy
- REDIS_URI="redis" # The Redis-URI (name of redis container OOTB)
- ENABLE_STATS="true" # Enables the /stats public frontend (Default: true)
- HOST=127.0.0.1 # Domain or IP-Adress
- PORT=3000 # The Port you want to use
- HTTPS=false # If you want to use HTTPS
- PROXY=false # If you want to use a Reverse Proxy
- REDIS_URI=redis:6379 # The Redis-URI (name of redis container OOTB)
- ENABLE_STATS=true # Enables the /stats public frontend (Default: true)
ports:
- "3000:3000"
depends_on: