本文整理了Java中redis.clients.jedis.Jedis.msetnx()
方法的一些代码示例,展示了Jedis.msetnx()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jedis.msetnx()
方法的具体详情如下:
包路径:redis.clients.jedis.Jedis
类名称:Jedis
方法名:msetnx
[英]Set the the respective keys to the respective values. #mset(String...) will replace old values with new values, while MSETNX 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 Long execute(Jedis connection) {
return connection.msetnx(keysvalues);
}
}.runBinary(keys.length, keys);
代码示例来源:origin: sohutv/cachecloud
@Override
public Long execute(Jedis connection) {
return connection.msetnx(keysvalues);
}
}.run(keys.length, keys);
代码示例来源:origin: spring-projects/spring-data-redis
@Override
public Boolean mSetNX(Map<byte[], byte[]> tuples) {
Assert.notNull(tuples, "Tuples must not be null!");
try {
if (isPipelined()) {
pipeline(
connection.newJedisResult(connection.getRequiredPipeline().msetnx(JedisConverters.toByteArrays(tuples)),
JedisConverters.longToBoolean()));
return null;
}
if (isQueueing()) {
transaction(
connection.newJedisResult(connection.getRequiredTransaction().msetnx(JedisConverters.toByteArrays(tuples)),
JedisConverters.longToBoolean()));
return null;
}
return JedisConverters.toBoolean(connection.getJedis().msetnx(JedisConverters.toByteArrays(tuples)));
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}
代码示例来源:origin: io.leopard/leopard-redis
@Override
public Long msetnx(String... keysvalues) {
return jedis.msetnx(keysvalues);
}
代码示例来源:origin: mindwind/craft-atom
private Long msetnx0(Jedis j, String... keysvalues) {
return j.msetnx(keysvalues);
}
代码示例来源:origin: apache/servicemix-bundles
@Override
public Long execute(Jedis connection) {
return connection.msetnx(keysvalues);
}
}.runBinary(keys.length, keys);
代码示例来源:origin: apache/servicemix-bundles
@Override
public Long execute(Jedis connection) {
return connection.msetnx(keysvalues);
}
}.run(keys.length, keys);
代码示例来源:origin: io.leopard/leopard-redis
@Override
public Long msetnx(String... keysvalues) {
return jedis.msetnx(keysvalues);
}
代码示例来源:origin: penggle/jedis-ms-sentinel
public Long msetnx(String... keysvalues) {
return master.msetnx(keysvalues);
}
代码示例来源:origin: penggle/jedis-ms-sentinel
public Long msetnx(byte[]... keysvalues) {
return master.msetnx(keysvalues);
}
代码示例来源:origin: io.enoa/nosql-redis
default Long msetnx(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.msetnx(keysvalues);
});
}
代码示例来源:origin: wxiaoqi/ace-cache
@Override
public Long msetnx(String... keysvalues) {
Jedis jedis = null;
Long res = 0L;
try {
jedis = pool.getResource();
res = jedis.msetnx(keysvalues);
} catch (Exception e) {
LOGGER.error(e.getMessage());
} finally {
returnResource(pool, jedis);
}
return res;
}
代码示例来源:origin: chenjunwen/SpringBootFrame
/**
* <p>批量的设置key:value,可以一个,如果key已经存在则会失败,操作会回滚</p>
* <p>example:</p>
* <p> obj.msetnx(new String[]{"key2","value1","key2","value2"})</p>
*
* @param keysvalues
* @return 成功返回1 失败返回0
*/
public Long msetnx(String... keysvalues) {
Jedis jedis = null;
Long res = 0L;
try {
jedis = pool.getResource();
res = jedis.msetnx(keysvalues);
} catch (Exception e) {
LOGGER.error(e.getMessage());
} finally {
returnResource(pool, jedis);
}
return res;
}
代码示例来源:origin: com.netflix.spinnaker.kork/kork-jedis
@Override
public Long msetnx(String... keysvalues) {
String command = "msetnx";
return instrumented(command, payloadSize(keysvalues), () -> delegated.msetnx(keysvalues));
}
代码示例来源:origin: com.netflix.spinnaker.kork/kork-jedis
@Override
public Long msetnx(byte[]... keysvalues) {
String command = "msetnx";
return instrumented(command, payloadSize(keysvalues), () -> delegated.msetnx(keysvalues));
}
代码示例来源:origin: org.nutz/nutz-integration-jedis
/**
* Set the the respective keys to the respective values. {@link #mset(String...) MSET} will
* replace old values with new values, while MSETNX will not perform any operation at all even if
* just a single key already exists.
* <p>
* 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.
* <p>
* 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.
*
* @param keysvalues
* @return Integer reply, specifically: 1 if the all the keys were set 0 if no key was set (at
* least one key already existed)
* @see #mset(String...)
*/
public Long msetnx(String... keysvalues) {
Jedis jedis = getJedis();
try {
return jedis.msetnx(keysvalues);
} finally {Streams.safeClose(jedis);}
}
代码示例来源:origin: youtongluan/sumk
@Override
public java.lang.Long msetnx(java.lang.String... keysvalues) {
Exception e1 = null;
for (int i = 0; i < tryCount; i++) {
Jedis jedis = null;
try {
jedis = pool.getResource();
return jedis.msetnx(keysvalues);
} catch (Exception e) {
if (isConnectException(e)) {
Log.get(LOG_NAME).error(this.hosts + " - redis connection failed,idle=" + pool.getNumIdle()
+ ",active=" + pool.getNumActive(), e);
e1 = e;
continue;
}
Log.get(LOG_NAME).error("msetnx - redis execute error!" + e.getMessage(), e);
SumkException.throwException(12342411, e.getMessage(), e);
} finally {
close(jedis);
}
}
handleRedisException(e1);
throw new SumkException(12342423, "未知redis异常");
}
代码示例来源:origin: youtongluan/sumk
@Override
public java.lang.Long msetnx(byte[]... keysvalues) {
Exception e1 = null;
for (int i = 0; i < tryCount; i++) {
Jedis jedis = null;
try {
jedis = pool.getResource();
return jedis.msetnx(keysvalues);
} catch (Exception e) {
if (isConnectException(e)) {
Log.get(LOG_NAME).error(this.hosts + " - redis connection failed,idle=" + pool.getNumIdle()
+ ",active=" + pool.getNumActive(), e);
e1 = e;
continue;
}
Log.get(LOG_NAME).error("msetnx - redis execute error!" + e.getMessage(), e);
SumkException.throwException(12342411, e.getMessage(), e);
} finally {
close(jedis);
}
}
handleRedisException(e1);
throw new SumkException(12342423, "未知redis异常");
}
代码示例来源:origin: apache/servicemix-bundles
@Override
public Boolean mSetNX(Map<byte[], byte[]> tuples) {
Assert.notNull(tuples, "Tuples must not be null!");
try {
if (isPipelined()) {
pipeline(
connection.newJedisResult(connection.getRequiredPipeline().msetnx(JedisConverters.toByteArrays(tuples)),
JedisConverters.longToBoolean()));
return null;
}
if (isQueueing()) {
transaction(
connection.newJedisResult(connection.getRequiredTransaction().msetnx(JedisConverters.toByteArrays(tuples)),
JedisConverters.longToBoolean()));
return null;
}
return JedisConverters.toBoolean(connection.getJedis().msetnx(JedisConverters.toByteArrays(tuples)));
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}
代码示例来源:origin: org.springframework.data/spring-data-redis
@Override
public Boolean mSetNX(Map<byte[], byte[]> tuples) {
Assert.notNull(tuples, "Tuples must not be null!");
try {
if (isPipelined()) {
pipeline(
connection.newJedisResult(connection.getRequiredPipeline().msetnx(JedisConverters.toByteArrays(tuples)),
JedisConverters.longToBoolean()));
return null;
}
if (isQueueing()) {
transaction(
connection.newJedisResult(connection.getRequiredTransaction().msetnx(JedisConverters.toByteArrays(tuples)),
JedisConverters.longToBoolean()));
return null;
}
return JedisConverters.toBoolean(connection.getJedis().msetnx(JedisConverters.toByteArrays(tuples)));
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}
内容来源于网络,如有侵权,请联系作者删除!