database

package
v1.2.9 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2023 License: GPL-3.0 Imports: 39 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 *Server, args [][]byte) redis.Reply

BGRewriteAOF asynchronously rewrites Append-Only-File

func BGSaveRDB

func BGSaveRDB(db *Server, 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 GenGodisInfoString added in v1.2.9

func GenGodisInfoString(section string, db *Server) []byte

func GetRelatedKeys

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

GetRelatedKeys analysis related keys

func Info added in v1.2.9

func Info(db *Server, args [][]byte) redis.Reply

Info the information of the godis server returned by the INFO command

func NewPersister added in v1.2.9

func NewPersister(db database.DBEngine, filename string, load bool, fsync string) (*aof.Persister, error)

func Ping

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

Ping the server

func RewriteAOF

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

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

func SaveRDB

func SaveRDB(db *Server, 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 deprecated for test only

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 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 Server added in v1.2.9

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

Server is a redis-server with full capabilities including multiple database, rdb loader, replication

func MakeAuxiliaryServer added in v1.2.9

func MakeAuxiliaryServer() *Server

MakeAuxiliaryServer create a Server only with basic capabilities for aof rewrite and other usages

func NewStandaloneServer

func NewStandaloneServer() *Server

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

func (*Server) AddAof added in v1.2.9

func (server *Server) AddAof(dbIndex int, cmdLine CmdLine)

func (*Server) AfterClientClose added in v1.2.9

func (server *Server) AfterClientClose(c redis.Connection)

AfterClientClose does some clean after client close connection

func (*Server) Close added in v1.2.9

func (server *Server) Close()

Close graceful shutdown database

func (*Server) Exec added in v1.2.9

func (server *Server) 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 (*Server) ExecMulti added in v1.2.9

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

ExecMulti executes multi commands transaction Atomically and Isolated

func (*Server) ExecWithLock added in v1.2.9

func (server *Server) ExecWithLock(conn redis.Connection, cmdLine [][]byte) redis.Reply

ExecWithLock executes normal commands, invoker should provide locks

func (*Server) ForEach added in v1.2.9

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

ForEach traverses all the keys in the given database

func (*Server) GetAvgTTL added in v1.2.9

func (server *Server) GetAvgTTL(dbIndex, randomKeyCount int) int64

GetAvgTTL Calculate the average expiration time of keys

func (*Server) GetDBSize added in v1.2.9

func (server *Server) GetDBSize(dbIndex int) (int, int)

GetDBSize returns keys count and ttl key count

func (*Server) GetUndoLogs added in v1.2.9

func (server *Server) GetUndoLogs(dbIndex int, cmdLine [][]byte) []CmdLine

GetUndoLogs return rollback commands

func (*Server) LoadRDB added in v1.2.9

func (server *Server) LoadRDB(dec *core.Decoder) error

LoadRDB real implementation of loading rdb file

func (*Server) RWLocks added in v1.2.9

func (server *Server) RWLocks(dbIndex int, writeKeys []string, readKeys []string)

RWLocks lock keys for writing and reading

func (*Server) RWUnLocks added in v1.2.9

func (server *Server) RWUnLocks(dbIndex int, writeKeys []string, readKeys []string)

RWUnLocks unlock keys for writing and reading

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