eth-blob-indexer/pkg/storage.go
Roy Crihfield 3d8d84df86 Initial service
Dockerfile & compose file

CI workflow
2024-05-30 13:24:45 +08:00

44 lines
976 B
Go

package blob_indexer
import (
"context"
"time"
"github.com/go-redis/redis/v8"
"github.com/protolambda/zrnt/eth2/beacon/common"
)
func BlobKeyFromHash(vhash common.Hash32) string {
return "blob:" + vhash.String()
}
// KvStorage represents a Redis-like KV store
type KvStorage interface {
Set(ctx context.Context, key string, value []byte, expiration time.Duration) error
}
type RedisStorage struct {
rdb *redis.Client
}
func NewRedisStorage(rdb *redis.Client) *RedisStorage {
return &RedisStorage{rdb: rdb}
}
func (rs *RedisStorage) Set(ctx context.Context, key string, value []byte, expiration time.Duration) error {
return rs.rdb.Set(ctx, key, value, expiration).Err()
}
type MapStorage struct {
store map[string][]byte
}
func NewMapStorage() *MapStorage {
return &MapStorage{store: make(map[string][]byte)}
}
func (ms *MapStorage) Set(ctx context.Context, key string, value []byte, expiration time.Duration) error {
ms.store[key] = value
return nil
}