redka: export TypeID (fix #40)

This commit is contained in:
Anton
2024-11-12 01:26:57 +05:00
parent 3049a9ff5d
commit 9a4edc6ab8
2 changed files with 23 additions and 1 deletions

View File

@@ -25,6 +25,19 @@ import (
"github.com/nalgeon/redka/internal/sqlx"
)
// A TypeID identifies the type of the key and thus
// the data structure of the value with that key.
type TypeID = core.TypeID
const (
TypeAny = core.TypeAny
TypeString = core.TypeString
TypeList = core.TypeList
TypeSet = core.TypeSet
TypeHash = core.TypeHash
TypeZSet = core.TypeZSet
)
// Common errors returned by data structure methods.
var (
ErrKeyType = core.ErrKeyType // key type mismatch

View File

@@ -26,7 +26,7 @@ func ExampleOpenRead() {
if err != nil {
panic(err)
}
db.Str().Set("name", "alice")
_ = db.Str().Set("name", "alice")
db.Close()
// open a read-only database
@@ -89,6 +89,7 @@ func ExampleDB_Key() {
defer db.Close()
_ = db.Str().SetExpires("name", "alice", 60*time.Second)
_ = db.Str().Set("city", "paris")
key, _ := db.Key().Get("name")
fmt.Printf("key=%v, type=%v, version=%v, exists=%v\n",
@@ -98,9 +99,17 @@ func ExampleDB_Key() {
fmt.Printf("key=%v, type=%v, version=%v, exists=%v\n",
key.Key, key.TypeName(), key.Version, key.Exists())
scan, _ := db.Key().Scan(0, "*", redka.TypeString, 100)
fmt.Print("keys:")
for _, key := range scan.Keys {
fmt.Print(" ", key.Key)
}
fmt.Println()
// Output:
// key=name, type=string, version=1, exists=true
// key=, type=unknown, version=0, exists=false
// keys: name city
}
func ExampleDB_Str() {