Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Jan 15, 2022. It is now read-only.

bukalapak/dallimin

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
30 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dallimin

Build Status GoDoc

Dalli Ring written in Go.

Usage

Say, we have ruby program that use dalli to save our data to memcache:

require 'dalli'
require 'json'

options = { namespace: 'api', compress: true, serializer: JSON }
servers = %w(
  cache1.example.com:11210
  cache2.example.com:11211
  cache3.example.com:11212
)

client = Dalli::Client.new(servers, options)

client.set('v1/foo', foo: 'bar')
client.set('say:hello', 'World!')

puts client.get('v1/foo')
puts client.get('say:hello')

Then, we can access that within Go by using:

package main

import (
	"bytes"
	"encoding/json"
	"fmt"

	"github.com/bradfitz/gomemcache/memcache"
	"github.com/bukalapak/dallimin"
)

func checkErr(err error) {
	if err != nil {
		panic(err)
	}
}

func main() {
    option := dallimin.Option{
        CheckAlive: true,
        Failover: true,
    }

	servers := []string{
		"cache1.example.com:11210",
		"cache2.example.com:11211",
		"cache3.example.com:11212",
	}

    ss, err := dallimin.New(servers, option)

	checkErr(err)

	client := memcache.NewFromSelector(ss)

	type Data struct {
		Foo string `json:"foo"`
	}

	it, err := client.Get("api:v1/foo")
	checkErr(err)

	a := &Data{}
	b := bytes.NewReader(it.Value)
	j := json.NewDecoder(b)
	checkErr(err)

	err = j.Decode(a)
	checkErr(err)

	fmt.Printf("%s => %#v\n", it.Key, a) // RETURNS: api:v1/foo => &main.Data{Foo:"bar"}

	it, err = client.Get("api:say:hello")
	checkErr(err)

	fmt.Printf("%s => %s\n", it.Key, string(it.Value)) // RETURNS: api:say:hello => "World!"
}

That's it.

About

Dalli compatible server selector for Golang (gomemcache)

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.