add changes diffing modal & silence some logs
This commit is contained in:
parent
148488e2c4
commit
da353cec84
22 changed files with 1770 additions and 120 deletions
|
|
@ -4,7 +4,6 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
|
|
@ -27,7 +26,7 @@ func NewRedisClient(address, password string) *RedisCli {
|
|||
client := redis.NewClient(&options)
|
||||
|
||||
if err := client.Ping(context.Background()); err.Err() != nil {
|
||||
fmt.Println("trying localhost ...", err)
|
||||
// //fmt.Println("trying localhost ...", err)
|
||||
client = redis.NewClient(&redis.Options{
|
||||
Addr: "localhost:6379",
|
||||
Password: password,
|
||||
|
|
@ -35,13 +34,14 @@ func NewRedisClient(address, password string) *RedisCli {
|
|||
})
|
||||
|
||||
if err_local := client.Ping(context.Background()); err_local.Err() != nil {
|
||||
fmt.Println("> result ====> ", err_local)
|
||||
// //fmt.Println("> result ====> ", err_local)
|
||||
|
||||
// do as warning
|
||||
} else {
|
||||
fmt.Println("\n> Localhost Redis OK!\n")
|
||||
// //fmt.Println("\n> Localhost Redis OK!\n")
|
||||
}
|
||||
} else {
|
||||
fmt.Println("\n> Redis OK! \n")
|
||||
// //fmt.Println("\n> Redis OK! \n")
|
||||
}
|
||||
|
||||
return &RedisCli{
|
||||
|
|
@ -54,51 +54,51 @@ func (r *RedisCli) HealthCheck() error {
|
|||
}
|
||||
|
||||
func (r *RedisCli) GetKeyTo(source string, dest interface{}) error {
|
||||
fmt.Println("Redis> GET ", source)
|
||||
// //fmt.Println("Redis> GET ", source)
|
||||
|
||||
// if cannot pass healthcheck, return err
|
||||
if err := r.HealthCheck(); err != nil {
|
||||
fmt.Println("HS> GET error ", err)
|
||||
// //fmt.Println("HS> GET error ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
saved, err := r.Client.Get(context.Background(), source).Result()
|
||||
|
||||
// chcek EOF
|
||||
// fmt.Println("GET last char ", saved[len(saved)-1:])
|
||||
// //fmt.Println("GET last char ", saved[len(saved)-1:])
|
||||
|
||||
if saved == "" || err != nil {
|
||||
fmt.Println("GET error (empty on error)|", err, "|while saved=", saved)
|
||||
// //fmt.Println("GET error (empty on error)|", err, "|while saved=", saved)
|
||||
return err
|
||||
}
|
||||
|
||||
// fmt.Println("GET ", saved)
|
||||
// //fmt.Println("GET ", saved)
|
||||
|
||||
// if err != nil {
|
||||
// fmt.Println("GET error ", err)
|
||||
// //fmt.Println("GET error ", err)
|
||||
// return err
|
||||
// }
|
||||
err = json.NewDecoder(bytes.NewBufferString(saved)).Decode(dest)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("GET error ", err)
|
||||
// //fmt.Println("GET error ", err)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *RedisCli) SetToKey(key string, value interface{}) error {
|
||||
fmt.Println("Redis> SET ", key)
|
||||
// //fmt.Println("Redis> SET ", key)
|
||||
|
||||
// if cannot pass healthcheck, return err
|
||||
if err := r.HealthCheck(); err != nil {
|
||||
fmt.Println("HS> SET error ", err)
|
||||
// //fmt.Println("HS> SET error ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
saved, err := json.Marshal(value)
|
||||
if err != nil {
|
||||
fmt.Println("SET error ", err)
|
||||
//fmt.Println("SET error ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -106,7 +106,7 @@ func (r *RedisCli) SetToKey(key string, value interface{}) error {
|
|||
err = r.Client.Set(context.Background(), key, saved, redis.KeepTTL).Err()
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("error on SET ", err)
|
||||
//fmt.Println("error on SET ", err)
|
||||
}
|
||||
|
||||
return err
|
||||
|
|
@ -116,7 +116,7 @@ func (r *RedisCli) ExpireKey(key string) error {
|
|||
|
||||
// if cannot pass healthcheck, return err
|
||||
if err := r.HealthCheck(); err != nil {
|
||||
fmt.Println("HS> EXPIRE error ", err)
|
||||
//fmt.Println("HS> EXPIRE error ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -127,19 +127,19 @@ func (r *RedisCli) SetKeyTimeout(key string, value interface{}, timeout int) err
|
|||
|
||||
// if cannot pass healthcheck, return err
|
||||
if err := r.HealthCheck(); err != nil {
|
||||
fmt.Println("HS> EXPIRE error ", err)
|
||||
//fmt.Println("HS> EXPIRE error ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
err := r.Client.Expire(context.Background(), key, time.Duration(timeout)*time.Second).Err()
|
||||
fmt.Println("error on EXPIRE ", err)
|
||||
//fmt.Println("error on EXPIRE ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *RedisCli) KeyList() ([]string, error) {
|
||||
// if cannot pass healthcheck, return err
|
||||
if err := r.HealthCheck(); err != nil {
|
||||
fmt.Println("HS> KEYS error ", err)
|
||||
//fmt.Println("HS> KEYS error ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
@ -153,7 +153,7 @@ func (r *RedisCli) KeyList() ([]string, error) {
|
|||
func (r *RedisCli) GetList(key string) ([]string, error) {
|
||||
// if cannot pass healthcheck, return err
|
||||
if err := r.HealthCheck(); err != nil {
|
||||
fmt.Println("HS> List.GET error ", err)
|
||||
//fmt.Println("HS> List.GET error ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
@ -163,7 +163,7 @@ func (r *RedisCli) GetList(key string) ([]string, error) {
|
|||
func (r *RedisCli) Add(key string, value interface{}) error {
|
||||
// if cannot pass healthcheck, return err
|
||||
if err := r.HealthCheck(); err != nil {
|
||||
fmt.Println("HS> List.ADD error ", err)
|
||||
//fmt.Println("HS> List.ADD error ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue