backends

package
v0.0.0-...-02374a7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AerospikeBackend

type AerospikeBackend struct {
	// contains filtered or unexported fields
}

AerospikeBackend upon creation will instantiates, and configure the Aerospike client. Implements the Backend interface

func NewAerospikeBackend

func NewAerospikeBackend(cfg config.Aerospike, metrics *metrics.Metrics) *AerospikeBackend

NewAerospikeBackend validates config.Aerospike and returns an AerospikeBackend

func NewMockAerospikeBackend

func NewMockAerospikeBackend(mockClient AerospikeDB) *AerospikeBackend

------------------------------------------ Aerospike client mocks ------------------------------------------

func (*AerospikeBackend) Get

func (a *AerospikeBackend) Get(ctx context.Context, key string) (string, error)

Get creates an aerospike key based on the UUID key parameter, perfomrs the client's Get call and validates results. Can return a KEY_NOT_FOUND error or other Aerospike server errors

func (*AerospikeBackend) Put

func (a *AerospikeBackend) Put(ctx context.Context, key string, value string, ttlSeconds int) error

Put creates an aerospike key based on the UUID key parameter and stores the value using the client's Put implementaion. Can return a RECORD_EXISTS error or other Aerospike server errors

type AerospikeDB

type AerospikeDB interface {
	NewUUIDKey(namespace string, key string) (*as.Key, error)
	Get(key *as.Key) (*as.Record, error)
	Put(policy *as.WritePolicy, key *as.Key, binMap as.BinMap) error
}

AerospikeDB is a wrapper for the Aerospike client

type AerospikeDBClient

type AerospikeDBClient struct {
	// contains filtered or unexported fields
}

AerospikeDBClient implements the AerospikeDB interface

func (AerospikeDBClient) Get

func (db AerospikeDBClient) Get(key *as.Key) (*as.Record, error)

Get performs the as.Client Get operation

func (*AerospikeDBClient) NewUUIDKey

func (db *AerospikeDBClient) NewUUIDKey(namespace string, key string) (*as.Key, error)

NewUUIDKey creates an aerospike key so we can store data under it

func (AerospikeDBClient) Put

func (db AerospikeDBClient) Put(policy *as.WritePolicy, key *as.Key, binMap as.BinMap) error

Put performs the as.Client Put operation

type Backend

type Backend interface {
	Put(ctx context.Context, key string, value string, ttlSeconds int) error
	Get(ctx context.Context, key string) (string, error)
}

Backend interface for storing data

type CassandraBackend

type CassandraBackend struct {
	// contains filtered or unexported fields
}

CassandraBackend implements the Backend interface and get called from our Prebid Cache's endpoint handle functions.

func NewCassandraBackend

func NewCassandraBackend(cfg config.Cassandra) *CassandraBackend

NewCassandraBackend expects a valid config.Cassandra object

func NewMockCassandraBackend

func NewMockCassandraBackend(ttl int, mockClient CassandraDB) *CassandraBackend

------------------------------------------ Cassandra client mocks ------------------------------------------

func (*CassandraBackend) Get

func (back *CassandraBackend) Get(ctx context.Context, key string) (string, error)

Get makes the Cassandra client to retrieve the value that has been previously stored under 'key'. Returns KeyNotFoundError if no such key has ever been stored in the Cassandra database service

func (*CassandraBackend) Put

func (back *CassandraBackend) Put(ctx context.Context, key string, value string, ttlSeconds int) error

Put makes the Cassandra client to store `value` only if `key` doesn't exist in the storage already. If it does, no operation is performed and Put returns RecordExistsError

type CassandraDB

type CassandraDB interface {
	Init() error
	Get(ctx context.Context, key string) (string, error)
	Put(ctx context.Context, key string, value string, ttlSeconds int) (bool, error)
}

CassandraDB is an interface that helps us communicate with a cassandra storage service using the cassandra "github.com/gocql/gocql" client

type CassandraDBClient

type CassandraDBClient struct {
	// contains filtered or unexported fields
}

CassandraDBClient is a wrapper for the Cassandra client 'gocql' that interacts with the Cassandra server and implements the CassandraDB interface

func (*CassandraDBClient) Get

func (c *CassandraDBClient) Get(ctx context.Context, key string) (string, error)

Get returns the value associated with the provided `key` parameter

func (*CassandraDBClient) Init

func (c *CassandraDBClient) Init() error

Init initializes Cassandra cluster and session with the configuration loaded from environment variables or configuration files at startup

func (*CassandraDBClient) Put

func (c *CassandraDBClient) Put(ctx context.Context, key string, value string, ttlSeconds int) (bool, error)

