func (s *Service) DelSession(key interface{}) error {
	err := s.store.DelSession(key)
	if err == errNotLeader {
		var keyStr string
		var ok bool
		if keyStr, ok = key.(string); !ok {
			return fmt.Errorf("session key type error, not a string")
		}
		return s.writeLeader(map[string][]byte{
			"key":  []byte(keyStr),
			"type": typDelSession,
		})
	}
	return err
}
DelSession delete the session from given key.
package cluster
import (
	"bytes"
	"encoding/json"
	"fmt"
	"net"
	"time"
	"github.com/lodastack/store/model"
	"github.com/hashicorp/raft"
)
var errNotLeader = raft.ErrNotLeader
var (
	typCBucket         = []byte("createrBucket")
	typRBucket         = []byte("removeBucket")
	typUpdate          = []byte("update")
	typBatch           = []byte("batch")
	typCBucketNotExist = []byte("createBucketIfNotExist")
	typRkey            = []byte("removekey")
	typSetSession = []byte("setsession")
	typDelSession = []byte("delsession")
	typJoin   = []byte("join")
	typRemove = []byte("remove")
	typPeer   = []byte("peer")
	leader   = "Leader"
	follower = "Follower"
)
type response struct {
	Code    int    `json:"code,omitempty"`
	Message string `json:"message,omitempty"`
}
func (s *Service) SetPeer(raftAddr, apiAddr string) error {
	err := s.store.UpdateAPIPeers(map[string]string{raftAddr: apiAddr})
	if err == errNotLeader {
		return s.writeLeader(map[string][]byte{
			"api":  []byte(apiAddr),
			"raft": []byte(raftAddr),
			"type": typPeer,
		})
	}
	return err
}
func (s *Service) Join(addr string) error {
	err := s.store.Join(addr)
	if err == errNotLeader {
		return s.writeLeader(map[string][]byte{
			"addr": []byte(addr),
			"type": typJoin,
		})
	}
	return err
}
func (s *Service) Peers() (map[string]map[string]string, error) {
	peerMap := make(map[string]map[string]string)
	peers, err := s.store.APIPeers()
	if err != nil {
		return nil, err
	}
	Leadership := s.store.Leader()
	for raftAddr, apiAddr := range peers {
		peerMap[raftAddr] = make(map[string]string)
		peerMap[raftAddr]["api"] = apiAddr
		if raftAddr == Leadership {
			peerMap[raftAddr]["role"] = leader
		} else {
			peerMap[raftAddr]["role"] = follower
		}
	}
	return peerMap, nil
}
func (s *Service) Nodes() ([]string, error) {
	return s.store.Nodes()
}
func (s *Service) WaitForLeader(timeout time.Duration) (string, error) {
	return s.store.WaitForLeader(timeout)
}
func (s *Service) Remove(addr string) error {
	err := s.store.Remove(addr)
	if err == errNotLeader {
		return s.writeLeader(map[string][]byte{
			"addr": []byte(addr),
			"type": typRemove,
		})
	}
	return err
}
func (s *Service) CreateBucket(name []byte) error {
	err := s.store.CreateBucket(name)
	if err == errNotLeader {
		return s.writeLeader(map[string][]byte{
			"name": name,
			"type": typCBucket,
		})
	}
	return err
}
func (s *Service) CreateBucketIfNotExist(name []byte) error {
	err := s.store.CreateBucketIfNotExist(name)
	if err == errNotLeader {
		return s.writeLeader(map[string][]byte{
			"name": name,
			"type": typCBucketNotExist,
		})
	}
	return err
}
func (s *Service) RemoveBucket(name []byte) error {
	err := s.store.RemoveBucket(name)
	if err == errNotLeader {
		return s.writeLeader(map[string][]byte{
			"name": name,
			"type": typRBucket,
		})
	}
	return err
}
func (s *Service) View(bucket, key []byte) ([]byte, error) {
	return s.store.View(bucket, key)
}
func (s *Service) ViewPrefix(bucket, keyPrefix []byte) (map[string][]byte, error) {
	return s.store.ViewPrefix(bucket, keyPrefix)
}
func (s *Service) RemoveKey(bucket, key []byte) error {
	err := s.store.RemoveKey(bucket, key)
	if err == errNotLeader {
		return s.writeLeader(map[string][]byte{
			"key":    key,
			"bucket": bucket,
			"type":   typRkey,
		})
	}
	return err
}
func (s *Service) Update(bucket []byte, key []byte, value []byte) error {
	err := s.store.Update(bucket, key, value)
	if err == errNotLeader {
		return s.writeLeader(map[string][]byte{
			"key":    key,
			"value":  value,
			"bucket": bucket,
			"type":   typUpdate,
		})
	}
	return err
}
func (s *Service) Batch(rows []model.Row) error {
	err := s.store.Batch(rows)
	if err == errNotLeader {
		buf := &bytes.Buffer{}
		e := json.NewEncoder(buf)
		if err := e.Encode(rows); err != nil {
			return err
		}
		return s.writeLeader(map[string][]byte{
			"rows": buf.Bytes(),
			"type": typBatch,
		})
	}
	return err
}
func (s *Service) GetSession(key interface{}) interface{} {
	return s.store.GetSession(key)
}
func (s *Service) SetSession(key, value interface{}) error {
	err := s.store.SetSession(key, value)
	if err == errNotLeader {
		var keyStr, valueStr string
		var ok bool
		if keyStr, ok = key.(string); !ok {
			return fmt.Errorf("session key type error, not a string")
		}
		if valueStr, ok = value.(string); !ok {
			return fmt.Errorf("session value type error, not a string")
		}
		return s.writeLeader(map[string][]byte{
			"key":   []byte(keyStr),
			"value": []byte(valueStr),
			"type":  typSetSession,
		})
	}
	return err
}