mirror of
https://github.com/eosswedenorg/thalos
synced 2026-06-19 04:50:02 +02:00
Move internal packages into internal subdirectory
This commit is contained in:
parent
770f0a48ef
commit
ddd5d67901
8 changed files with 6 additions and 6 deletions
|
|
@ -1,62 +0,0 @@
|
|||
package redis
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
_redis "github.com/go-redis/redis/v8"
|
||||
)
|
||||
|
||||
var rdb *_redis.Client
|
||||
|
||||
var redis_pipe _redis.Pipeliner
|
||||
|
||||
var redisCtx = context.Background()
|
||||
|
||||
var prefix []string
|
||||
|
||||
func Connect(addr string, password string, db int) error {
|
||||
rdb = _redis.NewClient(&_redis.Options{
|
||||
Addr: addr,
|
||||
Password: password,
|
||||
DB: db,
|
||||
})
|
||||
|
||||
redis_pipe = rdb.Pipeline()
|
||||
|
||||
return rdb.Ping(redisCtx).Err()
|
||||
}
|
||||
|
||||
func Client() *_redis.Client {
|
||||
return rdb
|
||||
}
|
||||
|
||||
func SetPrefix(components ...string) {
|
||||
prefix = components
|
||||
}
|
||||
|
||||
func Key(components ...string) string {
|
||||
components = append(prefix, components...)
|
||||
return strings.Join(components, ".")
|
||||
}
|
||||
|
||||
func Get(key string) *_redis.StringCmd {
|
||||
return rdb.Get(redisCtx, key)
|
||||
}
|
||||
|
||||
func Set(key string, value interface{}, expiration time.Duration) *_redis.StatusCmd {
|
||||
return rdb.Set(redisCtx, key, value, expiration)
|
||||
}
|
||||
|
||||
func Publish(channel string, message interface{}) *_redis.IntCmd {
|
||||
return rdb.Publish(redisCtx, channel, message)
|
||||
}
|
||||
|
||||
func RegisterPublish(channel string, message interface{}) *_redis.IntCmd {
|
||||
return redis_pipe.Publish(redisCtx, channel, message)
|
||||
}
|
||||
|
||||
func Send() ([]_redis.Cmder, error) {
|
||||
return redis_pipe.Exec(redisCtx)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue