Skip to content

Commit

Permalink
redka: export TypeID (fix #40)
Browse files Browse the repository at this point in the history
  • Loading branch information
nalgeon committed Nov 11, 2024
1 parent 3049a9f commit 9a4edc6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
13 changes: 13 additions & 0 deletions redka.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion redka_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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() {
Expand Down

0 comments on commit 9a4edc6

Please sign in to comment.