nodis

package module
v1.1.0-beta.5 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

README

Nodis

GitHub top language GitHub Release

English | 简体中文

A Golang implemented Redis data structure. It is a simple and easy to embed in your application.

Supported Data Types

  • String
  • List
  • Hash
  • Set
  • Sorted Set

Features

  • Fast and embeddable
  • Low memory used, only hot data stored in memory
  • Snapshot and WAL for data storage.

Get Started

 go get github.com/diiyw/nodis@v1.1.0-beta.5
package main

import "github.com/diiyw/nodis"

func main() {
	// Create a new Nodis instance
	opt := nodis.DefaultOptions
	n := nodis.Open(opt)

	// Set a key-value pair
	n.Set("key", []byte("value"), 0)
	n.LPush("list", []byte("value1"))
}

Note

Nodis is done by following the Redis data structure. It is not a complete Redis server. It is a simple and easy to embed in your application.

Documentation

Index

Constants

View Source
const (
	FileSizeKB = 1024
	FileSizeMB = 1024 * FileSizeKB
	FileSizeGB = 1024 * FileSizeMB
)

Variables

View Source
var DefaultOptions = &Options{
	Path:            "data",
	FileSize:        FileSizeGB,
	RecycleDuration: 60 * time.Second,
}
View Source
var (
	ErrCorruptedData = errors.New("corrupted data")
)

Functions

This section is empty.

Types

type Entity added in v1.1.0

type Entity struct {
	Key       string
	Value     ds.DataStruct
	ExpiredAt int64
}

func (*Entity) Marshal added in v1.1.0

func (e *Entity) Marshal() ([]byte, error)

Marshal marshals the entry

func (*Entity) Unmarshal added in v1.1.0

func (e *Entity) Unmarshal(data []byte) error

Unmarshal unmarshals the entry

type Key

type Key struct {
	ExpiredAt int64

	Type ds.DataType
	// contains filtered or unexported fields
}

type Nodis

type Nodis struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func Open

func Open(opt *Options) *Nodis

func (*Nodis) BLPop

func (n *Nodis) BLPop(key string, timeout time.Duration) []byte

func (*Nodis) BRPop

func (n *Nodis) BRPop(key string, timeout time.Duration) []byte

func (*Nodis) Clear

func (n *Nodis) Clear()

Clear removes all keys from the store

func (*Nodis) Close added in v1.0.8

func (n *Nodis) Close() error

Close the store

func (*Nodis) Del

func (n *Nodis) Del(key string)

Del a key

func (*Nodis) Exists

func (n *Nodis) Exists(key string) bool

func (*Nodis) Expire

func (n *Nodis) Expire(key string, seconds int64)

Expire the keys

func (*Nodis) ExpireAt

func (n *Nodis) ExpireAt(key string, timestamp time.Time)

ExpireAt the keys

func (*Nodis) Get

func (n *Nodis) Get(key string) []byte

Get a key

func (*Nodis) HClear

func (n *Nodis) HClear(key string)

func (*Nodis) HDel

func (n *Nodis) HDel(key string, field string)

func (*Nodis) HExists

func (n *Nodis) HExists(key string, field string) bool

func (*Nodis) HGet

func (n *Nodis) HGet(key string, field string) []byte

func (*Nodis) HGetAll

func (n *Nodis) HGetAll(key string) map[string][]byte

func (*Nodis) HIncrBy

func (n *Nodis) HIncrBy(key string, field string, value int64) int64

func (*Nodis) HIncrByFloat

func (n *Nodis) HIncrByFloat(key string, field string, value float64) float64

func (*Nodis) HKeys

func (n *Nodis) HKeys(key string) []string

func (*Nodis) HLen

func (n *Nodis) HLen(key string) int

func (*Nodis) HMGet

func (n *Nodis) HMGet(key string, fields ...string) [][]byte

func (*Nodis) HMSet

func (n *Nodis) HMSet(key string, fields map[string][]byte)

func (*Nodis) HScan

func (n *Nodis) HScan(key string, cursor int, match string, count int) (int, map[string][]byte)

func (*Nodis) HSet

func (n *Nodis) HSet(key string, field string, value []byte)

func (*Nodis) HSetNX

func (n *Nodis) HSetNX(key string, field string, value []byte) bool

func (*Nodis) HVals

func (n *Nodis) HVals(key string) [][]byte

func (*Nodis) Keys

func (n *Nodis) Keys(pattern string) []string

Keys gets the keys

func (*Nodis) LIndex

func (n *Nodis) LIndex(key string, index int) []byte

func (*Nodis) LInsert

func (n *Nodis) LInsert(key string, pivot, data []byte, before bool) int

func (*Nodis) LLen

func (n *Nodis) LLen(key string) int

func (*Nodis) LPop

func (n *Nodis) LPop(key string) []byte

func (*Nodis) LPopRPush

func (n *Nodis) LPopRPush(source, destination string) []byte

func (*Nodis) LPush

func (n *Nodis) LPush(key string, values ...[]byte)

func (*Nodis) LPushX

func (n *Nodis) LPushX(key string, data []byte) int

func (*Nodis) LRange

func (n *Nodis) LRange(key string, start, stop int) [][]byte

