本文整理匯總了Java中redis.clients.jedis.Transaction.sadd方法的典型用法代碼示例。如果您正苦於以下問題:Java Transaction.sadd方法的具體用法?Java Transaction.sadd怎麽用?Java Transaction.sadd使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類redis.clients.jedis.Transaction
的用法示例。
在下文中一共展示了Transaction.sadd方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testExec
import redis.clients.jedis.Transaction; //導入方法依賴的package包/類
@Test
public void testExec() throws Exception {
int rnd = ThreadLocalRandom.current().nextInt(0, presetElements.size());
String key = presetElementKeys.get(rnd);
String value = String.valueOf(presetElements.get(key));
Transaction transaction = jedis.multi();
Snapshot snapshot = commandTracker.snapshot();
Snapshot discardSnapshot = discardTracker.snapshot();
Snapshot txsnapshot = execTracker.snapshot();
txsnapshot.increment();
Response<Long> added = transaction.sadd(key, value);
transaction.exec();
assertEquals(1, (long) added.get());
txsnapshot.validate();
snapshot.validate();
discardSnapshot.validate();
}
示例2: testDiscard
import redis.clients.jedis.Transaction; //導入方法依賴的package包/類
@Test
public void testDiscard() throws Exception {
int rnd = ThreadLocalRandom.current().nextInt(0, presetElements.size());
String key = presetElementKeys.get(rnd);
String value = String.valueOf(presetElements.get(key));
Transaction transaction = jedis.multi();
Snapshot snapshot = commandTracker.snapshot();
Snapshot discardSnapshot = discardTracker.snapshot();
Snapshot txsnapshot = execTracker.snapshot();
discardSnapshot.increment();
Response<Long> added = transaction.sadd(key, value);
transaction.discard();
assertNull(jedis.get(key));
txsnapshot.validate();
snapshot.validate();
discardSnapshot.validate();
}
示例3: testCloseDiscards
import redis.clients.jedis.Transaction; //導入方法依賴的package包/類
@Test
public void testCloseDiscards() throws Exception {
int rnd = ThreadLocalRandom.current().nextInt(0, presetElements.size());
String key = presetElementKeys.get(rnd);
String value = String.valueOf(presetElements.get(key));
Transaction transaction = jedis.multi();
Snapshot snapshot = commandTracker.snapshot();
Snapshot discardSnapshot = discardTracker.snapshot();
Snapshot txsnapshot = execTracker.snapshot();
discardSnapshot.increment();
Response<Long> added = transaction.sadd(key, value);
transaction.close();
assertNull(jedis.get(key));
txsnapshot.validate();
snapshot.validate();
discardSnapshot.validate();
}
示例4: doCallback
import redis.clients.jedis.Transaction; //導入方法依賴的package包/類
@Override
public void doCallback(Transaction tx) {
for (Command cmd : redisCommands) {
switch (cmd.getOp()) {
case SET:
tx.set(cmd.getCacheKey(), cmd.getCacheValue());
break;
case MOD:
tx.set(cmd.getCacheKey(), cmd.getCacheValue());
break;
case DEL:
tx.del(cmd.getCacheKey());
break;
case ADD_MEMBERS:
tx.sadd(cmd.getCacheGroupKey(), cmd.getGroupValues());
break;
case DEL_MEMBERS:
tx.srem(cmd.getCacheGroupKey(), cmd.getGroupValues());
break;
case SETS:
tx.mset(cmd.getKeyvalues());
default:
break;
}
}
}
示例5: multi
import redis.clients.jedis.Transaction; //導入方法依賴的package包/類
@Test
public void multi() {
Transaction trans = jedis.multi();
trans.sadd("foo", "a");
trans.sadd("foo", "b");
trans.scard("foo");
List<Object> response = trans.exec();
List<Object> expected = new ArrayList<Object>();
expected.add(1L);
expected.add(1L);
expected.add(2L);
assertEquals(expected, response);
// Binary
trans = jedis.multi();
trans.sadd(bfoo, ba);
trans.sadd(bfoo, bb);
trans.scard(bfoo);
response = trans.exec();
expected = new ArrayList<Object>();
expected.add(1L);
expected.add(1L);
expected.add(2L);
assertEquals(expected, response);
}
示例6: set
import redis.clients.jedis.Transaction; //導入方法依賴的package包/類
@Override
public void set(String key, String sessionsKey, byte[] session, int timeout) throws UnsupportedEncodingException {
try(Jedis jedis = this.jedisPool.getResource()) {
Transaction t = jedis.multi();
t.setex(key.getBytes(Protocol.CHARSET), timeout, session);
t.sadd(sessionsKey, key);
t.exec();
}
}