Documentation
¶
Overview ¶
Package memorydatabase provides a service for managing interactions with memory databases. Currently supports Redis as the primary memory database implementation.
Index ¶
- type Client
- type MemoryDatabase
- type RedisClient
- func (client *RedisClient) Initiate(ctx context.Context) error
- func (client *RedisClient) IsClientInitiated() bool
- func (client *RedisClient) ReadString(ctx context.Context, key string) (string, bool, error)
- func (client *RedisClient) WriteString(ctx context.Context, key string, value string, ttl int) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface {
// WriteString stores a string value with the given key and TTL (time-to-live) in seconds.
// Returns an error if the operation fails.
WriteString(context.Context, string, string, int) error
// ReadString retrieves a string value by key.
// Returns the value, a boolean indicating if the key was found, and any error.
ReadString(context.Context, string) (string, bool, error)
// IsClientInitiated returns true if the client has been successfully initialized.
IsClientInitiated() bool
}
Client interface defines the contract for memory database operations. Implementations must provide methods for reading and writing string values, as well as checking if the client has been properly initialized.
type MemoryDatabase ¶
type MemoryDatabase struct {
// contains filtered or unexported fields
}
MemoryDatabase provides a high-level interface for memory database operations. It uses a Client implementation to perform actual database operations.
func NewMemoryDatabase ¶ added in v0.0.3
func NewMemoryDatabase(client Client) MemoryDatabase
NewMemoryDatabase creates a new MemoryDatabase instance with the provided client. The client must implement the Client interface.
func (*MemoryDatabase) ReadString ¶
func (memorydatabase *MemoryDatabase) ReadString(ctx context.Context, key string) (string, bool, error)
ReadString reads a string value from the memory database using the underlying client. This is a wrapper method that checks if the client is initialized before performing the operation. Returns the value, a boolean indicating if the key was found, and any error. Returns an error if the client is not initialized.
func (*MemoryDatabase) WriteString ¶
func (memorydatabase *MemoryDatabase) WriteString(ctx context.Context, key string, value string, ttl int) error
WriteString writes a string value to the memory database using the underlying client. This is a wrapper method that checks if the client is initialized before performing the operation. Returns an error if the client is not initialized or if the write operation fails.
type RedisClient ¶
type RedisClient struct {
// contains filtered or unexported fields
}
RedisClient implements the Client interface for Redis database operations. It manages the connection to a Redis server and provides methods for reading/writing data.
func NewRedisClient ¶
func NewRedisClient(redisConfig *redisconfig.Config) RedisClient
NewRedisClient creates a new RedisClient instance with the provided configuration. The client is not automatically initialized - call Initiate() to establish the connection.
func (*RedisClient) Initiate ¶
func (client *RedisClient) Initiate(ctx context.Context) error
Initiate establishes a connection to the Redis server and validates it with a ping. This method must be called before any read/write operations can be performed. It handles both IP addresses and domain names for the Redis host.
func (*RedisClient) IsClientInitiated ¶ added in v0.0.4
func (client *RedisClient) IsClientInitiated() bool
IsClientInitiated returns true if the Redis client has been successfully initialized and is ready to perform operations.
func (*RedisClient) ReadString ¶
ReadString retrieves a string value from Redis by key. Returns the value, a boolean indicating if the key was found, and any error. If the key doesn't exist, the boolean will be false and the string will be empty.
func (*RedisClient) WriteString ¶
func (client *RedisClient) WriteString(ctx context.Context, key string, value string, ttl int) error
WriteString stores a string value in Redis with the specified key and TTL. The TTL is specified in seconds. Use 0 for no expiration (infinite TTL). Returns an error if the operation fails or if the client is not initialized.