Skip to content

error-redis.Scan(unsupported time.Time) #2380

@leoantony72

Description

@leoantony72

Error :

cannot scan redis.result 2023-01-31T17:08:37.0314813+05:30 into struct field User.Date_created of type time.Time, error-redis.Scan(unsupported time.Time)</b>

Version : github.com/redis/go-redis/v9 v9.0.0-rc.4

type User struct {
	Id           string    `json:"id" gorm:"primaryKey;type:text" redis:"id"`
	Username     string    `json:"username" gorm:"type:varchar(25);uniqueIndex;not null" redis:"username"`
	Email        string    `json:"email" gorm:"type:varchar(40);uniqueIndex;not null" redis:"email"`
	Password     string    `json:"password,omitempty" gorm:"type:varchar(50);not null" redis:"-"`
	Date_created time.Time `json:"data_created" gorm:"type:timestamp" redis:"date_created"`
}
func (u *UserPostgresRepo) Create(user model.User) error {
	result := u.db.Create(&user)
	if result.Error != nil {
		return result.Error
	}

	redis_key := "users:" + user.Username + ":metadata"
	err := u.redis.HSet(
		ctx, redis_key,
		"id", user.Id,
		"username", user.Username,
		"email", user.Email,
		"date_created", time.Now(),
	)
	if err.Err() != nil {
		return err.Err()
	}
	return nil
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions