pebble

package module
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 6 Imported by: 0

README


id: pebble title: Pebble

Release Discord Test Security Linter

A fast key-value DB using cockroachdb/pebble

Note: Requires Go 1.19 and above

Table of Contents

Signatures

func New(config ...Config) Storage
func (s *Storage) Get(key string) ([]byte, error)
func (s *Storage) Set(key string, val []byte, exp time.Duration) error
func (s *Storage) Delete(key string) error
func (s *Storage) Reset() error
func (s *Storage) Close() error
func (s *Storage) Conn() *badger.DB

Installation

Pebble is tested on the 2 last Go versions with support for modules. So make sure to initialize one first if you didn't do that yet:

go mod init github.com/<user>/<repo>

Note: This step is only required if you don't have an existing module.

And then install the Pebble implementation:

go get github.com/gofiber/storage/pebble/v2

Examples

Import the storage package.

import "github.com/gofiber/storage/pebble/v2"

You can use the following possibilities to create a storage:

// Initialize default config
store := pebble.New()

// Initialize custom config
store := pebble.New(pebble.Config{
	Path:         "db",
	WriteOptions: &pebble.WriteOptions{},
})

Config

type Config struct {
	// Database name
	//
	// Optional. Default is "./db"
	Path string

	// Pass write options during write operations
	//
	// Optional. Default is nil
	WriteOptions &pebble.WriteOptions{}
}

Default Config

var ConfigDefault = Config{
	Path:         "db",
	WriteOptions: &pebble.WriteOptions{},
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigDefault = Config{
	Path:         "db",
	WriteOptions: &pebble.WriteOptions{},
}

Functions

This section is empty.

Types

type CacheType

type CacheType struct {
	Data    []byte `json:"data"`
	Created int64  `json:"created"`
	Expires int64  `json:"expires"`
}

type Config

type Config struct {
	Path         string
	WriteOptions *pebble.WriteOptions
}

type Storage

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

func New

func New(config ...Config) *Storage

func (*Storage) Close

func (s *Storage) Close() error

func (*Storage) Conn

func (s *Storage) Conn() *pebble.DB

// Return database client

func (*Storage) Delete

func (s *Storage) Delete(key string) error

// Implement the logic to delete the value for the given key from the storage provider // Return no error if the key does not exist in the storage

func (*Storage) Get

func (s *Storage) Get(key string) ([]byte, error)

// Implement the logic to retrieve the value for the given key from the storage provider // Return nil, nil if the key does not exist

func (*Storage) Reset

func (s *Storage) Reset() error

func (*Storage) Set

func (s *Storage) Set(key string, val []byte, exp time.Duration) error

// Implement the logic to store the given value for the given key in the storage provider // Use the provided expiration value (0 means no expiration) // Ignore empty key or value without returning an error

Jump to

Keyboard shortcuts

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