redis.clients.jedis.Jedis.zunionstore()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(133)

本文整理了Java中redis.clients.jedis.Jedis.zunionstore()方法的一些代码示例,展示了Jedis.zunionstore()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jedis.zunionstore()方法的具体详情如下:
包路径:redis.clients.jedis.Jedis
类名称:Jedis
方法名:zunionstore

Jedis.zunionstore介绍

[英]Creates a union or intersection of N sorted sets given by keys k1 through kN, and stores it at dstkey. It is mandatory to provide the number of input keys N, before passing the input keys and the other (optional) arguments.

As the terms imply, the #zinterstore(String,String...) command requires an element to be present in each of the given inputs to be inserted in the result. The #zunionstore(String,String...) command inserts all elements across all inputs.

Using the WEIGHTS option, it is possible to add weight to each input sorted set. This means that the score of each element in the sorted set is first multiplied by this weight before being passed to the aggregation. When this option is not given, all weights default to 1.

With the AGGREGATE option, it's possible to specify how the results of the union or intersection are aggregated. This option defaults to SUM, where the score of an element is summed across the inputs where it exists. When this option is set to be either MIN or MAX, the resulting set will contain the minimum or maximum score of an element across the inputs where it exists.

Time complexity: O(N) + O(M log(M)) with N being the sum of the sizes of the input sorted sets, and M being the number of elements in the resulting sorted set
[中]创建由键k1到kN给定的N个排序集的并集或交集,并将其存储在dstkey。在传递输入键和其他(可选)参数之前,必须提供输入键的数量N。
正如术语所暗示的那样,#zinterstore(字符串,字符串…)命令要求每个给定输入中都有一个元素,以便插入到结果中。#zunionstore(字符串,字符串…)命令在所有输入中插入所有元素。
使用“权重”选项,可以向每个输入排序集添加权重。这意味着排序集中每个元素的分数在传递给聚合之前首先乘以该权重。未指定此选项时,所有权重默认为1。
使用聚合选项,可以指定如何聚合并集或交集的结果。此选项默认为SUM,其中元素的分数在其存在的输入中求和。当此选项设置为“最小”或“最大”时,结果集将包含元素在其存在的输入中的最小或最大分数。
时间复杂度:O(N)+O(M log(M)),N是输入排序集的大小之和,M是结果排序集中的元素数

代码示例

代码示例来源:origin: sohutv/cachecloud

@Override
 public Long execute(Jedis connection) {
  return connection.zunionstore(dstkey, params, sets);
 }
}.run(mergedKeys.length, mergedKeys);

代码示例来源:origin: sohutv/cachecloud

@Override
 public Long execute(Jedis connection) {
  return connection.zunionstore(dstkey, sets);
 }
}.runBinary(wholeKeys.length, wholeKeys);

代码示例来源:origin: sohutv/cachecloud

@Override
 public Long execute(Jedis connection) {
  return connection.zunionstore(dstkey, params, sets);
 }
}.runBinary(wholeKeys.length, wholeKeys);

代码示例来源:origin: sohutv/cachecloud

@Override
 public Long execute(Jedis connection) {
  return connection.zunionstore(dstkey, sets);
 }
}.run(mergedKeys.length, mergedKeys);

代码示例来源:origin: spring-projects/spring-data-redis

@Override
public Long zUnionStore(byte[] destKey, Aggregate aggregate, Weights weights, byte[]... sets) {
  Assert.notNull(destKey, "Destination key must not be null!");
  Assert.notNull(sets, "Source sets must not be null!");
  Assert.notNull(weights, "Weights must not be null!");
  Assert.noNullElements(sets, "Source sets must not contain null elements!");
  Assert.isTrue(weights.size() == sets.length, () -> String
      .format("The number of weights (%d) must match the number of source sets (%d)!", weights.size(), sets.length));
  try {
    ZParams zparams = new ZParams().weights(weights.toArray()).aggregate(ZParams.Aggregate.valueOf(aggregate.name()));
    if (isPipelined()) {
      pipeline(connection.newJedisResult(connection.getRequiredPipeline().zunionstore(destKey, zparams, sets)));
      return null;
    }
    if (isQueueing()) {
      transaction(connection.newJedisResult(connection.getRequiredTransaction().zunionstore(destKey, zparams, sets)));
      return null;
    }
    return connection.getJedis().zunionstore(destKey, zparams, sets);
  } catch (Exception ex) {
    throw convertJedisAccessException(ex);
  }
}

代码示例来源:origin: spring-projects/spring-data-redis

