nodis

package module
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: GPL-3.0 Imports: 30 Imported by: 0

README

Nodis

GitHub top language GitHub Release

English | 简体中文

Nodis is a Redis implementation using the Golang programming language. This implementation provides a simple way to embed Redis functionality directly into your application or run it as a standalone server. The supported commands are compatible with the original Redis protocol, allowing you to use existing Redis clients like goredis for testing and integration.

Supported Data Types

  • Bitmap
  • String
  • List
  • Hash
  • Set
  • Sorted Set

Key Features

  • Fast and Embeddable: The Golang-based implementation is designed to be fast and easily embeddable within your applications.
  • Low Memory Usage: The system only stores hot data in memory, minimizing the overall memory footprint.
  • Snapshot and WAL for Data Storage: This Redis implementation supports snapshot and write-ahead logging (WAL) mechanisms for reliable data storage.
  • Custom Data Storage Backends: You can integrate custom data storage backends, such as Amazon S3, browser-based storage, and more.
  • Browser Support with WebAssembly: Starting from version 1.2.0, this Redis implementation can run directly in the browser using WebAssembly.
  • Remote Change Monitoring: From version 1.2.0 onwards, the system supports watching for changes from remote sources.
  • Redis Protocol Compatibility: As of version 1.5.0, this Redis implementation fully supports the original Redis protocol, ensuring seamless integration with existing Redis clients.

Supported Commands

Client Handling Configuration Key Commands String Commands Set Commands Hash Commands List Commands Sorted Set Commands Geo Commands
CLIENT FLUSHALL DEL GET SADD HSET LPUSH ZADD GEOADD
PING FLUSHDB EXISTS SET SSCAN HGET RPUSH ZCARD GEOPOS
QUIT SAVE EXPIRE INCR SCARD HDEL LPOP ZRANK GEOHASH
ECHO INFO EXPIREAT DECR SPOP HLEN RPOP ZREVRANK GEODISH
DBSIZE KEYS SETBIT SDIFF HKEYS LLEN ZSCORE GEORADIUS
MULTI TTL GETBIT SINTER HEXISTS LINDEX ZINCRBY GEORADIUSBYMEMBER
DISCARD RENAME INCR SISMEMBER HGETALL LINSERT ZRANGE
EXEC TYPE DESR SMEMBERS HINCRBY LPUSHX ZREVRANGE
SCAN SETEX SREM HICRBYFLOAT RPUSHX ZRANGEBYSCORE
RANDOMKEY INCRBY SMOVE HSETNX LREM ZREVRANGEBYSCORE
RENAMEEX DECRBY SRANDMEMBER HMGET LSET ZREM
PERSIST SETNX SINTERSTORE HMSET LRANGE ZREMRANGEBYRANK
PTTL INCRBYFLOAT SUNIONSTORE HCLEAR LPOPRPUSH ZREMRANGEBYSCORE
UNLINK APPEND HSCAN RPOPLPUSH ZCLEAR
GETRANGE HVALS BLPOP ZEXISTS
STRLEN HSTRLEN BRPOP ZUNIONSTORE
SETRANGE ZINTERSTORE

Get Started

 go get github.com/diiyw/nodis@latest

Or use test version

 go get github.com/diiyw/nodis@main
package main

import "github.com/diiyw/nodis"

func main() {
	// Create a new Nodis instance
	opt := nodis.DefaultOptions
	n := nodis.Open(opt)
	defer n.Close()
	// Set a key-value pair
	n.Set("key", []byte("value"),false)
	n.LPush("list", []byte("value1"))
}

Examples

Watch changes

Server:

package main

import (
	"fmt"
	"github.com/diiyw/nodis"
	"github.com/diiyw/nodis/pb"
	"github.com/diiyw/nodis/sync"
	"time"
)

