loach

package module
v0.0.0-...-baea7c9 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2025 License: MIT Imports: 12 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

loach

A goleveldb wrapper that allows easy store hash, zset data, base on goleveldb

Example

db, _ := loach.OpenDefault("testdb")

db.Hset("name", []byte("k"), []byte("v"))
db.Hget("name", []byte("k"))
db.Hdel("name", []byte("k"))
db.Hincr("name", []byte("k"), 3)
db.Hscan("name", nil, 10)
db.Hrscan("name", nil, 10)

db.Zset("name", []byte("k"), 1)
db.Zget("name", []byte("k"))
db.Zdel("name", []byte("k"))
db.Zincr("name", []byte("k"), 3)
db.Zscan("name", nil, 10)
db.Zrscan("name", nil, 10)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	HashPrefix      = []byte("H_") //H_
	ZsetPrefix      = []byte("Z_") //Z_
	ZsetKeyPrefix   = []byte("k")  //k
	ZsetScorePrefix = []byte("s")  //s
	SplitChar       = []byte("_")  //_
)

Functions

func Bconcat

func Bconcat(parts ...[]byte) []byte

helper functions

func BytesToDigitString

func BytesToDigitString(b []byte) string

BytesToDigitString converts an 8-byte big endian byte slice to a digit string. Example: []byte{...} -> uint64(123456) -> "123456"

func BytesToUint64

func BytesToUint64(v []byte) uint64

func DigitStringToBytes

func DigitStringToBytes(s string) []byte

DigitStringToBytes returns an 8-byte big endian representation of a digit string. Example: "123456" -> uint64(123456) -> []byte{...}

func DigitStringToUint64

func DigitStringToUint64(s string) uint64

DigitStringToUint64 parses a digit string into a uint64 number. Example: "123456" -> 123456

func Uint64ToBytes

func Uint64ToBytes(v uint64) []byte

Types

type DB

type DB struct {
	*leveldb.DB
}

func Open

func Open(dbPath string, o *opt.Options) (*DB, error)

func OpenDefault

func OpenDefault(dbPath string) (*DB, error)

func (*DB) BackupTo

func (db *DB) BackupTo(backupPath string) error

func (*DB) Close

func (db *DB) Close() error

func (*DB) Compact

func (db *DB) Compact() error

func (*DB) GetSnapshot

func (db *DB) GetSnapshot(key []byte) ([]byte, error)

func (*DB) Hdel

func (db *DB) Hdel(name string, key []byte) error

func (*DB) HdelBucket

func (db *DB) HdelBucket(name string) error

func (*DB) Hget

func (db *DB) Hget(name string, key []byte) *Reply

func (*DB) HgetInt

func (db *DB) HgetInt(name string, key []byte) uint64

func (*DB) HhasKey

func (db *DB) HhasKey(name string, key []byte) bool

func (*DB) Hincr

func (db *DB) Hincr(name string, key []byte, step int64) (newNum uint64, err error)

func (*DB) Hmdel

func (db *DB) Hmdel(name string, keys [][]byte) error

func (*DB) Hmget

func (db *DB) Hmget(name string, keys [][]byte) *Reply

func (*DB) Hmset

func (db *DB) Hmset(name string, kvs ...[]byte) error

func (*DB) Hprefix

func (db *DB) Hprefix(name string, prefix []byte, limit int) *Reply

func (*DB) Hrscan

func (db *DB) Hrscan(name string, keyStart []byte, limit int) *Reply

func (*DB) Hscan

func (db *DB) Hscan(name string, keyStart []byte, limit int) *Reply

func (*DB) Hset

func (db *DB) Hset(name string, key, val []byte) error

hash functions

func (*DB) RestoreFrom

func (db *DB) RestoreFrom(backupPath string) error

func (*DB) StatsStruct

func (db *DB) StatsStruct() (*DBStats, error)

func (*DB) Zdel

func (db *DB) Zdel(name string, key []byte) error

func (*DB) ZdelBucket

func (db *DB) ZdelBucket(name string) error

