Implement list and fix test

This commit is contained in:
bel
2019-06-21 17:57:00 -06:00
parent ade973d19d
commit 52479ed8a0
12 changed files with 161 additions and 29 deletions

View File

@@ -33,7 +33,35 @@ func (m *Redis) Close() error {
}
func (m *Redis) List(ns []string, limits ...string) ([]string, error) {
return nil, errors.New("not impl")
limits = resolveLimits(limits)
limits[0] = resolveNamespace(append(ns, limits[0]))
limits[1] = resolveNamespace(append(ns, limits[1]))
resp, err := m.client.Do("KEYS", "*")
if err != nil {
return nil, err
}
keys := []string{}
if results, ok := resp.([]interface{}); !ok {
return nil, ErrNotFound
} else {
for i := range results {
_, ok := results[i].([]uint8)
if !ok {
return nil, errors.New("not a []byte key")
}
k := fmt.Sprintf("%s", results[i])
if k < limits[0] {
continue
}
if k > limits[1] {
break
}
keys = append(keys, k)
}
}
return keys, nil
}
func (m *Redis) Get(key string, ns ...string) ([]byte, error) {