redis3

package module
v0.0.0-...-4320c2c Latest Latest
Warning

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

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

README

Build Status codecov Go Report Card GoDoc

RediS3

Poor man's HA and distributed key-value storage GO library running on top of AWS S3.

In some projects/PoC you may require some kind of persistence, perhaps accessible from different nodes/processes and in a key-value format.
RediS3 is a simple key-value library that leverages AWS S3 to provide HA and distributed persistence.

This library is in early stages and is missing some key features, but you can see what is this about, therefore PR and suggestions are very welcome.

Features

  • HA and distributed (kindly provided by AWS S3)
  • Key locking. Soft and Hard consistency
  • Store GO objects (GO built in and struct objects)
  • Key expiration
  • List keys
  • Read-only client
  • Configurable Exponential Back-Off for AWS calls
  • Client stats/metrics

Requirements

RediS3 leverages AWS S3 service to persist data. This means that the node running RediS3 requires proper access to AWS S3 service.

There are several ways to provide AWS credentials and proper access level to S3 buckets:

  • For testing purposes, run Moto AWS mock locally. Example running Moto in a Docker container:
docker pull picadoh/motocker
docker run --rm --name s3 -d -e MOTO_SERVICE=s3 -p 5001:5000 -i picadoh/motocker
export AWS_ACCESS_KEY_ID=DUMMYAWSACCESSKEY
export AWS_SECRET_ACCESS_KEY=DUMMYAWSSECRETACCESSKEY

  • For testing purposes, use Roly to use AWS S3 with STS tokens in your local machine.
  • If you are running RediS3 on an EC2 instance, attach an Instance Profile with proper permissions to the EC2 instance.
  • (Not recommended) use environment variables to provide proper access credentials.

Installation

Install:

go get -u github.com/danfaizer/redis3

Import:

import "github.com/danfaizer/redis3"

Quickstart

// Create RediS3 client
client, err := redis3.NewClient(
  &redis3.Options{
    Bucket:             "redis3-database",
    AutoCreateBucket:   true,
    Region:             "eu-west-1",
    Timeout:            1,
    EnforceConsistency: true,
  })
if err != nil {
  panic(err)
}
type person struct {
    uuid string
    name string
    age  int
}

p := person{
  uuid: "123e4567-e89b-12d3-a456-426655440000",
  name: "Daniel",
  age:  35,
}

var err error

err = client.Set(p.id, p, 0)
if err != nil {
  panic(err)
}

var b person

_, err = client.Get("123e4567-e89b-12d3-a456-426655440000", &b)
if err != nil {
  panic(err)
}

fmt.Printf("%+v", b)
{uuid:123e4567-e89b-12d3-a456-426655440000 name:Daniel age:35}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client defines a RediS3 client

func NewClient

func NewClient(opt *Options) (*Client, error)

NewClient returns a RediS3 client.

func (*Client) Del

func (c *Client) Del(key string) error

Del TBD

func (*Client) Get

func (c *Client) Get(key string, value interface{}) (KeyMetadata, error)

Get TBD

func (*Client) Lock

func (c *Client) Lock(key string) error

Lock TBD

func (*Client) Ping

func (c *Client) Ping() error

Ping AWS S3 "database" bucket to check connectivity.

func (*Client) Set

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

Set TBD

func (*Client) Unlock

func (c *Client) Unlock(key string) error

Unlock TBD

type KeyMetadata

type KeyMetadata struct {
	ValueType  string
	Locked     bool
	ExpireTime int64
	LastUpdate int64
}

KeyMetadata defines RediS3 key matadata which provides some useful information about the stored object.

type Options

type Options struct {
	// AWS S3 bucket to be selected as database persistent storage.
	Bucket string

	// When AutoCreateBucket is set to true the client will try to create the
	// the AWS S3 bucket if it doesn't exist.
	// Of course, AWS credentials/instance profile requires proper permissions
	// so the client can create the bucket in S3.
	// Default is false.
	AutoCreateBucket bool

	// AWS Region where S3 bucket is located/created.
	Region string

	// AWS API Endpoint
	Endpoint string

	// Timeout defines S3 upload timeout in seconds.
	// If not defined or set to 0, there is no timeout.
	Timeout int

	// EnforceConsistency enables key locking while modifying keys.
	// This increases the number of requests to AWS S3 API and decreases
	// performance signlificantly but consistency is warranted when several
	// clients are modifying same key.
	// Default is false.
	EnforceConsistency bool
	// contains filtered or unexported fields
}

Options defines RediS3 client option

Jump to

Keyboard shortcuts

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