eth-blob-indexer/pkg/storage/storage.go
Roy Crihfield 1d1ee73ff2
Some checks failed
Tests / Run Blobscan scraper tests (push) Successful in 2m23s
Tests / Run Beacon collector tests (push) Failing after 22m23s
Implement Blobscan scraper (#2)
New utility to backfill data from Blobscan.

Reviewed-on: #2
2024-07-01 14:01:27 +00:00

44 lines
971 B
Go

package storage
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
}