Documentation
¶
Index ¶
- type IMightyMapStorage
- func NewMightyMapBadgerStorage[K comparable, V any](optfuncs ...OptionFuncBadger) IMightyMapStorage[K, V]
- func NewMightyMapDefaultStorage[K comparable, V any]() IMightyMapStorage[K, V]
- func NewMightyMapRedisStorage[K comparable, V any](optfuncs ...OptionFuncRedis) IMightyMapStorage[K, V]
- func NewMightyMapSwissStorage[K comparable, V any](optfuncs ...OptionFuncSwiss) IMightyMapStorage[K, V]
- type OptionFuncBadger
- func WithBlockCacheSize(blockCacheSize int64) OptionFuncBadger
- func WithBlockSize(blockSize int) OptionFuncBadger
- func WithCompression(compression bool) OptionFuncBadger
- func WithDetectConflicts(detectConflicts bool) OptionFuncBadger
- func WithEncryptionKey(encryptionKey string) OptionFuncBadger
- func WithEncryptionKeyRotationDuration(encryptionKeyRotation time.Duration) OptionFuncBadger
- func WithGcInterval(gcInterval time.Duration) OptionFuncBadger
- func WithGcPercentage(gcPercentage float64) OptionFuncBadger
- func WithIndexCacheSize(indexCacheSize int64) OptionFuncBadger
- func WithLoggingLevel(loggingLevel int) OptionFuncBadger
- func WithMemTableSize(memTableSize int64) OptionFuncBadger
- func WithMemoryStorage(memoryStorage bool) OptionFuncBadger
- func WithMetricsEnabled(metricsEnabled bool) OptionFuncBadger
- func WithNumCompactors(numCompactors int) OptionFuncBadger
- func WithNumVersionsToKeep(numVersionsToKeep int) OptionFuncBadger
- func WithSyncWrites(syncWrites bool) OptionFuncBadger
- func WithTempDir(dir string) OptionFuncBadger
- func WithValueThreshold(valueThreshold int64) OptionFuncBadger
- type OptionFuncRedis
- func WithRedisAddr(addr string) OptionFuncRedis
- func WithRedisDB(db int) OptionFuncRedis
- func WithRedisExpire(expire time.Duration) OptionFuncRedis
- func WithRedisMaxRetries(maxRetries int) OptionFuncRedis
- func WithRedisMock(t *testing.T) OptionFuncRedis
- func WithRedisPassword(password string) OptionFuncRedis
- func WithRedisPoolSize(poolSize int) OptionFuncRedis
- func WithRedisPrefix(prefix string) OptionFuncRedis
- func WithRedisTLS(tls bool) OptionFuncRedis
- func WithRedisTLSConfig(tlsConfig *tls.Config) OptionFuncRedis
- func WithRedisTimeout(timeout time.Duration) OptionFuncRedis
- type OptionFuncSwiss
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IMightyMapStorage ¶ added in v0.1.2
type IMightyMapStorage[K comparable, V any] interface { Load(ctx context.Context, key K) (value V, ok bool) Store(ctx context.Context, key K, value V) Delete(ctx context.Context, keys ...K) Range(ctx context.Context, f func(key K, value V) bool) Next(ctx context.Context) (key K, value V, ok bool) Len(ctx context.Context) int Clear(ctx context.Context) Close(ctx context.Context) error }
func NewMightyMapBadgerStorage ¶ added in v0.1.2
func NewMightyMapBadgerStorage[K comparable, V any](optfuncs ...OptionFuncBadger) IMightyMapStorage[K, V]
NewMightyMapBadgerStorage creates a new thread-safe storage implementation using BadgerDB. It accepts optional configuration through OptionFuncBadger functions to customize the BadgerDB instance.
Parameters:
- optfuncs: Optional configuration functions that modify badgerOpts settings
The function:
- Starts with default options and applies any provided option functions
- Configures BadgerDB options including compression, logging level, and performance settings
- Opens a BadgerDB instance with the configured options
- Starts a background goroutine for value log garbage collection
Returns:
- IMightyMapStorage[K, V]: A new BadgerDB-backed storage implementation
Panics if BadgerDB fails to open with the provided configuration.
func NewMightyMapDefaultStorage ¶ added in v0.1.2
func NewMightyMapDefaultStorage[K comparable, V any]() IMightyMapStorage[K, V]
func NewMightyMapRedisStorage ¶ added in v0.3.0
func NewMightyMapRedisStorage[K comparable, V any](optfuncs ...OptionFuncRedis) IMightyMapStorage[K, V]
func NewMightyMapSwissStorage ¶ added in v0.1.2
func NewMightyMapSwissStorage[K comparable, V any](optfuncs ...OptionFuncSwiss) IMightyMapStorage[K, V]
NewMightyMapSwissStorage creates a new thread-safe map storage implementation using swiss.Map with optional configuration through OptionFuncSwiss functions.
type OptionFuncBadger ¶
type OptionFuncBadger func(*badgerOpts)
OptionFuncBadger is a function type that modifies badgerOpts configuration. It allows customizing the behavior of the BadgerDB storage implementation through functional options pattern. WithXXX...
func WithBlockCacheSize ¶
func WithBlockCacheSize(blockCacheSize int64) OptionFuncBadger
WithBlockCacheSize sets the size of the block cache in bytes. **Default value**: `512 << 20` (512 MB)
func WithBlockSize ¶
func WithBlockSize(blockSize int) OptionFuncBadger
WithBlockSize sets the size of each block in the LSM tree in bytes. **Default value**: `16 * 1024` (16 KB)
func WithCompression ¶
func WithCompression(compression bool) OptionFuncBadger
WithCompression enables or disables data compression using ZSTD in Badger. **Default value**: `false`
func WithDetectConflicts ¶
func WithDetectConflicts(detectConflicts bool) OptionFuncBadger
WithDetectConflicts enables or disables conflict detection in Badger. **Default value**: `true`
func WithEncryptionKey ¶ added in v0.1.4
func WithEncryptionKey(encryptionKey string) OptionFuncBadger
WithEncryptionKey sets the encryption key for the Badger database.
func WithEncryptionKeyRotationDuration ¶ added in v0.1.4
func WithEncryptionKeyRotationDuration(encryptionKeyRotation time.Duration) OptionFuncBadger
WithEncryptionKeyRotationDuration sets the rotation duration for the encryption key in Badger.
func WithGcInterval ¶ added in v0.1.2
func WithGcInterval(gcInterval time.Duration) OptionFuncBadger
WithGcInterval sets the interval for garbage collection in Badger. **Default value**: `10 * time.Second`
func WithGcPercentage ¶ added in v0.1.2
func WithGcPercentage(gcPercentage float64) OptionFuncBadger
WithGcPercentage sets the percentage of value log space to be collected during garbage collection. **Default value**: `0.5`
func WithIndexCacheSize ¶
func WithIndexCacheSize(indexCacheSize int64) OptionFuncBadger
WithIndexCacheSize sets the size of the LSM tree cache in bytes. **Default value**: `128 << 20` (128 MB)
func WithLoggingLevel ¶
func WithLoggingLevel(loggingLevel int) OptionFuncBadger
WithLoggingLevel sets the logging level for Badger. **Default value**: `int(badger.ERROR)` Logging levels: - `0`: `DEBUG` - `1`: `INFO` - `2`: `WARNING` - `3`: `ERROR`
func WithMemTableSize ¶ added in v0.1.4
func WithMemTableSize(memTableSize int64) OptionFuncBadger
WithMemTableSize sets the size of the memtable in bytes. **Default value**: `128 << 20` (128 MB)
func WithMemoryStorage ¶
func WithMemoryStorage(memoryStorage bool) OptionFuncBadger
WithMemoryStorage enables or disables in-memory storage. If set to `true`, the database will be stored in memory. **Default value**: `true`
func WithMetricsEnabled ¶
func WithMetricsEnabled(metricsEnabled bool) OptionFuncBadger
WithMetricsEnabled enables or disables metrics collection in Badger. **Default value**: `false`
func WithNumCompactors ¶
func WithNumCompactors(numCompactors int) OptionFuncBadger
WithNumCompactors sets the number of compaction workers in Badger. **Default value**: `8`
func WithNumVersionsToKeep ¶
func WithNumVersionsToKeep(numVersionsToKeep int) OptionFuncBadger
WithNumVersionsToKeep specifies the number of versions to keep per key. **Default value**: `2`
func WithSyncWrites ¶ added in v0.1.5
func WithSyncWrites(syncWrites bool) OptionFuncBadger
WithSyncWrites enables or disables synchronous writes in Badger. **Default value**: `false`
func WithTempDir ¶
func WithTempDir(dir string) OptionFuncBadger
WithTempDir sets the directory for storing the Badger database files. **Default value**: `os.TempDir() + "/badger-{timestamp}"`
func WithValueThreshold ¶ added in v0.1.4
func WithValueThreshold(valueThreshold int64) OptionFuncBadger
WithValueThreshold sets the threshold for value storage in Badger. **Default value**: `4 << 20` (4 MB)
type OptionFuncRedis ¶ added in v0.3.0
type OptionFuncRedis func(*redisOpts)
func WithRedisAddr ¶ added in v0.3.0
func WithRedisAddr(addr string) OptionFuncRedis
WithRedisAddr sets the Redis server address (host:port) for the client connection. Example: "localhost:6379" or "redis.example.com:6379"
func WithRedisDB ¶ added in v0.3.0
func WithRedisDB(db int) OptionFuncRedis
WithRedisDB selects the Redis logical database to use. Redis servers support multiple logical databases indexed by numbers (0-15 by default). The default database is 0.
func WithRedisExpire ¶ added in v0.3.0
func WithRedisExpire(expire time.Duration) OptionFuncRedis
WithRedisExpire sets the expiration time for the Redis key-value pairs. The expire parameter specifies the duration after which keys will expire. If expire is 0, keys will not expire (persist indefinitely).
func WithRedisMaxRetries ¶ added in v0.3.0
func WithRedisMaxRetries(maxRetries int) OptionFuncRedis
WithRedisMaxRetries sets the maximum number of retries for failed Redis operations. The client will retry operations if they fail due to network issues or other recoverable errors.
func WithRedisMock ¶ added in v0.3.0
func WithRedisMock(t *testing.T) OptionFuncRedis
WithRedisMock (not implemented) sets the Redis client to use a mock implementation. This is useful for testing and development environments where a real Redis server is not available.
func WithRedisPassword ¶ added in v0.3.0
func WithRedisPassword(password string) OptionFuncRedis
WithRedisPassword sets the password for Redis authentication. If Redis server requires authentication, this password will be used. For servers without authentication, pass an empty string.
func WithRedisPoolSize ¶ added in v0.3.0
func WithRedisPoolSize(poolSize int) OptionFuncRedis
WithRedisPoolSize sets the maximum number of socket connections in the Redis connection pool. Default is 10 connections per every available CPU as reported by runtime.NumCPU.
func WithRedisPrefix ¶ added in v0.3.0
func WithRedisPrefix(prefix string) OptionFuncRedis
WithRedisPrefix sets a global key prefix for all Redis operations. All keys will be automatically prefixed with this string. Useful for namespacing keys in a shared Redis instance.
func WithRedisTLS ¶ added in v0.3.0
func WithRedisTLS(tls bool) OptionFuncRedis
WithRedisTLS enables or disables TLS/SSL encryption for Redis connections. When enabled, the client will attempt to establish secure connections to the Redis server.
func WithRedisTLSConfig ¶ added in v0.3.0
func WithRedisTLSConfig(tlsConfig *tls.Config) OptionFuncRedis
WithRedisTLSConfig sets custom TLS configuration for Redis connections. This allows fine-grained control over TLS settings such as certificates, cipher suites, etc. Only used when TLS is enabled.
func WithRedisTimeout ¶ added in v0.3.0
func WithRedisTimeout(timeout time.Duration) OptionFuncRedis
WithRedisTimeout sets the timeout duration for Redis client operations. This timeout value is used to create a context with timeout for Redis operations. It helps prevent operations from hanging indefinitely.
type OptionFuncSwiss ¶
type OptionFuncSwiss func(*swissOpts)
OptionFuncSwiss is a function type that modifies swissOpts configuration. It allows customizing the behavior of the swiss.Map storage implementation through functional options pattern.
func WithDefaultCapacity ¶
func WithDefaultCapacity(capacity uint32) OptionFuncSwiss
WithDefaultCapacity returns an OptionFuncSwiss that sets the initial capacity of the swiss.Map. The capacity should be set based on the expected number of items to optimize memory usage.