nodis

package module
v1.0.7 Latest Latest
Warning

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

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

README

Nodis

A Golang implemented Redis data structure. It is a simple and easy to use in-memory key-value store.

Supported Data Types

  • String
  • List
  • Hash
  • Set
  • Sorted Set

Get Started

 go get github.com/diiyw/nodis 
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 does not guarantee persistence. Before closing your application, make sure to call the Sync method to save the data to disk for future use.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = &Options{
	Path:         "data",
	SyncInterval: 60 * time.Second,
}

Functions

This section is empty.

Types

type Key

type Key struct {
	Type ds.DataType
	TTL  int64
}

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(key string)

Clear removes all keys from 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, bool)

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

func (n *Nodis) Rename(key, newKey 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) Sync

func (n *Nodis) Sync() error

Sync saves the data to disk

func (*Nodis) TTL

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

TTL gets the TTL

func (*Nodis) Tidy

func (n *Nodis) Tidy() (keys map[string]*Key, store map[string]ds.DataStruct)

Tidy removes expired keys

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, score float64, member string) 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.Element

func (*Nodis) ZRangeWithScores

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

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.Element

func (*Nodis) ZRevRangeWithScores

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

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
	// SyncInterval is the interval at which the database is synced to disk
	SyncInterval time.Duration
}

Directories

Path Synopsis
ds
set
str

Jump to

Keyboard shortcuts

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