inmemory

package
v0.0.0-...-61d8e7e Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = func() Options {
	return Options{
		ShardsCount: 256,
	}
}()

DefaultOptions default options

Functions

This section is empty.

Types

type DB

type DB struct {
	Hasher Hasher
	// contains filtered or unexported fields
}

DB indicates that all data is stored in memory. If the system restarts or crashes, all data will be lost.

func Open

func Open(options Options, ops ...Option) (*DB, error)

Open returns a newly initialized in memory DB object.

func (*DB) AllKeys

func (db *DB) AllKeys(bucket string) (keys [][]byte, err error)

AllKeys list all key of bucket.

func (*DB) Delete

func (db *DB) Delete(bucket string, key []byte) (err error)

Delete removes a key from the bucket at given bucket and key.

func (*DB) Get

func (db *DB) Get(bucket string, key []byte) (*nutsdb.Entry, error)

func (*DB) GetShard

func (db *DB) GetShard(bucket string) (shardDB *ShardDB)

GetShard Get sharded db according to bucket as hashedKey

func (*DB) LPeek

func (db *DB) LPeek(bucket string, key string) (item []byte, err error)

LPeek returns the first element of the list stored in the bucket at given bucket and key.

func (*DB) LPop

func (db *DB) LPop(bucket, key string) (item []byte, err error)

LPop removes and returns the first element of the list stored in the bucket at given bucket and key.

func (*DB) LPush

func (db *DB) LPush(bucket string, key string, values ...[]byte) error

LPush inserts the values at the head of the list stored in the bucket at given bucket,key and values.

func (*DB) LRange

func (db *DB) LRange(bucket string, key string, start, end int) (list [][]byte, err error)

LRange returns the specified elements of the list stored in the bucket at given bucket,key, start and end. The offsets start and stop are zero-based indexes 0 being the first element of the list (the head of the list), 1 being the next element and so on. Start and end can also be negative numbers indicating offsets from the end of the list, where -1 is the last element of the list, -2 the penultimate element and so on.

func (*DB) LRem

func (db *DB) LRem(bucket string, key string, count int, value []byte) (removedNum int, err error)

LRem removes the first count occurrences of elements equal to value from the list stored in the bucket at given bucket,key,count. The count argument influences the operation in the following ways: count > 0: Remove elements equal to value moving from head to tail. count < 0: Remove elements equal to value moving from tail to head. count = 0: Remove all elements equal to value.

func (*DB) LSet

func (db *DB) LSet(bucket string, key string, index int, value []byte) error

LSet sets the list element at index to value.

func (*DB) LSize

func (db *DB) LSize(bucket, key string) (size int, err error)

LSize returns the size of key in the bucket in the bucket at given bucket and key.

func (*DB) LTrim

func (db *DB) LTrim(bucket string, key string, start, end int) error

LTrim trims an existing list so that it will contain only the specified range of elements specified. the offsets start and stop are zero-based indexes 0 being the first element of the list (the head of the list), 1 being the next element and so on. start and end can also be negative numbers indicating offsets from the end of the list, where -1 is the last element of the list, -2 the penultimate element and so on.

func (*DB) Managed

func (db *DB) Managed(bucket string, writable bool, fn func(shardDB *ShardDB) error) error

Managed read and write operations of sharded db based on bucket as hashedKey

func (*DB) PrefixScan

func (db *DB) PrefixScan(bucket string, prefix []byte, offsetNum int, limitNum int) (es nutsdb.Entries, off int, err error)

PrefixScan iterates over a key prefix at given bucket, prefix and limitNum. LimitNum will limit the number of entries return.

func (*DB) Put

func (db *DB) Put(bucket string, key, value []byte, ttl uint32) (err error)

func (*DB) RPeek

func (db *DB) RPeek(bucket, key string) (item []byte, err error)

RPeek returns the last element of the list stored in the bucket at given bucket and key.

func (*DB) RPop

func (db *DB) RPop(bucket, key string) (item []byte, err error)

RPop removes and returns the last element of the list stored in the bucket at given bucket and key.

func (*DB) RPush

func (db *DB) RPush(bucket string, key string, values ...[]byte) error

RPush inserts the values at the tail of the list stored in the bucket at given bucket,key and values.

func (*DB) Range

func (db *DB) Range(bucket string, start, end []byte, f func(key, value []byte) bool) (err error)

Range query a range at given bucket, start and end slice.

func (*DB) SAdd

func (db *DB) SAdd(bucket string, key string, items ...[]byte) error

SAdd adds the specified members to the set stored int the bucket at given bucket,key and items.

func (*DB) SAreMembers

func (db *DB) SAreMembers(bucket string, key string, items ...[]byte) (areMembers bool, err error)

SAreMembers returns if the specified members are the member of the set int the bucket at given bucket,key and items.

func (*DB) SCard

func (db *DB) SCard(bucket string, key string) (itemNumber int, err error)

SCard returns the set cardinality (number of elements) of the set stored in the bucket at given bucket and key.

func (*DB) SDiffByOneBucket

func (db *DB) SDiffByOneBucket(bucket string, key1, key2 string) (list [][]byte, err error)

SDiffByOneBucket returns the members of the set resulting from the difference between the first set and all the successive sets in one bucket.

func (*DB) SDiffByTwoBuckets

func (db *DB) SDiffByTwoBuckets(bucket1 string, key1 string, bucket2 string, key2 string) (list [][]byte, err error)

SDiffByTwoBuckets returns the members of the set resulting from the difference between the first set and all the successive sets in two buckets.

func (*DB) SHasKey

func (db *DB) SHasKey(bucket string, key string) (hasKey bool, err error)