Put writes the `value` under the provided `key` in the Cassandra DB server only if it doesn't already exist. We make sure of this by adding the 'IF NOT EXISTS' clause to the 'INSERT' query

type ErrorProneAerospikeClient

type ErrorProneAerospikeClient struct {
	ServerError string
}

func (*ErrorProneAerospikeClient) Get

func (c *ErrorProneAerospikeClient) Get(key *as.Key) (*as.Record, error)

func (*ErrorProneAerospikeClient) NewUUIDKey

func (c *ErrorProneAerospikeClient) NewUUIDKey(namespace string, key string) (*as.Key, error)

func (*ErrorProneAerospikeClient) Put

func (c *ErrorProneAerospikeClient) Put(policy *as.WritePolicy, key *as.Key, binMap as.BinMap) error

type ErrorProneCassandraClient

type ErrorProneCassandraClient struct {
	Applied     bool
	ServerError error
}

func (*ErrorProneCassandraClient) Get

func (*ErrorProneCassandraClient) Init

func (ec *ErrorProneCassandraClient) Init() error

func (*ErrorProneCassandraClient) Put

func (ec *ErrorProneCassandraClient) Put(ctx context.Context, key string, value string, ttlSeconds int) (bool, error)

type ErrorProneMemcache

type ErrorProneMemcache struct {
	ServerError error
}

func (*ErrorProneMemcache) Get

func (ec *ErrorProneMemcache) Get(key string) (*memcache.Item, error)

func (*ErrorProneMemcache) Put

func (ec *ErrorProneMemcache) Put(key string, value string, ttlSeconds int) error

type ErrorProneMemoryClient

type ErrorProneMemoryClient struct{}

func NewErrorResponseMemoryBackend

func NewErrorResponseMemoryBackend() *ErrorProneMemoryClient

------------------------------------------ Memory client mocks ------------------------------------------

func (*ErrorProneMemoryClient) Get

func (*ErrorProneMemoryClient) Put

func (ec *ErrorProneMemoryClient) Put(ctx context.Context, key string, value string, ttlSeconds int) error

type FakeRedisClient

type FakeRedisClient struct {
	StoredData  map[string]string
	ServerError error
	Success     bool
}

func (FakeRedisClient) Get

func (r FakeRedisClient) Get(ctx context.Context, key string) (string, error)

Get returns an error if the FakeRedisClient has a non-nil ServerError field.

func (FakeRedisClient) Put

func (r FakeRedisClient) Put(ctx context.Context, key string, value string, ttlSeconds int) (bool, error)

type GoodAerospikeClient

type GoodAerospikeClient struct {
	StoredData map[string]string
}

Aerospike client that does not throw errors

func (*GoodAerospikeClient) Get

func (c *GoodAerospikeClient) Get(aeKey *as.Key) (*as.Record, error)

func (*GoodAerospikeClient) NewUUIDKey

func (c *GoodAerospikeClient) NewUUIDKey(namespace string, key string) (*as.Key, error)

func (*GoodAerospikeClient) Put

func (c *GoodAerospikeClient) Put(policy *as.WritePolicy, aeKey *as.Key, binMap as.BinMap) error

type GoodCassandraClient

type GoodCassandraClient struct {
	StoredData map[string]string
}

Cassandra client client that does not throw errors

func (*GoodCassandraClient) Get

func (gc *GoodCassandraClient) Get(ctx context.Context, key string) (string, error)

func (*GoodCassandraClient) Init

func (gc *GoodCassandraClient) Init() error

func (*GoodCassandraClient) Put

func (gc *GoodCassandraClient) Put(ctx context.Context, key string, value string, ttlSeconds int) (bool, error)

type GoodMemcache

type GoodMemcache struct {
	StoredData map[string]string
}

Memcache client that does not throw errors

func (*GoodMemcache) Get

func (gm *GoodMemcache) Get(key string) (*memcache.Item, error)

func (*GoodMemcache) Put

func (gm *GoodMemcache) Put(key string, value string, ttlSeconds int) error

type Memcache

type Memcache struct {
	// contains filtered or unexported fields
}

Memcache Object use to implement MemcacheDataStore interface

func (*Memcache) Get

func (mc *Memcache) Get(key string) (*memcache.Item, error)

Get uses the github.com/bradfitz/gomemcache/memcache library to retrieve the value stored under 'key', if any

func (*Memcache) Put

func (mc *Memcache) Put(key string, value string, ttlSeconds int) error

Put uses the github.com/bradfitz/gomemcache/memcache library to store 'value' under 'key'. Because Prebid Cache doesn't implement 'upsert', Put calls Add(item *Item), that writes the given item only if no value already exists for its key as opposed to Set(item *Item), or Replace(item *Item)

