-
-
Notifications
You must be signed in to change notification settings - Fork 247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redis Hset Struct #270
Labels
Bug
Report a reproducible bug or regression
Comments
you can implement encoding.BinaryMarshaler on Template struct to fix this error |
If possible, please submit a repair PR |
it runs ok : package main
import (
"context"
"encoding/json"
"fmt"
"github.com/dromara/carbon/v2"
"github.com/redis/go-redis/v9"
"time"
)
type Template struct {
BirthDate carbon.Carbon `redis:"birth_date" carbon:"type:date"` // 出生日期
}
func (t Template) MarshalBinary() ([]byte, error) {
return json.Marshal(t)
}
func main() {
redisCli := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
})
ctx := context.TODO()
key := "testKey"
val, err := redisCli.Set(ctx, key, Template{
carbon.Now(),
}, time.Minute).Result()
if err != nil {
panic(err)
}
fmt.Println(val)
// output: OK
result, err := redisCli.Get(ctx, key).Result()
if err != nil {
return
}
fmt.Println(result)
// output: {"BirthDate":"2024-12-30 14:57:40"}
} |
|
Thank you for your contribution |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
I encountered an issue with the following code:
golang version: 1.23
carbon version: v2.5.2
redis: v9.7.0
github.com/redis/go-redis/v9
Thanks!
The text was updated successfully, but these errors were encountered: