1

Sorry if my question is stupid, all of us have seen many function arguments for methods documented as this

redis.createClient(port[, host][, options])

I'm unable to understand how it works the port and why host argument is in array and it starts with ,. The snippet above is from

https://github.com/NodeRedis/node_redis

Thanks

1 Answer 1

1

It is not an array. Square brackets are typically used in this manner to indicate optional parameters.

Basically it means that you can use it as any one of the following:

  • redis.createClient(port)
  • redis.createClient(port, host)
  • redis.createClient(port, options)
  • redis.createClient(port, host, options)

Sometimes the notation redis.createClient(port[, host[, options]]) is used instead, which implies it is not possible to use it as redis.createClient(port, options).

Similar notation is also used when documenting commands. (e.g., from ls manual: ls [OPTION]... [FILE]...)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.