Skip to content

rargulati/go-store

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

store GoDoc Build Status

store is a data-store library for Go that provides a set of platform-independent interfaces to persist and retrieve data.

Its primary goal is to wrap existing implementations of such primitives, such as those in package redis, into shared public interfaces that abstract functionality, plus some other related primitives.

It currently supports Redis from the redis package.

NOTE: This library is currently under active development and not ready for production use.

Example

The below example stores, lists and fetches the saved records

package main

import (
  "fmt"

  "github.com/gosuri/go-store/redis"
)

// Hacker implements store.Item interface methods Key and SetKey
type Hacker struct {
  Id        string
  Name      string
  Birthyear int
}

func (h *Hacker) Key() string {
  return h.Id
}

func (h *Hacker) SetKey(k string) {
  h.Id = k
}

func main() {
  db := redis.NewStore()

  // Save a hacker in the store with a auto-generated uuid
  db.Write(&Hacker{Name: "Alan Turing", Birthyear: 1912})

  var hackers []Hacker
  // Populate hackers slice with ids of all hackers in the store
  db.List(&hackers)

  alan := hackers[0]
  db.Read(&alan)
  fmt.Println("Hello,", alan.Name)

  fmt.Println("Listing all", len(hackers), "hackers")
  // Fetches all hackers with names from the store
  db.ReadMultiple(hackers)
  for _, hacker := range hackers {
    fmt.Printf("%s (%d) (%s)\n", hacker.Name, hacker.Birthyear, hacker.Id)
  }
}

Roadmap

Below are items I am and plan on working on in the near future. Contributions are welcome.

Feature Status
Save multiple records in a single call using pipelining implementing
Destroy records
Query (using finders) and indexing

Contributing

Dependency management

Users who import store into their package main are responsible to organize and maintain all of their dependencies to ensure code compatibility and build reproducibility. Store makes no direct use of dependency management tools like Godep.

We will use a variety of continuous integration providers to find and fix compatibility problems as soon as they occur.

Running Testing

$ go test

Benchmarks

$ go test -bench=.
...
BenchmarkRedisWrite     10000   178342 ns/op
BenchmarkRead           10000   119449 ns/op
BenchmarkRead1k         10   120388644 ns/op
BenchmarkRedisList1k    50    33211769 ns/op
BenchmarkRedisList10k   20    79867558 ns/op
BenchmarkReadMultiple1k 200   10372213 ns/op

About

A simple and fast Redis backed key-value store library for Go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 99.4%
  • Makefile 0.6%