func main() {
	var opt = nodis.DefaultOptions
	n := nodis.Open(opt)
	opt.Synchronizer = sync.NewWebsocket()
	n.Watch([]string{"*"}, func(op *pb.Operation) {
		fmt.Println("Server:", op.Key, string(op.Value))
	})
	go func() {
		for {
			time.Sleep(time.Second)
			n.Set("test", []byte(time.Now().Format("2006-01-02 15:04:05")))
		}
	}()
	err := n.Publish("127.0.0.1:6380", []string{"*"})
	if err != nil {
		panic(err)
	}
}
  • Browser client built with WebAssembly
GOOS=js GOARCH=wasm go build -o test.wasm
package main

import (
	"fmt"
	"github.com/diiyw/nodis"
	"github.com/diiyw/nodis/fs"
	"github.com/diiyw/nodis/pb"
	"github.com/diiyw/nodis/sync"
)

func main() {
	var opt = nodis.DefaultOptions
	opt.Filesystem = &fs.Memory{}
	opt.Synchronizer = sync.NewWebsocket()
	n := nodis.Open(opt)
	n.WatchKey([]string{"*"}, func(op *pb.Operation) {
		fmt.Println("Subscribe: ", op.Key)
	})
	err := n.Subscribe("ws://127.0.0.1:6380")
	if err != nil {
		panic(err)
	}
	select {}
}
Simple Redis Server
package main

import (
	"fmt"
	"net/http"

	"github.com/diiyw/nodis"
)

func main() {
	opt := nodis.DefaultOptions
	n := nodis.Open(opt)
	if err := n.Serve(":6380"); err != nil {
		fmt.Printf("Serve() = %v", err)
	}
}

You can use redis-cli to connect to the server.

redis-cli -p 6380
> set key value

Benchmark

Embed benchmark

Windows 11: 12C/32G

goos: windows
goarch: amd64
pkg: github.com/diiyw/nodis/bench
BenchmarkSet-12         	 1469863	        715.9 ns/op	     543 B/op	       7 allocs/op
BenchmarkGet-12         	12480278	        96.47 ns/op	       7 B/op	       0 allocs/op
BenchmarkLPush-12       	 1484466	        786.2 ns/op	     615 B/op	       9 allocs/op
BenchmarkLPop-12        	77275986	        15.10 ns/op	       0 B/op	       0 allocs/op
BenchmarkSAdd-12        	 1542252	        831.9 ns/op	     663 B/op	      10 allocs/op
BenchmarkSMembers-12    	12739020	        95.18 ns/op	       8 B/op	       1 allocs/op
BenchmarkZAdd-12        	 1000000	        1177 ns/op	     550 B/op	      10 allocs/op
BenchmarkZRank-12       	11430135	        104.1 ns/op	       7 B/op	       0 allocs/op
BenchmarkHSet-12        	 1341817	        863.5 ns/op	     743 B/op	      11 allocs/op
BenchmarkHGet-12        	 9801158	        105.9 ns/op	       7 B/op	       0 allocs/op

Linux VM: 4C/8GB

goos: linux
goarch: amd64
pkg: github.com/diiyw/nodis/bench
BenchmarkSet-4        	  806912	      1658 ns/op	     543 B/op	       7 allocs/op
BenchmarkGet-4        	 5941904	       190.6 ns/op	       7 B/op	       0 allocs/op
BenchmarkLPush-4      	  852932	      1757 ns/op	     615 B/op	       9 allocs/op
BenchmarkLPop-4       	40668902	        27.22 ns/op	       0 B/op	       0 allocs/op
BenchmarkSAdd-4       	  706376	      1913 ns/op	     662 B/op	      10 allocs/op
BenchmarkSMembers-4   	 4819993	       208.1 ns/op	       8 B/op	       1 allocs/op
BenchmarkZAdd-4       	  729039	      2013 ns/op	     550 B/op	      10 allocs/op
BenchmarkZRank-4      	 4959448	       246.4 ns/op	       7 B/op	       0 allocs/op
BenchmarkHSet-4       	  735676	      1971 ns/op	     742 B/op	      11 allocs/op
BenchmarkHGet-4       	 4442625	       243.4 ns/op	       7 B/op	       0 allocs/op
Redis benchmark tool
redis-benchmark -p 6380 -t set,get,lpush,lpop,sadd,smembers,zadd,zrank,hset,hget -n 100000 -q
SET: 89126.56 requests per second
GET: 90415.91 requests per second
LPUSH: 91491.30 requests per second
LPOP: 92165.90 requests per second
SADD: 91911.76 requests per second
HSET: 93023.25 requests per second

