ioredis: Create keys with expires

Hi,

Is it poissible to send this Redis command with ioredis in just one function call?

set key 100 ex 10

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 21 (2 by maintainers)

Most upvoted comments

Yep! redis.set('key', 100, 'ex', 10)

@arankhem no, you’ll have to do it with 2 commands:

  • hmset(key, data)
  • expire(key, ttl)

Thanks @luin! Would it make sense to add this example to README? If you like I can create a PR 😃

TL;DR Method signatures should be documented.

Disclaimer: Maybe I didn’t see the part of documentation that talks about this when I “scanned” it. I didn’t read the entire page. I mainly used mouse scroll and Ctrl + F (searched for “set”, “ex”, “command”, “commands”).

@luin @dirkbonhomme I would like to see explicit documentation on the existence of the set method on Redis prototype. Also I would like to see explicit documentation on the arguments each command can take even if that means just writing something like ioredis.set(String arg0,String arg1,String arg2...) where arg<x> is the positional argument documented in the Redis API documentation for your version available here: <link>

There is no reference of the set method (or any other Redis command) here: https://github.com/luin/ioredis/blob/master/API.md#new_Redis I knew the set method existed from the README.

It wasn’t obvious to me what arguments the set command can take: I was wondering if it would be like ioredis.set(key, value, px, nx, xx) but then what about ex or ioredis.set(key, value, {px: new Date().getTime()}) but then where do I find the options names in the documentation. Then I searched online and I stumbled upon this issue where @luin gave an example. It would be nice to have that example visible somewhere in the documentation.

This would also reduce probability of issues like #159.

@luin Please add this to the API documentation.

+1 on document for the instance methods signature

@luin , Just wanted to know is there a way to expire hash similar to set. For example

let sample = { ‘field1’: 1, ‘field2’: 2, ‘field3’: 3, } redis.hmset(‘test’, sample, ‘EX’, 1000)

@luin , Just wanted to know is there a way to expire hash similar to set. For example

let sample = { ‘field1’: 1, ‘field2’: 2, ‘field3’: 3, } redis.hmset(‘test’, sample, ‘EX’, 1000)

This does not work at 2020 Feb

@aalexgabi I agree with you that the api documentation should be more informative. As noted in README, all arguments are passed directly to the redis server, so that ioredis supports every command / option that your redis server supports. Given people may run different versions of redis servers, the commands / options may differ, so it’s a little hard to document them clearly.

However, I think some examples do help, and it’s also better to note how to pass options like EX so that people won’t confused.

You can also use this dedicated command http://redis.io/commands/SETEX 😉