2014-05-16 06:36:18 +04:00
|
|
|
package ledis
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2014-05-20 04:41:24 +04:00
|
|
|
func TestHashCodec(t *testing.T) {
|
|
|
|
db := getTestDB()
|
|
|
|
|
|
|
|
key := []byte("key")
|
|
|
|
field := []byte("field")
|
|
|
|
|
|
|
|
ek := db.hEncodeSizeKey(key)
|
|
|
|
if k, err := db.hDecodeSizeKey(ek); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
} else if string(k) != "key" {
|
|
|
|
t.Fatal(string(k))
|
|
|
|
}
|
|
|
|
|
|
|
|
ek = db.hEncodeHashKey(key, field)
|
|
|
|
if k, f, err := db.hDecodeHashKey(ek); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
} else if string(k) != "key" {
|
|
|
|
t.Fatal(string(k))
|
|
|
|
} else if string(f) != "field" {
|
|
|
|
t.Fatal(string(f))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-16 06:36:18 +04:00
|
|
|
func TestDBHash(t *testing.T) {
|
|
|
|
db := getTestDB()
|
|
|
|
|
|
|
|
key := []byte("testdb_hash_a")
|
|
|
|
|
|
|
|
if n, err := db.HSet(key, []byte("a"), []byte("hello world")); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 1 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
}
|