client

package
v0.0.0-...-411d5f7 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is the cache client SDK. It understands the hash ring and routes requests directly to the correct node.

func NewClient

func NewClient(nodes map[string]string, opts ...Option) (*Client, error)

NewClient creates a new cache client. nodes is a map of nodeID → gRPC address (e.g., "node-1" → "localhost:7001").

func (*Client) Close

func (c *Client) Close() error

Close closes all connections to cache nodes.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, key string) (bool, error)

Delete removes a key from the cache.

func (*Client) Get

func (c *Client) Get(ctx context.Context, key string) ([]byte, bool, error)

Get retrieves a value by key from the appropriate cache node.

func (*Client) NodeForKey

func (c *Client) NodeForKey(key string) (string, error)

NodeForKey returns the node ID that owns a given key (for debugging).

func (*Client) Nodes

func (c *Client) Nodes() []string

Nodes returns the list of connected node IDs.

func (*Client) Ping

func (c *Client) Ping(ctx context.Context, nodeID string) (*pb.PingResponse, error)

Ping checks if a specific node is alive.

func (*Client) Set

func (c *Client) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error

Set stores a key-value pair with optional TTL (0 = no expiry).

type L1Cache

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

L1Cache is a simple thread-safe LRU cache with TTL support for client-side hot key caching.

func NewL1Cache

func NewL1Cache(capacity int, defaultTTL time.Duration) *L1Cache

NewL1Cache creates a new L1 cache with the specified capacity and default TTL.

func (*L1Cache) Clear

func (c *L1Cache) Clear()

Clear clears all items from the cache.

func (*L1Cache) Delete

func (c *L1Cache) Delete(key string)

Delete removes a key from the L1 cache.

func (*L1Cache) Get

func (c *L1Cache) Get(key string) ([]byte, bool)

Get retrieves a key's value if it exists and is not expired.

func (*L1Cache) Len

func (c *L1Cache) Len() int

Len returns the number of items in the L1 cache.

func (*L1Cache) Set

func (c *L1Cache) Set(key string, value []byte, ttl time.Duration)

Set adds or updates a key-value pair in the L1 cache.

type Option

type Option func(*Client)

Option is a functional option for configuring the Client.

func WithDialTimeout

func WithDialTimeout(d time.Duration) Option

WithDialTimeout sets the gRPC dial timeout.

func WithL1Cache

func WithL1Cache(capacity int, defaultTTL time.Duration) Option

WithL1Cache enables the client-side L1 cache for hot keys.

func WithRequestTimeout

func WithRequestTimeout(d time.Duration) Option

WithRequestTimeout sets the default request timeout.

Jump to

Keyboard shortcuts

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