-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
hmset in typescript object #1536
Comments
There's an example in README: https://github.com/luin/ioredis/blob/main/examples/hash.js#L13. Prior v5.x.x, you also need to install @types/ioredis since v5.0.0 is the first version ioredis provides native TypeScript declarations. |
Thanks a lot. I have seen this example . Perhaps I am not good with typescript, hence I am not able convert same example to typescript object type defination and call the API. Could you please give an example which is written with typescript ? |
I tried like this Redis.hmset("user-hash", newUser) but typescript has an error...What could be the right way to put newUser object ? |
const redis = new Redis();
redis.hmset("hash", {
name: "Bob",
age: "20",
}); It works for me. |
Closing as this should be resolved in v5.0.0. Feel free to reopen if the issue still exists. |
dear luin, let newUser : User = { |
Thanks for the follow-up. It's actually a limit on TypeScript side that you can't assign an interface to a record: interface User {
name: string;
age: string;
}
let newUser: User = {
name: "suman",
age: "34",
};
const record: Record<string, string> = newUser; // Error here ioredis expects a |
🎉 This issue has been resolved in version 5.0.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Dear luin, Thanks |
## [5.0.2](redis/ioredis@v5.0.1...v5.0.2) (2022-03-30) ### Bug Fixes * allow option maxRetriesPerRequest to be null ([#1553](redis/ioredis#1553)) ([d62a808](redis/ioredis@d62a808)), closes [#1550](redis/ioredis#1550) * support TypeScript interface as parameters of hmset and mset ([#1545](redis/ioredis#1545)) ([3444791](redis/ioredis@3444791)), closes [#1536](redis/ioredis#1536)
I tried to insert one simple object in typescript to ioredis hashmap. I define object like this
interface User {
name : string,
age :string
}
let newUser : User = {
name : "suman",
age :"34"
}
How do I write hmset command ?
The text was updated successfully, but these errors were encountered: