private static void useMSetNX (JRedis jredis) {
Map<String, byte[]> kvMap = new HashMap<String, byte[]>();
kvMap.put("foo", "bar".getBytes());
kvMap.put("cat", "meow".getBytes());
kvMap.put("dog", "woof".getBytes());
kvMap.put("bird", "whale fail".getBytes());
kvMap.put("pi", String.valueOf(3.141592653589793).getBytes());
try {
jredis.flushdb();
jredis.set("bird", "tweet");
boolean stat = jredis.msetnx(kvMap);
if(!stat) {
System.out.format("Couldn't msetnx - one of these already exists: %s\n", kvMap.keySet());
}
for(String key : kvMap.keySet()){
if(jredis.exists(key)){
System.out.format("key '%s' [value: %s] already existed!\n", key, new String(jredis.get(key)));
}
}
}
catch (RedisException e) { e.printStackTrace(); }
}