Note

If you want to persist data, please make sure to call the Close() method when your application exits.

Documentation

Index

Constants

View Source
const (
	KeyStateNormal   uint8 = 1
	KeyStateModified uint8 = 2
)
View Source
const (
	FileSizeKB = 1024
	FileSizeMB = 1024 * FileSizeKB
	FileSizeGB = 1024 * FileSizeMB
)

Variables

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

Functions

func Persist added in v1.6.0

func Persist(n *Nodis, conn *redis.Conn, cmd redis.Command)

Types

type GeoMember added in v1.8.0

type GeoMember struct {
	Longitude float64
	Latitude  float64
	Score     float64
	Member    string
}

func (*GeoMember) Hash added in v1.8.0

func (m *GeoMember) Hash() uint64

type Key

type Key struct {
	// contains filtered or unexported fields
}

type Nodis

type Nodis struct {
	// contains filtered or unexported fields
}

func Open

func Open(opt *Options) *Nodis

func (*Nodis) Append added in v1.6.0

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

Append a value to a key

func (*Nodis) BLPop

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

func (*Nodis) BRPop

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

func (*Nodis) BitCount added in v1.2.0

func (n *Nodis) BitCount(key string, start, end int64, bit bool) int64

BitCount returns the number of bits set to 1

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) Decr added in v1.5.0

func (n *Nodis) Decr(key string) (int64, error)

Decr decrement the integer value of a key by one

func (*Nodis) DecrBy added in v1.5.2

func (n *Nodis) DecrBy(key string, decrement int64) (int64, error)

func (*Nodis) Del

func (n *Nodis) Del(keys ...string) int64

Del a key

func (*Nodis) Exists

func (n *Nodis) Exists(keys ...string) int64

func (*Nodis) Expire

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

Expire the keys

func (*Nodis) ExpireAt

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

ExpireAt the keys

func (*Nodis) ExpireAtGT added in v1.5.0

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

ExpireAtGT the keys only when the new expiry is greater than current one

func (*Nodis) ExpireAtLT added in v1.5.0

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

ExpireAtLT the keys only when the new expiry is less than current one

func (*Nodis) ExpireAtNX added in v1.5.0

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

ExpireAtNX the keys only when the key has no expiry

func (*Nodis) ExpireAtXX added in v1.5.0

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

ExpireAtXX the keys only when the key has an existing expiry

func (*Nodis) ExpireGT added in v1.5.0

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

ExpireGT the keys only when the new expiry is greater than current one

func (*Nodis) ExpireLT added in v1.5.0

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

ExpireLT the keys only when the new expiry is less than current one

func (*Nodis) ExpireNX added in v1.5.0

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

ExpireNX the keys only when the key has no expiry

func (*Nodis) ExpirePX added in v1.5.0

func (n *Nodis) ExpirePX(key string, milliseconds int64) int64

ExpirePX the keys in milliseconds

func (*Nodis) ExpireXX added in v1.5.0

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

ExpireXX the keys only when the key has an existing expiry

func (*Nodis) GeoAdd added in v1.8.0

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

func (*Nodis) GeoAddNX added in v1.8.0

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

GeoAddNX adds the specified members to the key only if the member does not already exist.

func (*Nodis) GeoAddXX added in v1.8.0

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

GeoAddXX adds the specified members to the key only if the member already exists.

func (*Nodis) GeoDist added in v1.8.0

func (n *Nodis) GeoDist(key string, member1, member2 string) (float64, error)

func (*Nodis) GeoHash added in v1.8.0

