func (s *Zookeeper) Exists(key string, opts *store.ReadOptions) (bool, error) {
	exists, _, err := s.client.Exists(s.normalize(key))
	if err != nil {
		return false, err
	}
	return exists, nil
}
Exists checks if the key exists inside the store
package zookeeper
import (
	"strings"
	"time"
	"github.com/abronan/valkeyrie"
	"github.com/abronan/valkeyrie/store"
	"github.com/samuel/go-zookeeper/zk"
)
const (
	SOH = "\x01"
	defaultTimeout = 10 * time.Second
	syncRetryLimit = 5
)
type Zookeeper struct {
	timeout time.Duration
	client  *zk.Conn
}
type zookeeperLock struct {
	client *zk.Conn
	lock   *zk.Lock
	key    string
	value  []byte
}
func Register() {
	valkeyrie.AddStore(store.ZK, New)
}
func New(endpoints []string, options *store.Config) (store.Store, error) {
	s := &Zookeeper{}
	s.timeout = defaultTimeout
	if options != nil {
		if options.ConnectionTimeout != 0 {
			s.setTimeout(options.ConnectionTimeout)
		}
	}
	conn, _, err := zk.Connect(endpoints, s.timeout)
	if err != nil {
		return nil, err
	}
	s.client = conn
	return s, nil
}
func (s *Zookeeper) setTimeout(time time.Duration) {
	s.timeout = time
}
func (s *Zookeeper) Get(key string, opts *store.ReadOptions) (pair *store.KVPair, err error) {
	resp, meta, err := s.get(key)
	if err != nil {
		return nil, err
	}
	pair = &store.KVPair{
		Key:       key,
		Value:     resp,
		LastIndex: uint64(meta.Version),
	}
	return pair, nil
}
func (s *Zookeeper) createFullPath(path []string, data []byte, ephemeral bool) error {
	for i := 1; i <= len(path); i++ {
		newpath := "/" + strings.Join(path[:i], "/")
		if i == len(path) {
			flag := 0
			if ephemeral {
				flag = zk.FlagEphemeral
			}
			_, err := s.client.Create(newpath, data, int32(flag), zk.WorldACL(zk.PermAll))
			return err
		}
		_, err := s.client.Create(newpath, []byte{}, 0, zk.WorldACL(zk.PermAll))
		if err != nil {
			if err != zk.ErrNodeExists {
				return err
			}
		}
	}
	return nil
}
func (s *Zookeeper) Put(key string, value []byte, opts *store.WriteOptions) error {
	fkey := s.normalize(key)
	exists, err := s.Exists(key, nil)
	if err != nil {
		return err
	}
	if !exists {
		if opts != nil && opts.TTL > 0 {
			_ = s.createFullPath(store.SplitKey(strings.TrimSuffix(key, "/")), value, true)
		} else {
			_ = s.createFullPath(store.SplitKey(strings.TrimSuffix(key, "/")), value, false)
		}
	} else {
		_, err = s.client.Set(fkey, value, -1)
	}
	return err
}
func (s *Zookeeper) Delete(key string) error {
	err := s.client.Delete(s.normalize(key), -1)
	if err == zk.ErrNoNode {
		return store.ErrKeyNotFound
	}
	return err
}