spotcache

package
v0.0.0-...-0f2463b Latest Latest
Warning

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

Go to latest
Published: May 28, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResponseOk    = "ok"
	ResponseFail  = "fail"
	ResponseTrue  = "true"
	ResponseFalse = "false"
	ResponsePong  = "pong"
)

public constants

View Source
const (
	NOOP        = CommandOp(0)
	PUT         = CommandOp(1)
	GET         = CommandOp(2)
	HAS         = CommandOp(3)
	DELETE      = CommandOp(4)
	BATCH       = CommandOp(9)
	EXPIRE      = CommandOp(10)
	TTL         = CommandOp(11)
	SUBSCRIBE   = CommandOp(20)
	UNSUBSCRIBE = CommandOp(21)
	PUBLISH     = CommandOp(22)
	KEYS        = CommandOp(30)
	BACKUP      = CommandOp(110)
	CLEAR       = CommandOp(119)
	STATUS      = CommandOp(127)
	PING        = CommandOp(128)
	SHUTDOWN    = CommandOp(255)
)

manually assign the op codes...

Variables

This section is empty.

Functions

func CreateLogFolder

func CreateLogFolder(logpath string) error

CreateLogFolder - create the log folder if it doesn't already exist

func CreateLogger

func CreateLogger(cfg *Config) *logger.Logger

CreateLogger create a new logger based on config

func CreateSessionID

func CreateSessionID() string

CreateSessionID returns a string of 12 chars

func IsProduction

func IsProduction(env string) bool

IsProduction return true if the current env is production

func StartClientSession

func StartClientSession(conn net.Conn) (string, error)

StartClientSession create a client session id and send to the new client (move to sock utils?)

func Version

func Version() string

Version - return the version number as a single string

Types

type Cache

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

Cache the cache object

func NewCache

func NewCache(cfg *Config) *Cache

NewCache create a new cache object

func (Cache) Close

func (c Cache) Close()

Close close the cache db

func (Cache) CreateOptions

func (c Cache) CreateOptions() *bolt.Options

CreateOptions create the cache options

func (Cache) Delete

func (c Cache) Delete(key []byte) error

Delete delete the data based on key

func (Cache) Get

func (c Cache) Get(key []byte) ([]byte, error)

Get return the data from key; return nil,nil on not found

func (Cache) Has

func (c Cache) Has(key []byte) (bool, error)

Has return true if cache has the key

func (Cache) Keys

func (c Cache) Keys() ([]string, error)

Keys return all keys in the database

func (Cache) Open

func (c Cache) Open() error

Open open the cache db

func (Cache) Put

func (c Cache) Put(key, value []byte, ttl TTLSeconds) error

Put define the methods get, put, delete, has, ttl, etc...

func (*Cache) TTL

func (c *Cache) TTL(key []byte) TTLSeconds

TTL return the time to live

type CacheService

type CacheService struct {
	ClientCount int
	CreateDate  time.Time
	Port        int
	DbPath      string
	Timeout     time.Duration
	// contains filtered or unexported fields
}

CacheService - the main struct with client count, port, etc

func NewCacheService

func NewCacheService(cfg *Config) CacheService

NewCacheService - create a cache service

func (*CacheService) CreateListener

func (s *CacheService) CreateListener() (*net.TCPListener, error)

CreateListener create the listener for the specified address/port

func (*CacheService) InitializeCache

func (s *CacheService) InitializeCache(cfg *Config)

InitializeCache configure the commander and cache database

func (*CacheService) ListenAndServe

func (s *CacheService) ListenAndServe(ss *net.TCPListener)

ListenAndServe open the cache database and start the main socket service; block forever...

func (*CacheService) OpenClientHandler

func (s *CacheService) OpenClientHandler(conn net.Conn)

OpenClientHandler handle client requests as long as they stay connected

func (*CacheService) Shutdown

func (s *CacheService) Shutdown()

Shutdown - stop everything

type Command

type Command struct {
	ID    IDType
	Op    CommandOp
	Key   []byte
	Value []byte
	Resp  []byte
}

Command command object to support executions

func CreateCommand

func CreateCommand(id IDType, op CommandOp, key, value []byte) *Command

CreateCommand a public helper method to create a full comman structure

func (*Command) Exec

func (cmd *Command) Exec() error

Exec execute the command as specified in the command structure

func (*Command) String

func (cmd *Command) String() string

a string representation of the command buffer

type CommandOp

type CommandOp uint8

CommandOp the op type

type Commander

type Commander struct {
}

Commander the commander struct

func NewCommander

func NewCommander(db *Cache) *Commander

NewCommander create a new command object

type Config

type Config struct {
	Home     string // defaults to user's home
	Env      string // defaults to production
	Logpath  string
	Logname  string
	Dbpath   string
	Baseport int
	Timeout  int64
}

Config the config structure

func NewConfigForEnvironment

func NewConfigForEnvironment(env string) *Config

NewConfigForEnvironment configure for a specific environment

func NewDefaultConfig

func NewDefaultConfig() *Config

NewDefaultConfig default settings

func ParseArgs

func ParseArgs() *Config

ParseArgs parse the command line args

type IDType

type IDType [26]byte

IDType 26 bytes

func CreateCommandID

func CreateCommandID() IDType

CreateCommandID create a command id

type Request

type Request struct {
	ID       IDType
	Session  SessionType
	Op       CommandOp
	MetaSize uint16
	KeySize  uint16
	DataSize uint32
	Metadata []byte
	Key      []byte
	Value    []byte
}

Request request object as created by the client

func RequestFromBytes

func RequestFromBytes(buf []byte) (*Request, error)

RequestFromBytes decode the little endian bytes and parse into request object

func (*Request) CreateResponse

func (req *Request) CreateResponse(value, metadata []byte) *Response

CreateResponse create a response object from the reqest, response value and new meta data

func (*Request) String

func (req *Request) String() string

func (*Request) ToBytes

func (req *Request) ToBytes() ([]byte, error)

ToBytes encode the request into a stream of little endian bytes; return error if encoding fails

type RequestBuilder

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

RequestBuilder holds the session

func NewRequestBuilder

func NewRequestBuilder(sess SessionType) *RequestBuilder

NewRequestBuilder return a new request builder object

func (*RequestBuilder) CreateDeleteRequest

func (rb *RequestBuilder) CreateDeleteRequest(key, metadata []byte) *Request

CreateDeleteRequest create a delete request op

func (*RequestBuilder) CreateGetRequest

func (rb *RequestBuilder) CreateGetRequest(key, metadata []byte) *Request

CreateGetRequest create a get request

func (*RequestBuilder) CreateHasRequest

func (rb *RequestBuilder) CreateHasRequest(key, metadata []byte) *Request

CreateHasRequest return the has request op

func (*RequestBuilder) CreateKeysRequest

func (rb *RequestBuilder) CreateKeysRequest(key, metadata []byte) *Request

CreateKeysRequest create a keys request

func (*RequestBuilder) CreatePingRequest

func (rb *RequestBuilder) CreatePingRequest() *Request

CreatePingRequest create a simple ping request

func (*RequestBuilder) CreatePutRequest

func (rb *RequestBuilder) CreatePutRequest(key, value, metadata []byte) *Request

CreatePutRequest create a put command with the current session

func (RequestBuilder) NewRequest

func (rb RequestBuilder) NewRequest(op CommandOp) Request

NewRequest create a new request object

type Response

type Response struct {
	ID       IDType
	Session  SessionType
	Op       CommandOp
	MetaSize uint16
	DataSize uint32
	Metadata []byte
	Data     []byte
}

Response request object as created by the client

func ResponseFromBytes

func ResponseFromBytes(buf []byte) (*Response, error)

ResponseFromBytes decode the little endian bytes and parse into response object

func (*Response) String

func (res *Response) String() string

func (*Response) ToBytes

func (res *Response) ToBytes() ([]byte, error)

ToBytes encode the response into a stream of little endian bytes; return error if encoding fails

type SessionType

type SessionType [12]byte

SessionType - 12 bytes

type TTLSeconds

type TTLSeconds int64

TTLSeconds compatible with time.Unix() in seconds

Jump to

Keyboard shortcuts

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