question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ArgumentTransformer for zadd

See original GitHub issue

Doc for zadd: https://redis.io/commands/zadd

Hello, The zadd command can accept endless score member [score member ...]. May I have a default ArgumentTransformer for zadd? I can create a PR for that.

My code:

function convertFilpObjectToArray (obj) {
  var result = []
  for (var key in obj) {
    result.push(obj[key], key)
  }
  return result
}

Redis.Command.setArgumentTransformer('zadd', args => {
  if (args.length > 1) {
    let last = args.pop()
    if (typeof last === 'object' && last !== null) {
      args.concat(convertFilpObjectToArray(last))
    } else args.push(last)
  }
  return args
})

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
luincommented, May 23, 2017

I’m aware of this fact. It’s just not straightforward compared with the transformer of hmset for the hash key, which itself is an object.

Anyway, I’d like to accept a PR for that, as long as the transformer keeps the same format with hmset that only takes effect when the argument length is 2 and supports both Map and plain object.

1reaction
luincommented, May 23, 2017

It’s a little confused whether score should be the key or the value of an object (at least more confused than mset for a hash key).

Since ioredis flattens arguments, the following form is supported:

redis.zadd('key', [17, 'a'], [18, 'b'], [19, 'c'])

Given that I don’t think the transformer is necessary.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ZADD
Adds all the specified members with the specified scores to the sorted set stored at key . It is possible to specify multiple...
Read more >
Performance-focused & full-featured Redis client for Node.js
A robust, performance-focused and full-featured Redis client for Node.js. Supports Redis >= 2.6.12 and (Node.js >= 6). Completely compatible with Redis 6.x.
Read more >
RedisAPI (Vert.x Stack - Docs 4.2.7 API) - Eclipse Vert.x
RedisAPI · zadd(List<String> args, Handler<AsyncResult<Response>> handler). Redis command zadd. RedisAPI · zcard(String arg0). Redis command zcard.
Read more >
Command (Vertx Javadocs 4.0.3.GA API)
static Command · ZADD. static Command · ZCARD. static Command · ZCOUNT. static Command · ZINCRBY. static Command · ZINTERSTORE. static Command ·...
Read more >
github.com-luin-ioredis_-_2022-06-25_07-27-55
There are two typesof transformers, argument transformer and reply transformer: ```javascriptconst Redis = require("ioredis");.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found