Implement list and fix test
This commit is contained in:
30
redis.go
30
redis.go
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user