func (*DB) Zget

func (db *DB) Zget(name string, key []byte) uint64

func (*DB) ZhasKey

func (db *DB) ZhasKey(name string, key []byte) bool

func (*DB) Zincr

func (db *DB) Zincr(name string, key []byte, step int64) (uint64, error)

func (*DB) Zmdel

func (db *DB) Zmdel(name string, keys [][]byte) error

func (*DB) Zmget

func (db *DB) Zmget(name string, keys [][]byte) *Reply

func (*DB) Zmset

func (db *DB) Zmset(name string, kvs [][]byte) error

func (*DB) Zrscan

func (db *DB) Zrscan(name string, keyStart, scoreStart []byte, limit int) *Reply

func (*DB) Zscan

func (db *DB) Zscan(name string, keyStart, scoreStart []byte, limit int) *Reply

func (*DB) Zset

func (db *DB) Zset(name string, key []byte, val uint64) error

zset functions

type DBStats

type DBStats struct {
	Compactions      string                 `json:"compactions"`        // raw compaction stats text
	TableStats       map[int]TableStat      `json:"table_stats"`        // parsed per-level table stats
	SSTableInfo      string                 `json:"sstable_info"`       // raw sstables info text
	SSTables         map[int][]SSTableEntry `json:"sstables"`           // parsed per-level SSTable entries
	BlockPoolInfo    string                 `json:"block_pool_info"`    // raw block pool info
	OpenedTablesInfo string                 `json:"opened_tables_info"` // raw opened tables info
}

type Entry

type Entry struct {
	Key, Value RawData
}

type RawData

type RawData []byte

func (RawData) Bytes

func (b RawData) Bytes() []byte

func (RawData) Int

func (b RawData) Int() int

Int is a convenience wrapper over Get for int value of a hashmap.

func (RawData) Int64

func (b RawData) Int64() int64

Int64 is a convenience wrapper over Get for int64 value of a hashmap.

func (RawData) Json

func (b RawData) Json() gjson.Result

func (RawData) String

func (b RawData) String() string

func (RawData) Uint

func (b RawData) Uint() uint

Uint is a convenience wrapper over Get for uint value of a hashmap.

func (RawData) Uint64

func (b RawData) Uint64() uint64

Uint64 is a convenience wrapper over Get for uint64 value of a hashmap.

type Reply

type Reply struct {
	State string
	Data  []RawData
}

func (*Reply) Bytes

func (r *Reply) Bytes() []byte

func (*Reply) Dict

func (r *Reply) Dict() map[string][]byte

Dict retrieves the key/value pairs from reply of a hashmap.

func (*Reply) Int

func (r *Reply) Int() int

Int is a convenience wrapper over Get for int value of a hashmap.

func (*Reply) Int64

func (r *Reply) Int64() int64

Int64 is a convenience wrapper over Get for int64 value of a hashmap.

func (*Reply) Json

func (r *Reply) Json() gjson.Result

func (*Reply) KvEach

func (r *Reply) KvEach(fn func(key, value RawData)) int

func (*Reply) KvLen

func (r *Reply) KvLen() int

func (*Reply) List

func (r *Reply) List() []Entry

List retrieves the key/value pairs from reply of a hashmap.

func (*Reply) NotFound

func (r *Reply) NotFound() bool

func (*Reply) OK

func (r *Reply) OK() bool

func (*Reply) String

func (r *Reply) String() string

String is a convenience wrapper over Get for string value.

func (*Reply) Uint

func (r *Reply) Uint() uint

Uint is a convenience wrapper over Get for uint value of a hashmap.

func (*Reply) Uint64

func (r *Reply) Uint64() uint64

Uint64 is a convenience wrapper over Get for uint64 value of a hashmap.

type SSTableEntry

type SSTableEntry struct {
	FileNumber int   `json:"file_number"`
	FileSize   int64 `json:"file_size"`
}

type TableStat

type TableStat struct {
	Tables int     `json:"tables"`
	SizeMB float64 `json:"size_mb"`
	Score  float64 `json:"score"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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