@Override
public Long zUnionStore(byte[] destKey, byte[]... sets) {
  Assert.notNull(destKey, "Destination key must not be null!");
  Assert.notNull(sets, "Source sets must not be null!");
  Assert.noNullElements(sets, "Source sets must not contain null elements!");
  try {
    if (isPipelined()) {
      pipeline(connection.newJedisResult(connection.getRequiredPipeline().zunionstore(destKey, sets)));
      return null;
    }
    if (isQueueing()) {
      transaction(connection.newJedisResult(connection.getRequiredTransaction().zunionstore(destKey, sets)));
      return null;
    }
    return connection.getJedis().zunionstore(destKey, sets);
  } catch (Exception ex) {
    throw convertJedisAccessException(ex);
  }
}

代码示例来源:origin: io.leopard/leopard-redis

@Override
  public Object execute(Jedis jedis) {
    return jedis.zunionstore(dstkey, sets);
  }
});

代码示例来源:origin: io.leopard/leopard-redis

@Override
  public Object execute(Jedis jedis) {
    return jedis.zunionstore(dstkey, params, sets);
  }
});

代码示例来源:origin: apache/servicemix-bundles

@Override
 public Long execute(Jedis connection) {
  return connection.zunionstore(dstkey, params, sets);
 }
}.run(mergedKeys.length, mergedKeys);

代码示例来源:origin: apache/servicemix-bundles

@Override
 public Long execute(Jedis connection) {
  return connection.zunionstore(dstkey, sets);
 }
}.runBinary(wholeKeys.length, wholeKeys);

代码示例来源:origin: apache/servicemix-bundles

@Override
 public Long execute(Jedis connection) {
  return connection.zunionstore(dstkey, params, sets);
 }
}.runBinary(wholeKeys.length, wholeKeys);

代码示例来源:origin: io.leopard/leopard-redis

@Override
public Long zunionstore(String dstkey, String... sets) {
  return jedis.zunionstore(dstkey, sets);
}

代码示例来源:origin: Impetus/Kundera

((Jedis) connection).zunionstore(destStore, keySets.toArray(new String[] {}));

代码示例来源:origin: com.netflix.spinnaker.kork/kork-jedis

@Override
public Long zunionstore(String dstkey, String... sets) {
 String command = "zunionstore";
 return instrumented(command, () -> delegated.zunionstore(dstkey, sets));
}

代码示例来源:origin: com.netflix.spinnaker.kork/kork-jedis

@Override
public Long zunionstore(String dstkey, ZParams params, String... sets) {
 String command = "zunionstore";
 return instrumented(command, () -> delegated.zunionstore(dstkey, params, sets));
}

代码示例来源:origin: com.netflix.spinnaker.kork/kork-jedis

@Override
public Long zunionstore(byte[] dstkey, byte[]... sets) {
 String command = "zunionstore";
 return instrumented(command, () -> delegated.zunionstore(dstkey, sets));
}

代码示例来源:origin: com.netflix.spinnaker.kork/kork-jedis

@Override
public Long zunionstore(byte[] dstkey, ZParams params, byte[]... sets) {
 String command = "zunionstore";
 return instrumented(command, () -> delegated.zunionstore(dstkey, params, sets));
}

代码示例来源:origin: mindwind/craft-atom

@SuppressWarnings("deprecation")
private Long zunionstore_weights(Jedis j, String destination, Map<String, Integer> weightkeys) {
  Object[] objs = convert4zstore(weightkeys);
  String[] keys = (String[]) objs[0];
  int [] weights = (int[]) objs[1];
  return j.zunionstore(destination, new ZParams().weights(weights), keys);
}

代码示例来源:origin: mindwind/craft-atom

@SuppressWarnings("deprecation")
private Long zunionstore_weights_max(Jedis j, String destination, Map<String, Integer> weightkeys) {
  Object[] objs = convert4zstore(weightkeys);
  String[] keys = (String[]) objs[0];
  int [] weights = (int[]) objs[1];
  return j.zunionstore(destination, new ZParams().weights(weights).aggregate(Aggregate.MAX), keys);
}

代码示例来源:origin: mindwind/craft-atom

@SuppressWarnings("deprecation")
private Long zunionstore_weights_min(Jedis j, String destination, Map<String, Integer> weightkeys) {
  Object[] objs = convert4zstore(weightkeys);
  String[] keys = (String[]) objs[0];
  int [] weights = (int[]) objs[1];
  return j.zunionstore(destination, new ZParams().weights(weights).aggregate(Aggregate.MIN), keys);
}

相关文章

微信公众号

最新文章

更多

Jedis类方法