database

package
v1.2.8 Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: GPL-3.0 Imports: 28 Imported by: 1

Documentation

Overview

Package database is a memory database with redis compatible interface

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Auth

func Auth(c redis.Connection, args [][]byte) redis.Reply

Auth validate client's password

func BGRewriteAOF

func BGRewriteAOF(db *MultiDB, args [][]byte) redis.Reply

BGRewriteAOF asynchronously rewrites Append-Only-File

func BGSaveRDB

func BGSaveRDB(db *MultiDB, args [][]byte) redis.Reply

BGSaveRDB asynchronously save RDB

func DiscardMulti

func DiscardMulti(conn redis.Connection) redis.Reply

DiscardMulti drops MULTI pending commands

func EnqueueCmd

func EnqueueCmd(conn redis.Connection, cmdLine [][]byte) redis.Reply

EnqueueCmd puts command line into `multi` pending queue

func GetRelatedKeys

func GetRelatedKeys(cmdLine [][]byte) ([]string, []string)

GetRelatedKeys analysis related keys

func Ping

func Ping(db *DB, args [][]byte) redis.Reply

Ping the server

func RegisterCommand

func RegisterCommand(name string, executor ExecFunc, prepare PreFunc, rollback UndoFunc, arity int)

RegisterCommand registers a new command arity means allowed number of cmdArgs, arity < 0 means len(args) >= -arity. for example: the arity of `get` is 2, `mget` is -2

func RewriteAOF

func RewriteAOF(db *MultiDB, args [][]byte) redis.Reply

RewriteAOF start Append-Only-File rewriting and blocked until it finished

func SaveRDB

func SaveRDB(db *MultiDB, args [][]byte) redis.Reply

SaveRDB start RDB writing and blocked until it finished

func StartMulti

func StartMulti(conn redis.Connection) redis.Reply

StartMulti starts multi-command-transaction

func Watch

func Watch(db *DB, conn redis.Connection, args [][]byte) redis.Reply

Watch set watching keys

Types

type CmdLine

type CmdLine = [][]byte

CmdLine is alias for [][]byte, represents a command line

type DB

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

DB stores data and execute user's commands

func (*DB) Exec

func (db *DB) Exec(c redis.Connection, cmdLine [][]byte) redis.Reply

Exec executes command within one database

func (*DB) ExecMulti

func (db *DB) ExecMulti(conn redis.Connection, watching map[string]uint32, cmdLines []CmdLine) redis.Reply

ExecMulti executes multi commands transaction Atomically and Isolated

func (*DB) Expire

func (db *DB) Expire(key string, expireTime time.Time)

Expire sets ttlCmd of key

func (*DB) Flush

func (db *DB) Flush()

Flush clean database

func (*DB) ForEach

func (db *DB) ForEach(cb func(key string, data *database.DataEntity, expiration *time.Time) bool)

ForEach traverses all the keys in the database

func (*DB) GetEntity

func (db *DB) GetEntity(key string) (*database.DataEntity, bool)

GetEntity returns DataEntity bind to given key

func (*DB) GetUndoLogs

func (db *DB) GetUndoLogs(cmdLine [][]byte) []CmdLine

GetUndoLogs return rollback commands

func (*DB) GetVersion

func (db *DB) GetVersion(key string) uint32

GetVersion returns version code for given key

func (*DB) IsExpired

func (db *DB) IsExpired(key string) bool

IsExpired check whether a key is expired

func (*DB) Persist

func (db *DB) Persist(key string)

Persist cancel ttlCmd of key

func (*DB) PutEntity

func (db *DB) PutEntity(key string, entity *database.DataEntity) int

PutEntity a DataEntity into DB

func (*DB) PutIfAbsent

func (db *DB) PutIfAbsent(key string, entity *database.DataEntity) int

PutIfAbsent insert an DataEntity only if the key not exists

func (*DB) PutIfExists

func (db *DB) PutIfExists(key string, entity *database.DataEntity) int

PutIfExists edit an existing DataEntity

func (*DB) RWLocks

func (db *DB) RWLocks(writeKeys []string, readKeys []string)

RWLocks lock keys for writing and reading

func (*DB) RWUnLocks

func (db *DB) RWUnLocks(writeKeys []string, readKeys []string)

RWUnLocks unlock keys for writing and reading

func (*DB) Remove

func (db *DB) Remove(key string)

Remove the given key from db

func (*DB) Removes

func (db *DB) Removes(keys ...string) (deleted int)

Removes the given keys from db

type ExecFunc

type ExecFunc func(db *DB, args [][]byte) redis.Reply

ExecFunc is interface for command executor args don't include cmd line

type MultiDB

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

MultiDB is a set of multiple database set

func MakeBasicMultiDB

func MakeBasicMultiDB() *MultiDB

MakeBasicMultiDB create a MultiDB only with basic abilities for aof rewrite and other usages

func NewStandaloneServer

func NewStandaloneServer() *MultiDB

NewStandaloneServer creates a standalone redis server, with multi database and all other funtions

func (*MultiDB) AfterClientClose

func (mdb *MultiDB) AfterClientClose(c redis.Connection)

AfterClientClose does some clean after client close connection

func (*MultiDB) Close

func (mdb *MultiDB) Close()

Close graceful shutdown database

func (*MultiDB) Exec

func (mdb *MultiDB) Exec(c redis.Connection, cmdLine [][]byte) (result redis.Reply)

Exec executes command parameter `cmdLine` contains command and its arguments, for example: "set key value"

func (*MultiDB) ExecMulti

func (mdb *MultiDB) ExecMulti(conn redis.Connection, watching map[string]uint32, cmdLines []CmdLine) redis.Reply

ExecMulti executes multi commands transaction Atomically and Isolated

func (*MultiDB) ExecWithLock

func (mdb *MultiDB) ExecWithLock(conn redis.Connection, cmdLine [][]byte) redis.Reply

ExecWithLock executes normal commands, invoker should provide locks

func (*MultiDB) ForEach

func (mdb *MultiDB) ForEach(dbIndex int, cb func(key string, data *database.DataEntity, expiration *time.Time) bool)

ForEach traverses all the keys in the given database

func (*MultiDB) GetDBSize

func (mdb *MultiDB) GetDBSize(dbIndex int) (int, int)

GetDBSize returns keys count and ttl key count

func (*MultiDB) GetUndoLogs

func (mdb *MultiDB) GetUndoLogs(dbIndex int, cmdLine [][]byte) []CmdLine

GetUndoLogs return rollback commands

func (*MultiDB) RWLocks

func (mdb *MultiDB) RWLocks(dbIndex int, writeKeys []string, readKeys []string)

RWLocks lock keys for writing and reading

func (*MultiDB) RWUnLocks

func (mdb *MultiDB) RWUnLocks(dbIndex int, writeKeys []string, readKeys []string)

RWUnLocks unlock keys for writing and reading

type PreFunc

type PreFunc func(args [][]byte) ([]string, []string)

PreFunc analyses command line when queued command to `multi` returns related write keys and read keys

type UndoFunc

type UndoFunc func(db *DB, args [][]byte) []CmdLine

UndoFunc returns undo logs for the given command line execute from head to tail when undo

Jump to

Keyboard shortcuts

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