-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds HSCAN key/value support to storage.redisIterator (#392)
* Adds HSCAN key/value support to storage.redisIterator The HSCAN result gives us a 1-dimensional array with [n] == key, [n+1] == value so we take advantage of that in the iterator. * the iterator contract expects Next to be called first on redisIterator fixes #394
- Loading branch information
1 parent
0f272ce
commit d13eca2
Showing
2 changed files
with
98 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package redis | ||
|
||
import ( | ||
"runtime/debug" | ||
"testing" | ||
) | ||
|
||
func Test_redisIterator(t *testing.T) { | ||
assertRedisIterator(t, &redisIterator{ | ||
current: 0, | ||
keys: []string{ | ||
"key1", | ||
"val1", | ||
offsetKey, | ||
"123", | ||
"key2", | ||
"val2", | ||
}, | ||
}) | ||
assertRedisIterator(t, &redisIterator{ | ||
current: 0, | ||
keys: []string{ | ||
offsetKey, | ||
"123", | ||
"key1", | ||
"val1", | ||
"key2", | ||
"val2", | ||
}, | ||
}) | ||
assertRedisIterator(t, &redisIterator{ | ||
current: 0, | ||
keys: []string{ | ||
"key1", | ||
"val1", | ||
"key2", | ||
"val2", | ||
offsetKey, | ||
"123", | ||
}, | ||
}) | ||
} | ||
|
||
func assertRedisIterator(t *testing.T, it *redisIterator) { | ||
// the iterator contract implies we must call `Next()` first | ||
it.Next() | ||
assertRedisIteratorKey(t, it, "key1", "val1") | ||
|
||
it.Next() | ||
assertRedisIteratorKey(t, it, "key2", "val2") | ||
|
||
it.Next() | ||
if !it.exhausted() { | ||
t.Fatalf("Expected iterator to be exhausted in %s", string(debug.Stack())) | ||
} | ||
} | ||
|
||
func assertRedisIteratorKey(t *testing.T, it *redisIterator, expectedKey string, expectedValue string) { | ||
if it.exhausted() { | ||
t.Fatalf("Did not expect iterator to be exhausted in %s", string(debug.Stack())) | ||
} | ||
|
||
actualKey := string(it.Key()) | ||
if actualKey != expectedKey { | ||
t.Fatalf("Expected iterator key to be '%s', but was '%s' in %s", expectedKey, actualKey, string(debug.Stack())) | ||
} | ||
|
||
actualValue, _ := it.Value() | ||
if string(actualValue) != expectedValue { | ||
t.Fatalf("Expected iterator value to be '%s', but was '%s' in %s", expectedValue, actualValue, string(debug.Stack())) | ||
} | ||
} |