Example #1
0
func main() {
	// Create a new service. Optionally include some options here.
	service := micro.NewService()
	service.Init()

	// Start the key value gossiping
	keyval := kv.NewKV()
	defer keyval.Close()

	// Start server since we have to be
	// part of the hash ring for now
	go service.Run()

	go exit()

	id := rand.Int() % 100

	for i := 0; i < 100; i++ {
		key := fmt.Sprintf("foo%d-%d", i, id)

		err := keyval.Put(&kv.Item{
			Key:        key,
			Value:      []byte(`hello`),
			Expiration: time.Second * 20,
		})
		if err != nil {
			fmt.Println("put err", err)
		}

		item, err := keyval.Get(key)
		if err != nil {
			fmt.Println("get err", err)
		} else {
			fmt.Println("get", item)
		}

		time.Sleep(time.Second)
	}
}
Example #2
0
func NewKV(opts ...kv.Option) kv.KV {
	return kv.NewKV(opts...)
}