func (n *Nodis) GeoHash(key string, members ...string) []string

func (*Nodis) GeoPos added in v1.8.0

func (n *Nodis) GeoPos(key string, members ...string) []*GeoMember

func (*Nodis) GeoRadius added in v1.8.0

func (n *Nodis) GeoRadius(key string, longitude, latitude, radiusMeters float64, count int64, desc bool) ([]*GeoMember, error)

func (*Nodis) GeoRadiusByMember added in v1.8.0

func (n *Nodis) GeoRadiusByMember(key, member string, radiusMeters float64, count int64, desc bool) ([]*GeoMember, error)

func (*Nodis) Get

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

Get a key

func (*Nodis) GetBit added in v1.2.0

func (n *Nodis) GetBit(key string, offset int64) int64

GetBit get a bit in a key

func (*Nodis) GetEntry added in v1.2.0

func (n *Nodis) GetEntry(key string) (data []byte)

GetEntry gets an entity

func (*Nodis) GetRange added in v1.6.0

func (n *Nodis) GetRange(key string, start, end int64) []byte

GetRange returns the substring of the string value stored at key, determined by the offsets start and end (both are inclusive).

func (*Nodis) GetSet added in v1.6.0

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

GetSet set a key with a value and return the old value

func (*Nodis) HClear

func (n *Nodis) HClear(key string)

func (*Nodis) HDel

func (n *Nodis) HDel(key string, fields ...string) int64

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, error)

func (*Nodis) HIncrByFloat

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

func (*Nodis) HKeys

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

func (*Nodis) HLen

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

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

func (*Nodis) HScan

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

func (*Nodis) HSet

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

func (*Nodis) HSetNX

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

HSetNX Sets field in the hash stored at key to value, only if field does not yet exist. If key does not exist, a new key holding a hash is created. If field already exists, this operation has no effect.

func (*Nodis) HStrLen added in v1.6.0

func (n *Nodis) HStrLen(key, field string) int64

func (*Nodis) HVals

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

func (*Nodis) Incr added in v1.5.0

func (n *Nodis) Incr(key string) (int64, error)

Incr increment the integer value of a key by one

func (*Nodis) IncrBy added in v1.5.2

func (n *Nodis) IncrBy(key string, increment int64) (int64, error)

func (*Nodis) IncrByFloat added in v1.6.0

func (n *Nodis) IncrByFloat(key string, increment float64) (float64, error)

func (*Nodis) Keys

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

Keys gets the keys

func (*Nodis) Keyspace added in v1.6.0

func (n *Nodis) Keyspace() (keys int64, expires int64, avgTTL int64)

Keyspace gets the keyspace

func (*Nodis) LIndex

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

func (*Nodis) LInsert

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

func (*Nodis) LLen

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

func (*Nodis) LPop

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

func (*Nodis) LPopRPush

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

func (*Nodis) LPush

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

func (*Nodis) LPushX

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

func (*Nodis) LRange

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

func (*Nodis) LRem

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

func (*Nodis) LSet

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

func (*Nodis) LTrim

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

func (*Nodis) MSet added in v1.6.0

func (n *Nodis) MSet(pairs ...string)

MSet sets the given keys to their respective values

func (*Nodis) PTTL added in v1.7.0

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

PTTL gets the TTL in milliseconds

func (*Nodis) Patch added in v1.2.0

func (n *Nodis) Patch(ops ...*pb.Op) error

func (*Nodis) Persist added in v1.6.0

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

Persist the key

func (*Nodis) Publish added in v1.2.0

func (n *Nodis) Publish(addr string, pattern []string) error

func (*Nodis) RPop

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

func (*Nodis) RPopLPush

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

func (*Nodis) RPush

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

func (*Nodis) RPushX

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

func (*Nodis) RandomKey added in v1.6.0

func (n *Nodis) RandomKey() string

RandomKey gets a random key

func (*Nodis) Rename

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

Rename a key

func (*Nodis) RenameNX added in v1.6.0

func (n *Nodis) RenameNX(key, dstKey string) error