SHasKey returns if the set in the bucket at given bucket and key.

func (*DB) SIsMember

func (db *DB) SIsMember(bucket string, key string, item []byte) (isMember bool, err error)

SIsMember returns if member is a member of the set stored int the bucket at given bucket,key and item.

func (*DB) SMembers

func (db *DB) SMembers(bucket string, key string) (list [][]byte, err error)

SMembers returns all the members of the set value stored int the bucket at given bucket and key.

func (*DB) SMoveByOneBucket

func (db *DB) SMoveByOneBucket(bucket, key1, key2 string, item []byte) (isOk bool, err error)

SMoveByOneBucket moves member from the set at source to the set at destination in one bucket.

func (*DB) SMoveByTwoBuckets

func (db *DB) SMoveByTwoBuckets(bucket1 string, key1 string, bucket2 string, key2 string, item []byte) (isOK bool, err error)

SMoveByTwoBuckets moves member from the set at source to the set at destination in two buckets.

func (*DB) SPop

func (db *DB) SPop(bucket string, key string) (item []byte, err error)

SPop removes and returns one or more random elements from the set value store in the bucket at given bucket and key.

func (*DB) SRem

func (db *DB) SRem(bucket string, key string, items ...[]byte) error

SRem removes the specified members from the set stored int the bucket at given bucket,key and items.

func (*DB) SUnionByOneBucket

func (db *DB) SUnionByOneBucket(bucket string, key1, key2 string) (list [][]byte, err error)

SUnionByOneBucket the members of the set resulting from the union of all the given sets in one bucket.

func (*DB) SUnionByTwoBuckets

func (db *DB) SUnionByTwoBuckets(bucket1 string, key1 string, bucket2 string, key2 string) (list [][]byte, err error)

SUnionByTwoBuckets the members of the set resulting from the union of all the given sets in two buckets.

func (*DB) ZAdd

func (db *DB) ZAdd(bucket string, key string, score float64, val []byte) error

ZAdd adds the specified member key with the specified score and specified val to the sorted set stored at bucket.

func (*DB) ZCard

func (db *DB) ZCard(bucket string) (int, error)

ZCard returns the sorted set cardinality (number of elements) of the sorted set stored at bucket.

func (*DB) ZCount

func (db *DB) ZCount(bucket string, start, end float64, opts *zset.GetByScoreRangeOptions) (int, error)

ZCount returns the number of elements in the sorted set at bucket with a score between min and max and opts. opts includes the following parameters: Limit int // limit the max nodes to return ExcludeStart bool // exclude start value, so it search in interval (start, end] or (start, end) ExcludeEnd bool // exclude end value, so it search in interval [start, end) or (start, end)

func (*DB) ZGetByKey

func (db *DB) ZGetByKey(bucket string, key string) (node *zset.SortedSetNode, err error)

ZGetByKey returns node in the bucket at given bucket and key.

func (*DB) ZMembers

func (db *DB) ZMembers(bucket string) (dict map[string]*zset.SortedSetNode, err error)

ZMembers returns all the members of the set value stored at bucket.

func (*DB) ZRangeByRank

func (db *DB) ZRangeByRank(bucket string, start, end int) (nodes []*zset.SortedSetNode, err error)

ZRangeByRank returns all the elements in the sorted set in one bucket and key with a rank between start and end (including elements with rank equal to start or end).

func (*DB) ZRangeByScore

func (db *DB) ZRangeByScore(bucket string, start, end float64, opts *zset.GetByScoreRangeOptions) (nodes []*zset.SortedSetNode, err error)

ZRangeByScore returns all the elements in the sorted set at bucket with a score between min and max.

func (*DB) ZRank

func (db *DB) ZRank(bucket string, key string) (rank int, err error)

ZRank returns the rank of member in the sorted set stored in the bucket at given bucket and key, with the scores ordered from low to high.

func (*DB) ZRem

func (db *DB) ZRem(bucket, key string) error

ZRem removes the specified members from the sorted set stored in one bucket at given bucket and key.

func (*DB) ZRemRangeByRank

func (db *DB) ZRemRangeByRank(bucket string, start, end int) error

ZRemRangeByRank removes all elements in the sorted set stored in one bucket at given bucket with rank between start and end. the rank is 1-based integer. Rank 1 means the first node; Rank -1 means the last node.

func (*DB) ZRevRank

func (db *DB) ZRevRank(bucket string, key string) (rank int, err error)

ZRevRank returns the rank of member in the sorted set stored in the bucket at given bucket and key, with the scores ordered from high to low.

func (*DB) ZScore

func (db *DB) ZScore(bucket string, key string) (score float64, err error)

ZScore returns the score of member in the sorted set in the bucket at given bucket and key.

type Hasher

type Hasher interface {
	Sum64(string) uint64
}

Hasher is responsible for generating unsigned, 64 bit hash of provided string.

type Option

type Option func(*Options)

func WithShardsCount

func WithShardsCount(shardsCount uint64) Option

type Options

type Options struct {
	// ShardsCount represents Number of cache shards.
	ShardsCount uint64
}

type ShardDB

type ShardDB struct {
	BPTreeIdx    nutsdb.BPTreeIdx // Hint Index
	SetIdx       nutsdb.SetIdx
	SortedSetIdx nutsdb.SortedSetIdx
	ListIdx      nutsdb.ListIdx

	KeyCount int
	// contains filtered or unexported fields
}

func InitShardDB

func InitShardDB() *ShardDB

func (*ShardDB) Lock

func (sd *ShardDB) Lock(writable bool)

func (*ShardDB) Unlock

func (sd *ShardDB) Unlock(writable bool)

Jump to

Keyboard shortcuts

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