type MemcacheBackend

type MemcacheBackend struct {
	// contains filtered or unexported fields
}

MemcacheBackend implements the Backend interface

func NewMemcacheBackend

func NewMemcacheBackend(cfg config.Memcache) *MemcacheBackend

NewMemcacheBackend creates a new memcache backend and expects a valid 'cfg config.Memcache' argument

func NewMockMemcacheBackend

func NewMockMemcacheBackend(mockClient MemcacheDataStore) *MemcacheBackend

------------------------------------------ Memcache client mocks ------------------------------------------

func (*MemcacheBackend) Get

func (mc *MemcacheBackend) Get(ctx context.Context, key string) (string, error)

Get makes the MemcacheDataStore client to retrieve the value that has been previously stored under 'key'. If unseuccessful, returns an empty value and a KeyNotFoundError or other, memcache-related error

func (*MemcacheBackend) Put

func (mc *MemcacheBackend) Put(ctx context.Context, key string, value string, ttlSeconds int) error

Put makes the MemcacheDataStore client to store `value` only if `key` doesn't exist in the storage already. If it does, no operation is performed and Put returns RecordExistsError

type MemcacheDataStore

type MemcacheDataStore interface {
	Get(key string) (*memcache.Item, error)
	Put(key string, value string, ttlSeconds int) error
}

MemcacheDataStore is an interface that helps us communicate with an instance of the memcached cache server. Its implementation is intended to use the "github.com/bradfitz/gomemcache/memcache" client

type MemoryBackend

type MemoryBackend struct {
	// contains filtered or unexported fields
}

MemoryBackend stores information in the local memory heap. Stored data dissapears upon Prebid Cache restart

func NewMemoryBackend

func NewMemoryBackend() *MemoryBackend

NewMemoryBackend instances a MemoryBackend struct

func NewMemoryBackendWithValues

func NewMemoryBackendWithValues(customData map[string]string) (*MemoryBackend, error)

Good memory client does not throw errors

func (*MemoryBackend) Get

func (b *MemoryBackend) Get(ctx context.Context, key string) (string, error)

Get retrieves from the local memory and uses a mutex lock to aviod data race scenarios

func (*MemoryBackend) Put

func (b *MemoryBackend) Put(ctx context.Context, key string, value string, ttlSeconds int) error

Put stores data in local memory and uses a mutex lock to aviod data race scenarios

type RedisBackend

type RedisBackend struct {
	// contains filtered or unexported fields
}

RedisBackend when initialized will instantiate and configure the Redis client. It implements the Backend interface.

func NewFakeRedisBackend

func NewFakeRedisBackend(mockClient RedisDB) *RedisBackend

------------------------------------------ Redis client mocks ------------------------------------------

func NewRedisBackend

func NewRedisBackend(cfg config.Redis, ctx context.Context) *RedisBackend

NewRedisBackend initializes the redis client and pings to make sure connection was successful

func (*RedisBackend) Get

func (b *RedisBackend) Get(ctx context.Context, key string) (string, error)

Get calls the Redis client to return the value associated with the provided `key` parameter and interprets its response. A `Nil` error reply of the Redis client means the `key` does not exist.

func (*RedisBackend) Put

func (b *RedisBackend) Put(ctx context.Context, key string, value string, ttlSeconds int) error

Put writes the `value` under the provided `key` in the Redis storage server. Because the backend implementation of Put calls SetNX(item *Item), a `false` return value is interpreted as the data not being written because the `key` already holds a value, and a RecordExistsError is returned

type RedisDB

type RedisDB interface {
	Get(ctx context.Context, key string) (string, error)
	Put(ctx context.Context, key string, value string, ttlSeconds int) (bool, error)
}

RedisDB is an interface that helps us communicate with an instance of a Redis database. Its implementation is intended to use the "github.com/go-redis/redis" client

type RedisDBClient

type RedisDBClient struct {
	// contains filtered or unexported fields
}

RedisDBClient is a wrapper for the Redis client that implements the RedisDB interface

func (RedisDBClient) Get

func (db RedisDBClient) Get(ctx context.Context, key string) (string, error)

Get returns the value associated with the provided `key` parameter

func (RedisDBClient) Put

func (db RedisDBClient) Put(ctx context.Context, key, value string, ttlSeconds int) (bool, error)

Put will set 'key' to hold string 'value' if 'key' does not exist in the redis storage. When key already holds a value, no operation is performed. That's the reason this adapter uses the 'github.com/go-redis/redis's library SetNX. SetNX is short for "SET if Not eXists".

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL