kivor

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

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

Go to latest
Published: Sep 1, 2025 License: MIT Imports: 14 Imported by: 0

README

kivor

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

Example

db, _ := kivor.Open("testdb", nil)

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, nil, 10)
db.Zrscan("name", nil, nil, 10)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	HashKeyPrefix   = []byte{31}
	ZsetKeyPrefix   = []byte{30}
	ZsetScorePrefix = []byte{29}
	SplitChar       = []byte{28}
)

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

BytesToUint64 return an uint64 of v v (8-byte big endian) -> uint64(123456).

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 SetJsonField

func SetJsonField(obj interface{}, path string, value interface{}) ([]byte, error)

SetJsonField converts any input to JSON and sets a field using sjson.

func ToJsonBytes

func ToJsonBytes(v interface{}) ([]byte, error)

json utils ToJsonBytes converts a struct, map, string, or []byte into a valid JSON []byte.

func Uint64ToBytes

func Uint64ToBytes(v uint64) []byte

Uint64ToBytes returns an 8-byte big endian representation of v v uint64(123456) -> 8-byte big endian.

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) CompactAll

func (db *DB) CompactAll() 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