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

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

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

Jedis.mset介绍

[英]Set the the respective keys to the respective values. MSET will replace old values with new values, while #msetnx(String...) will not perform any operation at all even if just a single key already exists.

Because of this semantic MSETNX can be used in order to set different keys representing different fields of an unique logic object in a way that ensures that either all the fields or none at all are set.

Both MSET and MSETNX are atomic operations. This means that for instance if the keys A and B are modified, another client talking to Redis can either see the changes to both A and B at once, or no modification at all.
[中]将相应的键设置为相应的值。MSET将用新值替换旧值,而#msetnx(字符串…)即使只有一个密钥已经存在,也不会执行任何操作。
由于这种语义,可以使用MSETNX来设置表示唯一逻辑对象的不同字段的不同键,以确保设置所有字段或根本不设置任何字段。
MSET和MSETNX都是原子操作。这意味着,例如,如果密钥A和B被修改,与Redis对话的另一个客户端可以立即看到A和B的更改,或者根本不进行任何修改。

代码示例

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

@Override
 public String execute(Jedis connection) {
  return connection.mset(keysvalues);
 }
}.run(keys.length, keys);

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

@Override
 public String execute(Jedis connection) {
  return connection.mset(keysvalues);
 }
}.runBinary(keys.length, keys);

代码示例来源:origin: jfinal/jfinal

/**
 * 同时设置一个或多个 key-value 对。
 * 如果某个给定 key 已经存在,那么 MSET 会用新值覆盖原来的旧值,如果这不是你所希望的效果,请考虑使用 MSETNX 命令:它只会在所有给定 key 都不存在的情况下进行设置操作。
 * MSET 是一个原子性(atomic)操作,所有给定 key 都会在同一时间内被设置,某些给定 key 被更新而另一些给定 key 没有改变的情况,不可能发生。
 * <pre>
 * 例子:
 * Cache cache = RedisKit.use();            // 使用 Redis 的 cache
 * cache.mset("k1", "v1", "k2", "v2");        // 放入多个 key value 键值对
 * List list = cache.mget("k1", "k2");        // 利用多个键值得到上面代码放入的值
 * </pre>
 */
public String mset(Object... keysValues) {
  if (keysValues.length % 2 != 0)
    throw new IllegalArgumentException("wrong number of arguments for met, keysValues length can not be odd");
  Jedis jedis = getJedis();
  try {
    byte[][] kv = new byte[keysValues.length][];
    for (int i=0; i<keysValues.length; i++) {
      if (i % 2 == 0)
        kv[i] = keyToBytes(keysValues[i]);
      else
        kv[i] = valueToBytes(keysValues[i]);
    }
    return jedis.mset(kv);
  }
  finally {close(jedis);}
}

代码示例来源:origin: apache/storm

case STRING:
  String[] keyValue = buildKeyValuesList(keyValues);
  jedis.mset(keyValue);
  if (this.options.expireIntervalSec > 0) {
    Pipeline pipe = jedis.pipelined();

代码示例来源:origin: apache/ignite

/**
 * @throws Exception If failed.
 */
@Test
public void testMSet() throws Exception {
  try (Jedis jedis = pool.getResource()) {
    jedis.mset("setKey1", "1", "setKey2", "2");
    Assert.assertEquals("1", jcache().get("setKey1"));
    Assert.assertEquals("2", jcache().get("setKey2"));
  }
}

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

@Override
public Boolean mSet(Map<byte[], byte[]> tuples) {
  Assert.notNull(tuples, "Tuples must not be null!");
  try {
    if (isPipelined()) {
      pipeline(connection.newJedisResult(connection.getRequiredPipeline().mset(JedisConverters.toByteArrays(tuples)),
          Converters.stringToBooleanConverter()));
      return null;
    }
    if (isQueueing()) {
      transaction(
          connection.newJedisResult(connection.getRequiredTransaction().mset(JedisConverters.toByteArrays(tuples)),
              Converters.stringToBooleanConverter()));
      return null;
    }
    return Converters.stringToBoolean(connection.getJedis().mset(JedisConverters.toByteArrays(tuples)));
  } catch (Exception ex) {
    throw convertJedisAccessException(ex);
  }
}

代码示例来源:origin: yrain/smart-cache

@Override
  String doInJedis(Jedis jedis) {
    return jedis.mset(keyvalues);
  }
});

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

@Override
 public String execute(Jedis connection) {
  return connection.mset(keysvalues);
 }
}.runBinary(keys.length, keys);

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

@Override
 public String execute(Jedis connection) {
  return connection.mset(keysvalues);
 }
}.run(keys.length, keys);

代码示例来源:origin: yrain/smart-cache

@Override
  String doInJedis(Jedis jedis) {
    return jedis.mset(keyvalues);
  }
});

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

private String mset0(Jedis j, String... keysvalues) {
  return j.mset(keysvalues);
}

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

@Override
public String mset(String... keysvalues) {
  return jedis.mset(keysvalues);
}

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

@Override
public String mset(String... keysvalues) {
  return jedis.mset(keysvalues);
}

代码示例来源:origin: penggle/jedis-ms-sentinel

public String mset(byte[]... keysvalues) {
  return master.mset(keysvalues);
}

代码示例来源:origin: com.github.sogyf/goja-mvt

@Override
  public Boolean action(Jedis jedis) {
    Iterator<Entry<String, String>> iter = values.entrySet().iterator();
    int index = 0;
    String[] encodeValues = new String[values.size() * 2];
    while (iter.hasNext()) {
      Entry<String, String> entry = iter.next();
      encodeValues[index++] = entry.getKey();
      encodeValues[index++] = entry.getValue();
    }
    return "OK".equalsIgnoreCase(jedis.mset(encodeValues));
  }
});

代码示例来源:origin: com.github.sogyf/goja-mvt

@Override
  public Boolean action(Jedis jedis) {
    byte[][] encodeValues = new byte[values.size() * 2][];
    int index = 0;
    for (Entry<String, Serializable> entry : values.entrySet()) {
      encodeValues[index++] = entry.getKey().getBytes();
      encodeValues[index++] = SerializableKit.toByteArray(entry.getValue());
    }
    String retVal = jedis.mset(encodeValues);
    return "OK".equalsIgnoreCase(retVal);
  }
});

代码示例来源:origin: kstyrc/trident-redis

private void mset(String... keyValues) {
   Jedis jedis = pool.getResource();
   try {
     jedis.mset(keyValues);
   } finally {
     pool.returnResource(jedis);
   }
  }
}

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

default String mset(String... keysvalues) {
  if (keysvalues.length % 2 != 0)
   throw new IllegalArgumentException("wrong number of arguments for met, keysValues length can not be odd");
  return this.run((jedis, serializer) -> {
//      byte[][] kvs = new byte[keysvalues.length][];
//      for (int i = 0; i < keysvalues.length; i++) {
//        if (i % 2 == 0)
//          kvs[i] = SafeEncoder.encode(keysvalues[i]);
//        else
//          kvs[i] = SafeEncoder.encode(keysvalues[i]);
//      }
   return jedis.mset(keysvalues);
  });
 }

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

@Override
public String mset(byte[]... keysvalues) {
 String command = "mset";
 return instrumented(command, payloadSize(keysvalues), () -> delegated.mset(keysvalues));
}

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

@Override
public String mset(String... keysvalues) {
 String command = "mset";
 return instrumented(command, payloadSize(keysvalues), () -> delegated.mset(keysvalues));
}

相关文章

Jedis类方法