memstore

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package memstore provides a generic thread-safe in-memory key-value store.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

type Store[V any] struct {
	// contains filtered or unexported fields
}

Store is a generic thread-safe in-memory key-value store.

func New

func New[V any]() *Store[V]

New creates a new empty Store.

func (*Store[V]) All

func (s *Store[V]) All() map[string]V

All returns a copy of all items in the store.

func (*Store[V]) Clear

func (s *Store[V]) Clear()

Clear removes all items from the store.

func (*Store[V]) Delete

func (s *Store[V]) Delete(key string) bool

Delete removes a value by key. Returns true if the key was present.

func (*Store[V]) Filter

func (s *Store[V]) Filter(fn func(key string, value V) bool) map[string]V

Filter returns all values matching the predicate.

func (*Store[V]) Get

func (s *Store[V]) Get(key string) (V, bool)

Get retrieves a value by key. Returns the value and true if found.

func (*Store[V]) Has

func (s *Store[V]) Has(key string) bool

Has returns true if the key exists.

func (*Store[V]) Keys

func (s *Store[V]) Keys() []string

Keys returns all keys in the store.

func (*Store[V]) Len

func (s *Store[V]) Len() int

Len returns the number of items in the store.

func (*Store[V]) Set

func (s *Store[V]) Set(key string, value V)

Set stores a value at the given key.

func (*Store[V]) SetIfAbsent

func (s *Store[V]) SetIfAbsent(key string, value V) bool

SetIfAbsent stores a value only if the key does not already exist. Returns true if set.

func (*Store[V]) Update

func (s *Store[V]) Update(key string, fn func(V) V) bool

Update atomically reads, modifies, and writes a value. Returns false if key not found.

Jump to

Keyboard shortcuts

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