RenameNX a key

func (*Nodis) SAdd

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

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

func (*Nodis) SCard

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

SCard gets the set members count.

func (*Nodis) SDiff

func (n *Nodis) SDiff(keys ...string) []string

SDiff gets the difference between sets.

func (*Nodis) SDiffStore added in v1.6.0

func (n *Nodis) SDiffStore(destination string, keys ...string) int64

SDiffStore stores the difference between sets.

func (*Nodis) SInter

func (n *Nodis) SInter(keys ...string) []string

SInter gets the intersection between sets.

func (*Nodis) SInterStore added in v1.6.0

func (n *Nodis) SInterStore(destination string, keys ...string) int64

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) SMove added in v1.6.0

func (n *Nodis) SMove(source, destination, member string) bool

SMove moves a member from one set to another.

func (*Nodis) SPop added in v1.5.0

func (n *Nodis) SPop(key string, count int64) []string

SPop removes and returns a random element from the set value stored at key.

func (*Nodis) SRandMember added in v1.6.0

func (n *Nodis) SRandMember(key string, count int64) []string

SRandMember returns one or more random elements from the set value stored at key.

func (*Nodis) SRem added in v1.1.0

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

SRem removes the specified members from the set stored at key.

func (*Nodis) SScan added in v1.5.0

func (n *Nodis) SScan(key string, cursor int64, match string, count int64) (int64, []string)

SScan scans the set value stored at key.

func (*Nodis) SUnion added in v1.6.0

func (n *Nodis) SUnion(keys ...string) []string

SUnion gets the union between sets.

func (*Nodis) SUnionStore added in v1.6.0

func (n *Nodis) SUnionStore(destination string, keys ...string) int64

func (*Nodis) Scan

func (n *Nodis) Scan(cursor int64, match string, count int64, typ ds.ValueType) (int64, []string)

Scan the keys

func (*Nodis) Serve added in v1.5.0

func (n *Nodis) Serve(addr string) error

func (*Nodis) Set

func (n *Nodis) Set(key string, value []byte, keepTTL bool)

Set a key with a value and a TTL

func (*Nodis) SetBit added in v1.2.0

func (n *Nodis) SetBit(key string, offset int64, value bool) int64

SetBit set a bit in a key

func (*Nodis) SetEX added in v1.5.0

func (n *Nodis) SetEX(key string, value []byte, seconds int64)

SetEX set a key with specified expire time, in seconds (a positive integer).

func (*Nodis) SetEntry added in v1.2.0

func (n *Nodis) SetEntry(data []byte) error

SetEntry sets an entity

func (*Nodis) SetNX added in v1.5.0

func (n *Nodis) SetNX(key string, value []byte, keepTTL bool) bool

SetNX set a key with a value if it does not exist

func (*Nodis) SetPX added in v1.5.0

func (n *Nodis) SetPX(key string, value []byte, milliseconds int64)

SetPX set a key with specified expire time, in milliseconds (a positive integer).

func (*Nodis) SetRange added in v1.6.0

func (n *Nodis) SetRange(key string, offset int64, value []byte) int64

SetRange overwrite part of a string at key starting at the specified offset

func (*Nodis) SetXX added in v1.5.0

func (n *Nodis) SetXX(key string, value []byte, keepTTL bool) bool

SetXX set a key with a value if it exists

func (*Nodis) Snapshot added in v1.0.8

func (n *Nodis) Snapshot(path string)

Snapshot saves the data to disk

func (*Nodis) StrLen added in v1.6.0

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

StrLen returns the length of the string value stored at key

func (*Nodis) Subscribe added in v1.2.0

func (n *Nodis) Subscribe(addr string) error

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) UnWatch added in v1.2.0

func (n *Nodis) UnWatch(rn *redis.Conn, keys ...string)

func (*Nodis) UnWatchKey added in v1.8.0

func (n *Nodis) UnWatchKey(id int)
func (n *Nodis) Unlink(keys ...string) int64

