model

package
v0.0.0-...-b56bca1 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Conn net.Conn
	// database index selected
	Data *DataStorage
	// transaction info
	Multi *MultiInfo
	// collect stat
	Stat bool
}

Client entity: client information stored

func NewClient

func NewClient(conn net.Conn, dataStorage *DataStorage) *Client

NewClient returns a client selecting database 0, transaction state false

func (*Client) Del

func (c *Client) Del(key string)

Del deletes the value of correspond key

func (*Client) Get

func (c *Client) Get(key string) interface{}

Get returns correspond value of data indexed and key

func (*Client) Set

func (c *Client) Set(key string, value interface{}, expire int64) interface{}

Set puts key-value pair and its ttl in data

func (*Client) Unwatch

func (c *Client) Unwatch()

Unwatch cancel all watched keys

func (*Client) Watch

func (c *Client) Watch(key string)

Watch append key to self watch list and append self to global watch map

type CmdTask

type CmdTask struct {
	Cli *Client
	Req *token.Token
	Rsp chan *token.Token
}

CmdTask is the structure hold by the channel which sends task to execute command from server client managers to processor.

func (*CmdTask) Task

func (t *CmdTask) Task() task.Task

type DataStorage

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

DataStorage stores key-value data, expiration control heap, watched key-client map

func NewDataArray

func NewDataArray(n int) []*DataStorage

func NewDataStorage

func NewDataStorage() *DataStorage

NewDataStorage returns data storage entity with default constructor

func (*DataStorage) Del

func (d *DataStorage) Del(key string)

Del deletes the value of correspond key

func (*DataStorage) Freeze

func (d *DataStorage) Freeze() error

Freeze and following logic ensure the origin data won't change until "ToMove"

func (*DataStorage) Get

func (d *DataStorage) Get(key string) interface{}

Get returns the value of correspond key

func (*DataStorage) GetOrigin

func (d *DataStorage) GetOrigin() map[string]*Item

GetOrigin returns the original data of the data storage.

func (*DataStorage) Idx

func (d *DataStorage) Idx() int

Idx returns the index position in the data array

func (*DataStorage) Set

func (d *DataStorage) Set(key string, value interface{}, expire int64) interface{}

Set puts the new value of key

func (*DataStorage) ToMove

func (d *DataStorage) ToMove() error

ToMove notifies data storage to move items from new data to old data

type Item

type Item struct {
	Row    interface{}
	Expire int64
	// contains filtered or unexported fields
}

Item is key-value pair stored in model

type ModTask

type ModTask struct {
	Cmd     string
	DataIdx int
	Rsp     chan error
}

ModTask is the structure hold by the channel which sends task to control data persistence from server persistence goroutine to processor.

func (*ModTask) Task

func (t *ModTask) Task() task.Task

Task prevents type cast from interface to Task.

type MultiInfo

type MultiInfo struct {
	// true if transaction started
	State bool
	// true if watched key is changed
	Dirty bool
	// transaction queue
	Queue []*token.Token
	// watch keys
	Watched []*watchKey
}

MultiInfo stores transaction info related

Jump to

Keyboard shortcuts

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