func (*Nodis) LRem

func (n *Nodis) LRem(key string, count int, data []byte) int

func (*Nodis) LSet

func (n *Nodis) LSet(key string, index int, data []byte) bool

func (*Nodis) LTrim

func (n *Nodis) LTrim(key string, start, stop int)

func (*Nodis) RPop

func (n *Nodis) RPop(key string) []byte

func (*Nodis) RPopLPush

func (n *Nodis) RPopLPush(source, destination string) []byte

func (*Nodis) RPush

func (n *Nodis) RPush(key string, values ...[]byte)

func (*Nodis) RPushX

func (n *Nodis) RPushX(key string, data []byte) int

func (*Nodis) Recycle added in v1.0.8

func (n *Nodis) Recycle()

Recycle removes expired and unused keys

func (*Nodis) Rename

func (n *Nodis) Rename(key, key2 string) error

Rename a key

func (*Nodis) SAdd

func (n *Nodis) SAdd(key string, members ...string) int

SAdd adds the specified members to the set stored at key.

func (*Nodis) SCard

func (n *Nodis) SCard(key string) int

SCard gets the set members count.

func (*Nodis) SDiff

func (n *Nodis) SDiff(key string, sets ...string) []string

SDiff gets the difference between sets.

func (*Nodis) SInter

func (n *Nodis) SInter(key string, sets ...string) []string

SInter gets the intersection between sets.

func (*Nodis) SIsMember

func (n *Nodis) SIsMember(key, member string) bool

SIsMember returns if member is a member of the set stored at key.

func (*Nodis) SMembers

func (n *Nodis) SMembers(key string) []string

SMembers returns all the members of the set value stored at key.

func (*Nodis) Scan

func (n *Nodis) Scan(cursor int, match string, count int) (int, []string)

Scan the keys

func (*Nodis) Set

func (n *Nodis) Set(key string, value []byte, ttl int64)

Set a key with a value and a TTL

func (*Nodis) Snapshot added in v1.0.8

func (n *Nodis) Snapshot(path string)

Snapshot saves the data to disk

func (*Nodis) TTL

func (n *Nodis) TTL(key string) time.Duration

TTL gets the TTL

func (*Nodis) Type

func (n *Nodis) Type(key string) string

Type gets the type of key

func (*Nodis) ZAdd

func (n *Nodis) ZAdd(key string, member string, score float64)

func (*Nodis) ZCard

func (n *Nodis) ZCard(key string) int64

func (*Nodis) ZClear

func (n *Nodis) ZClear(key string)

func (*Nodis) ZExists

func (n *Nodis) ZExists(key string, member string) bool

func (*Nodis) ZIncrBy

func (n *Nodis) ZIncrBy(key string, member string, score float64) float64

func (*Nodis) ZRange

func (n *Nodis) ZRange(key string, start int64, stop int64) []string

func (*Nodis) ZRangeByScore

func (n *Nodis) ZRangeByScore(key string, min float64, max float64) []string

func (*Nodis) ZRangeByScoreWithScores

func (n *Nodis) ZRangeByScoreWithScores(key string, min float64, max float64) []*zset.Item

func (*Nodis) ZRangeWithScores

func (n *Nodis) ZRangeWithScores(key string, start int64, stop int64) []*zset.Item

func (*Nodis) ZRank

func (n *Nodis) ZRank(key string, member string) int64

func (*Nodis) ZRem

func (n *Nodis) ZRem(key string, members ...string) int64

func (*Nodis) ZRemRangeByRank

func (n *Nodis) ZRemRangeByRank(key string, start int64, stop int64) int64

func (*Nodis) ZRemRangeByScore

func (n *Nodis) ZRemRangeByScore(key string, min float64, max float64) int64

func (*Nodis) ZRevRange

func (n *Nodis) ZRevRange(key string, start int64, stop int64) []string

func (*Nodis) ZRevRangeByScore

func (n *Nodis) ZRevRangeByScore(key string, min float64, max float64) []string

func (*Nodis) ZRevRangeByScoreWithScores

func (n *Nodis) ZRevRangeByScoreWithScores(key string, min float64, max float64) []*zset.Item

func (*Nodis) ZRevRangeWithScores

func (n *Nodis) ZRevRangeWithScores(key string, start int64, stop int64) []*zset.Item

func (*Nodis) ZRevRank

func (n *Nodis) ZRevRank(key string, member string) int64

func (*Nodis) ZScore

func (n *Nodis) ZScore(key string, member string) float64

type Options

type Options struct {
	// Path is the path to the database.
	Path string

	// RecycleDuration is the interval at which the database is recycled .
	// This is useful for reducing the risk of data loss in the event of a crash.
	// It is also used for refreshing hot keys.
	RecycleDuration time.Duration

	// FileSize is the size of each file. The default value is 1GB.
	FileSize int64

	// SnapshotDuration is the interval at which the database is snapshotted.
	// Default 0 for disabling snapshot. and you can call Snapshot manually.
	SnapshotDuration time.Duration
}

Options represents the configuration options for the database.

Directories

Path Synopsis
ds
set
str

Jump to

Keyboard shortcuts

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