Changed redis client
This commit is contained in:
parent
73e6312699
commit
f811aeb827
8 changed files with 31 additions and 28 deletions
|
@ -5,17 +5,17 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func StatsIncreaseTotalLinks() (int, error) {
|
func StatsIncreaseTotalLinks() (int, error) {
|
||||||
val, err := Client.Get(ctx, "total-links").Result()
|
val, err := Client_redis().Get(ctx, "total-links").Result()
|
||||||
|
|
||||||
if err != nil {
|
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 {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i, _ := strconv.Atoi(val)
|
i, _ := strconv.Atoi(val)
|
||||||
i++
|
i++
|
||||||
err = Client.Set(ctx, "total-links", i, 0).Err()
|
err = Client_redis().Set(ctx, "total-links", i, 0).Err()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,17 +5,17 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func StatsIncreaseViewsLinks() (int, error) {
|
func StatsIncreaseViewsLinks() (int, error) {
|
||||||
val, err := Client.Get(ctx, "total-views").Result()
|
val, err := Client_redis().Get(ctx, "total-views").Result()
|
||||||
|
|
||||||
if err != nil {
|
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 {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i, _ := strconv.Atoi(val)
|
i, _ := strconv.Atoi(val)
|
||||||
i++
|
i++
|
||||||
err = Client.Set(ctx, "total-views", i, 0).Err()
|
err = Client_redis().Set(ctx, "total-views", i, 0).Err()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
package db
|
package db
|
||||||
|
|
||||||
func Get(input string) (string, error) {
|
func Get(input string) (string, error) {
|
||||||
return Client.Get(ctx, input).Result()
|
return Client_redis().Get(ctx, input).Result()
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetTotalLinks() int {
|
func GetTotalLinks() int {
|
||||||
val1, err1 := Client.Get(ctx, "total-links").Result()
|
val1, err1 := Client_redis().Get(ctx, "total-links").Result()
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ func GetTotalLinks() int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTotalViews() int {
|
func GetTotalViews() int {
|
||||||
val1, err1 := Client.Get(ctx, "total-views").Result()
|
val1, err1 := Client_redis().Get(ctx, "total-views").Result()
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,5 +3,5 @@ package db
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
func Set(key string, value interface{}, time time.Duration) error {
|
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()
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,14 +10,17 @@ import (
|
||||||
|
|
||||||
var ctx = context.Background()
|
var ctx = context.Background()
|
||||||
|
|
||||||
|
func Client_redis() *redis.Client {
|
||||||
var Client *redis.Client = redis.NewClient(&redis.Options{
|
var Client *redis.Client = redis.NewClient(&redis.Options{
|
||||||
Addr: utils.REDIS_URI, // use default Addr
|
Addr: utils.REDIS_URI, // use default Addr
|
||||||
Password: "", // no password set
|
Password: "", // no password set
|
||||||
DB: 0, // use default DB
|
DB: 0, // use default DB
|
||||||
})
|
})
|
||||||
|
return Client
|
||||||
|
}
|
||||||
|
|
||||||
func Init_redis() {
|
func Init_redis() {
|
||||||
_, err := Client.Ping(ctx).Result()
|
_, err := Client_redis().Ping(ctx).Result()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err.Error())
|
log.Fatal(err.Error())
|
||||||
|
|
|
@ -4,12 +4,12 @@ services:
|
||||||
# build: . # Only if you want to Build the image on your own Server!
|
# build: . # Only if you want to Build the image on your own Server!
|
||||||
image: registry.ucode.space/phil/goshorly:latest
|
image: registry.ucode.space/phil/goshorly:latest
|
||||||
environment:
|
environment:
|
||||||
- HOST="127.0.0.1" # Domain or IP-Adress
|
- HOST=127.0.0.1 # Domain or IP-Adress
|
||||||
- PORT="3000" # The Port you want to use
|
- PORT=3000 # The Port you want to use
|
||||||
- HTTPS="true" # If you want to use HTTPS
|
- HTTPS=true # If you want to use HTTPS
|
||||||
- PROXY="true" # If you want to use a Reverse Proxy
|
- PROXY=true # If you want to use a Reverse Proxy
|
||||||
- REDIS_URI="redis" # The Redis-URI (name of redis container OOTB)
|
- REDIS_URI=redis # The Redis-URI (name of redis container OOTB)
|
||||||
- ENABLE_STATS="true" # Enables the /stats public frontend
|
- ENABLE_STATS=true # Enables the /stats public frontend
|
||||||
depends_on:
|
depends_on:
|
||||||
- redis
|
- redis
|
||||||
restart: always
|
restart: always
|
||||||
|
|
|
@ -4,12 +4,12 @@ services:
|
||||||
# build: . # Only if you want to Build the image on your own Server!
|
# build: . # Only if you want to Build the image on your own Server!
|
||||||
image: registry.ucode.space/phil/goshorly:latest
|
image: registry.ucode.space/phil/goshorly:latest
|
||||||
environment:
|
environment:
|
||||||
- HOST="127.0.0.1" # Domain or IP-Adress
|
- HOST=127.0.0.1 # Domain or IP-Adress
|
||||||
- PORT="3000" # The Port you want to use
|
- PORT=3000 # The Port you want to use
|
||||||
- HTTPS="false" # If you want to use HTTPS
|
- HTTPS=false # If you want to use HTTPS
|
||||||
- PROXY="false" # If you want to use a Reverse Proxy
|
- PROXY=false # If you want to use a Reverse Proxy
|
||||||
- REDIS_URI="redis" # The Redis-URI (name of redis container OOTB)
|
- REDIS_URI=redis:6379 # The Redis-URI (name of redis container OOTB)
|
||||||
- ENABLE_STATS="true" # Enables the /stats public frontend (Default: true)
|
- ENABLE_STATS=true # Enables the /stats public frontend (Default: true)
|
||||||
ports:
|
ports:
|
||||||
- "3000:3000"
|
- "3000:3000"
|
||||||
depends_on:
|
depends_on:
|
||||||
|
|
Loading…
Reference in a new issue