[feat] add pkgs, dockerfile, makefile
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package redis
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/go-redis/redis"
|
||||
)
|
||||
|
||||
const (
|
||||
KeyToken = "91-token:%s"
|
||||
)
|
||||
|
||||
type Redis struct {
|
||||
*redis.Client
|
||||
prefix string
|
||||
}
|
||||
|
||||
var r *Redis
|
||||
|
||||
// Init redis client
|
||||
func Init(port int, host, prefix string) error {
|
||||
r = &Redis{prefix: prefix}
|
||||
r.Client = redis.NewClient(&redis.Options{
|
||||
Addr: fmt.Sprintf("%s:%d", host, port),
|
||||
})
|
||||
|
||||
if _, err := r.Ping().Result(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Key combine prefix to key
|
||||
func (x *Redis) Key(key string) string {
|
||||
if len(x.prefix) > 0 {
|
||||
return fmt.Sprintf("%s:%s", x.prefix, key)
|
||||
}
|
||||
return key
|
||||
}
|
||||
Reference in New Issue
Block a user