Use concrete Item rather than an interface. Removes unnecessary dupe structs

This commit is contained in:
Asim
2015-05-23 21:25:55 +01:00
parent 74fd1fc989
commit b5dcbbe998
7 changed files with 34 additions and 121 deletions

View File

@@ -11,20 +11,7 @@ type mstore struct {
Client *mc.Client
}
type item struct {
key string
value []byte
}
func (i *item) Key() string {
return i.key
}
func (i *item) Value() []byte {
return i.value
}
func (m *mstore) Get(key string) (store.Item, error) {
func (m *mstore) Get(key string) (*store.Item, error) {
kv, err := m.Client.Get(key)
if err != nil && err == mc.ErrCacheMiss {
return nil, errors.New("key not found")
@@ -36,9 +23,9 @@ func (m *mstore) Get(key string) (store.Item, error) {
return nil, errors.New("key not found")
}
return &item{
key: kv.Key,
value: kv.Value,
return &store.Item{
Key: kv.Key,
Value: kv.Value,
}, nil
}
@@ -46,20 +33,13 @@ func (m *mstore) Del(key string) error {
return m.Client.Delete(key)
}
func (m *mstore) Put(item store.Item) error {
func (m *mstore) Put(item *store.Item) error {
return m.Client.Set(&mc.Item{
Key: item.Key(),
Value: item.Value(),
Key: item.Key,
Value: item.Value,
})
}
func (m *mstore) NewItem(key string, value []byte) store.Item {
return &item{
key: key,
value: value,
}
}
func NewStore(addrs []string, opts ...store.Option) store.Store {
if len(addrs) == 0 {
addrs = []string{"127.0.0.1:11211"}