mirror of
https://github.com/eosswedenorg/thalos
synced 2026-06-17 04:30:03 +02:00
Remove internal/redis/wrapper.go
This commit is contained in:
parent
b22118898d
commit
bcf55f1c12
3 changed files with 13 additions and 58 deletions
|
|
@ -5,10 +5,9 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"eosio-ship-trace-reader/internal/redis"
|
||||
|
||||
eos "github.com/eoscanada/eos-go"
|
||||
redis_cache "github.com/go-redis/cache/v8"
|
||||
"github.com/go-redis/redis/v8"
|
||||
)
|
||||
|
||||
type AbiManager struct {
|
||||
|
|
@ -17,10 +16,10 @@ type AbiManager struct {
|
|||
ctx context.Context
|
||||
}
|
||||
|
||||
func NewAbiManager(api *eos.API, id string) *AbiManager {
|
||||
func NewAbiManager(rdb *redis.Client, api *eos.API, id string) *AbiManager {
|
||||
// Init abi cache
|
||||
cache := NewCache("ship.cache."+id+".abi", &redis_cache.Options{
|
||||
Redis: redis.Client(),
|
||||
Redis: rdb,
|
||||
// Cache 10k keys for 10 minutes.
|
||||
LocalCache: redis_cache.NewTinyLFU(10000, 10*time.Minute),
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,50 +0,0 @@
|
|||
package redis
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
_redis "github.com/go-redis/redis/v8"
|
||||
)
|
||||
|
||||
var rdb *_redis.Client
|
||||
|
||||
var redis_pipe _redis.Pipeliner
|
||||
|
||||
var redisCtx = context.Background()
|
||||
|
||||
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 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)
|
||||
}
|
||||
14
main.go
14
main.go
|
|
@ -7,10 +7,10 @@ import (
|
|||
"os/signal"
|
||||
"time"
|
||||
|
||||
"github.com/go-redis/redis/v8"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"eosio-ship-trace-reader/config"
|
||||
"eosio-ship-trace-reader/internal/redis"
|
||||
"eosio-ship-trace-reader/transport"
|
||||
"eosio-ship-trace-reader/transport/redis_pubsub"
|
||||
|
||||
|
|
@ -219,14 +219,20 @@ func main() {
|
|||
notify.UseServices(telegram)
|
||||
|
||||
// Connect to redis
|
||||
err = redis.Connect(conf.Redis.Addr, conf.Redis.Password, conf.Redis.DB)
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: conf.Redis.Addr,
|
||||
Password: conf.Redis.Password,
|
||||
DB: conf.Redis.DB,
|
||||
})
|
||||
|
||||
err = rdb.Ping(context.Background()).Err()
|
||||
if err != nil {
|
||||
log.WithError(err).Fatal("Failed to connect to redis")
|
||||
return
|
||||
}
|
||||
|
||||
// Setup publisher
|
||||
publisher = redis_pubsub.New(redis.Client())
|
||||
publisher = redis_pubsub.New(rdb)
|
||||
|
||||
// Connect client and get chain info.
|
||||
log.Printf("Get chain info from api at: %s", conf.Api)
|
||||
|
|
@ -238,7 +244,7 @@ func main() {
|
|||
}
|
||||
|
||||
// Init Abi cache
|
||||
abi_mgr = abi.NewAbiManager(eosClient, conf.Redis.CacheID)
|
||||
abi_mgr = abi.NewAbiManager(rdb, eosClient, conf.Redis.CacheID)
|
||||
|
||||
redisNs = transport.Namespace{
|
||||
Prefix: conf.Redis.Prefix,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue