hastack

package module
v0.0.0-...-0e00fdb Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2017 License: Apache-2.0 Imports: 4 Imported by: 0

README

Golang HA Stack

Build Status Godoc Reference Go Report Card

Share a thread-safe FIFO Stack across multiple hosts. HA Stack use Redis as backend and helps you to push and pop elements in your stack.

Open or connect to a Stack

Each stack have a logical name, a is accessible through redis.

    stack, err := hastack.Connect("mystack", "localhost:6379", "", 3, 100)

Push

stack, _ := hastack.Connect("mystack", "localhost:6379", "", 3, 100)

var data myData{
        ...,
}

s.Push(data)

Pop

stack, _ := hastack.Connect("mystack", "localhost:6379", "", 3, 100)
    var data myData{}
err := s.Pop(&data) //can be nil is there is no data in the stack

Blocking Pop

stack, _ = hastack.Connect("mystack", "localhost:6379", "", 3, 100)

var data myData{}

err := s.BPop(&data) //This will block the thread until data can be poped

Documentation

Overview

Package hastack aims to share a thread-safe FIFO Stack across multiple hosts. HA Stack use Redis as backend and helps you to push and pop elements in your stack. See https://github.com/fsamin/go-hastack for sample usages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Stack

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

Stack serves as a collection of elements, with two principal operations: push, which adds an element to the collection, and pop, which removes the most recently added element that was not yet removed. Hastack uses Redis ad backend and ensures thread-safe access to enable high availability capacities Import this as dependencies to manage a thread-safe FIFO Stack across multiple hosts

func Connect

func Connect(name, redisServer, password string, maxIdle, idleTimeout int) (*Stack, error)

Connect to a stack and open its connection pool to redis

func (*Stack) BPop

func (s *Stack) BPop(data interface{}) error

BPop from the stack, this is block until there is something to pop

func (*Stack) InboxLength

func (s *Stack) InboxLength() (int64, error)

InboxLength returns size of pending message

func (*Stack) OutboxLength

func (s *Stack) OutboxLength() (int64, error)

OutboxLength returns size of computed message

func (*Stack) Pop

func (s *Stack) Pop(data interface{}) error

Pop from the stack

func (*Stack) Push

func (s *Stack) Push(data interface{}) error

Push to the stack

Jump to

Keyboard shortcuts

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