All Projects → otiai10 → rodeo

otiai10 / rodeo

Licence: other
Simple Redis Client for Golang

Programming Languages

go
31211 projects - #10 most used programming language

rodeo Build Status GoDoc

"rodeo" is a simple Redis client for Go.

rodeo

API Samples

Set & Get

can set and get strings by keys.

vaquero, _ := rodeo.NewVaquero("localhost","6379")

// Set
_ = vaquero.Set("my_key", "12345")

// Get
val := vaquero.Get("my_key")
// string "12345"

Store & Cast

can set and get objects by keys.

type Sample struct {
    Foo string
}

vaquero, _ := rodeo.NewVaquero("localhost","6379")

// Store
obj := Sample{"this is foo"}
_ = vaquero.Store("my_key", obj)

// Cast
var dest Sample
_ = vaquero.Cast("my_key", &dest)
// *Sample{"this is foo"}

Pub & Sub

vaqueroA, _ := rodeo.NewVaquero("localhost","6379")
go func(){
    for {
        message := <-vaqueroA.Sub("mychan")
        // Hi, this is vaqueroB
    }
}()

vaqueroB, _ := rodeo.NewVaquero("localhost","6379")
_ = vaqueroB.Pub("mychan", "Hi, this is vaqueroB")

Tame

can provide active model for Sorted Sets of Redis.

type Member struct {
    Name string
}

vaquero, _ := rodeo.NewVaquero("localhost","6379")
// Give representative dummy object in second arg
members, _ := vaquero.Tame("members", Member{})

members.Count() // 0
members.Range().([]Member) // []

members.Add(1020, Member{"John"})
members.Add(1001, Member{"Paul"})
members.Add(1012, Member{"Ringo"})
members.Add(1100, Member{"George"})

// COUNT members -inf +inf
members.Count() // 4

// ZRANGE members -inf +inf
found := members.Find()
found[0].Score() // 1001
found[0].Retrieve().(*Member) // &Member{Name:Paul}

Test

go test ./...
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].