func (*Nodis) Watch added in v1.2.0

func (n *Nodis) Watch(rn *redis.Conn, keys ...string)

func (*Nodis) WatchKey added in v1.8.0

func (n *Nodis) WatchKey(pattern []string, fn func(op *pb.Operation)) int

func (*Nodis) ZAdd

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

func (*Nodis) ZAddGT added in v1.5.0

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

ZAddGT add member if score greater than the current score

func (*Nodis) ZAddLT added in v1.5.0

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

ZAddLT add member if score less than the current score

func (*Nodis) ZAddNX added in v1.5.0

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

func (*Nodis) ZAddXX added in v1.5.0

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

ZAddXX Only update elements that already exist. Don't add new elements.

func (*Nodis) ZCard

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

func (*Nodis) ZClear

func (n *Nodis) ZClear(key string)

func (*Nodis) ZCount added in v1.6.0

func (n *Nodis) ZCount(key string, min, max float64, mode int) int64

ZCount returns the number of elements in the sorted set at key with a score between min and max.

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) ZInter added in v1.6.0

func (n *Nodis) ZInter(keys []string, weights []float64, aggregate string) []*zset.Item

func (*Nodis) ZInterStore added in v1.6.0

func (n *Nodis) ZInterStore(destination string, keys []string, weights []float64, aggregate string) int64

ZInterStore computes the intersection of numkeys sorted sets given by the specified keys, and stores the result in destination.

func (*Nodis) ZMax added in v1.6.0

func (n *Nodis) ZMax(key string) *zset.Item

ZMax returns the member with the highest score in the sorted set at key.

func (*Nodis) ZMin added in v1.6.0

func (n *Nodis) ZMin(key string) *zset.Item

ZMin returns the member with the lowest score in the sorted set at key.

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, offset, count int64, mode int) []string

func (*Nodis) ZRangeByScoreWithScores

func (n *Nodis) ZRangeByScoreWithScores(key string, min float64, max float64, offset, count int64, mode int) []*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) (v int64, err error)

func (*Nodis) ZRankWithScore added in v1.5.0

func (n *Nodis) ZRankWithScore(key string, member string) (int64, *zset.Item)

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, mode int) 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, offset, count int64, mode int) []string

func (*Nodis) ZRevRangeByScoreWithScores

func (n *Nodis) ZRevRangeByScoreWithScores(key string, min float64, max float64, offset, count int64, mode int) []*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) (v int64, err error)

func (*Nodis) ZRevRankWithScore added in v1.5.0

func (n *Nodis) ZRevRankWithScore(key string, member string) (int64, *zset.Item)

func (*Nodis) ZScore

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

func (*Nodis) ZUnion added in v1.6.0

func (n *Nodis) ZUnion(keys []string, weights []float64, aggregate string) []*zset.Item

func (*Nodis) ZUnionStore added in v1.6.0

func (n *Nodis) ZUnionStore(destination string, keys []string, weights []float64, aggregate string) int64

ZUnionStore computes the union of numkeys sorted sets given by the specified keys, and stores the result in destination.

type Options

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

	// TidyDuration is the interval which the database is flushing unused keys to disk.
	// This is useful for reducing the risk of data loss in the event of a crash.
	// It is also used for refreshing hot keys.
	TidyDuration time.Duration

	// MaxKeyUseTimes is the maximum number of times a key can be used before it is considered hot.
	// The default value is 0, which means that the key will never be considered hot.
	// Hot keys are refreshed every TidyDuration.
	MaxKeyUseTimes uint64

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

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

	// Filesystem is the filesystem to use. The default is the memory filesystem.
	Filesystem fs.Fs

	// Synchronizer is the synchronizer to use. The default is nil and no synchronization is performed.
	Synchronizer sync.Synchronizer
}

Options represents the configuration options for the database.

type Tx added in v1.6.0

type Tx struct {
	// contains filtered or unexported fields
}

Directories

Path Synopsis
ds
set
str
examples
internal

Jump to

Keyboard shortcuts

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