Skip to content

murtaza-u/dream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dream is an in-memory key-value data store.


Usage

go get -u github.com/murtaza-u/dream
package main

import (
	"fmt"
	"log"

	"github.com/murtaza-u/dream"
)

type User struct {
	Name string
	Age  int
}

func main() {
	s := dream.New()
	// OR
	// With automatic clean up
	// s := dream.New(dream.WithCleanUp(time.Hour))

	s.Put("foo", "bar")
	s.Put("bar", true)
	s.Put("blah", 100)
	s.Put("user", User{
		Name: "Alice",
		Age:  30,
	})

	fmt.Printf("foo=%s\n", s.GetString("foo"))
	fmt.Printf("bar=%v\n", s.GetBool("bar"))
	fmt.Printf("blah=%d\n", s.GetInt("blah"))

	u, ok := s.Get("user").(User)
	if !ok {
		log.Fatal("failed to retrieve user")
	}
	fmt.Printf("user.name=%s | user.age=%d\n", u.Name, u.Age)
}

Full API reference: GoDoc