sdb

package module
v0.0.0-...-1f07301 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2022 License: MIT Imports: 11 Imported by: 0

README

sdb

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

Example

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

See more

Users

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func B2ds

func B2ds(v []byte) string

B2ds return a Digit string of v v (8-byte big endian) -> uint64(123456) -> "123456".

func B2i

func B2i(v []byte) uint64

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

func B2s

func B2s(b []byte) string

B2s converts byte slice to a string without memory allocation. []byte("abc") -> "abc" s

func Bconcat

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

Bconcat concat a list of byte

func DS2b

func DS2b(v string) []byte

DS2b returns an 8-byte big endian representation of Digit string v ("123456") -> uint64(123456) -> 8-byte big endian.

func DS2i

func DS2i(v string) uint64

DS2i returns uint64 of Digit string v ("123456") -> uint64(123456).

func I2b

func I2b(v uint64) []byte

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

func S2b

func S2b(s string) (b []byte)

S2b converts string to a byte slice without memory allocation. "abc" -> []byte("abc")

Types

type BS

type BS []byte

func (BS) Bytes

func (b BS) Bytes() []byte

func (BS) Int

func (b BS) Int() int

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

func (BS) Int64

func (b BS) Int64() int64

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

func (BS) String

func (b BS) String() string

func (BS) Uint

func (b BS) Uint() uint

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

func (BS) Uint64

func (b BS) Uint64() uint64

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

type DB

type DB struct {
	*leveldb.DB
}

DB embeds a leveldb.DB.

func Open

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

Open creates/opens a DB at specified path, and returns a DB enclosing the same.

func (*DB) Close

func (db *DB) Close() error

Close closes the DB.

func (*DB) Hdel

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

Hdel delete specified key of a hashmap.

func (*DB) HdelBucket

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

HdelBucket delete all keys in a hashmap.

func (*DB) Hget

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

Hget get the value related to the specified key of a hashmap.

func (*DB) HgetInt

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

HgetInt get the value related to the specified key of a hashmap.

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)

Hincr increment the number stored at key in a hashmap by step.

func (*DB) Hmdel

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

Hmdel delete specified multiple keys of a hashmap.

func (*DB) Hmget

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

Hmget get the values related to the specified multiple keys of a hashmap.

func (*DB) Hmset

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

Hmset set multiple key-value pairs of a hashmap in one method call.

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

Hrscan list key-value pairs of a hashmap with keys in range (key_start, key_end], in reverse order.

func (*DB) Hscan

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

Hscan list key-value pairs of a hashmap with keys in range (key_start, key_end].

func (*DB) Hset

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

Hset set the byte value in argument as value of the key of a hashmap.

func (*DB) Zdel

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

Zdel delete specified key of a zset.

func (*DB) ZdelBucket

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

ZdelBucket delete all keys in a zset.

func (*DB) Zget

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

Zget get the score related to the specified key of a zset.

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)

Zincr increment the number stored at key in a zset by step.

func (*DB) Zmdel

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

Zmdel delete specified multiple keys of a zset.

func (*DB) Zmget

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

Zmget get the values related to the specified multiple keys of a zset.

func (*DB) Zmset

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

Zmset et multiple key-score pairs of a zset in one method call.

func (*DB) Zrscan

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

Zrscan list key-score pairs of a zset, in reverse order.

func (*DB) Zscan

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

Zscan list key-score pairs in a zset, where key-score in range (key_start+score_start, score_end].

func (*DB) Zset

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

Zset set the score of the key of a zset.

type Entry

type Entry struct {
	Key, Value BS
}

Entry a key-value pair.

type Reply

type Reply struct {
	State string
	Data  []BS
}

Reply a holder for a Entry list of a hashmap.

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

func (r *Reply) KvEach(fn func(key, value BS)) 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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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