本文整理汇总了Java中redis.clients.jedis.Transaction.del方法的典型用法代码示例。如果您正苦于以下问题:Java Transaction.del方法的具体用法?Java Transaction.del怎么用?Java Transaction.del使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类redis.clients.jedis.Transaction
的用法示例。
在下文中一共展示了Transaction.del方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteMulti
import redis.clients.jedis.Transaction; //导入方法依赖的package包/类
@Override
public boolean deleteMulti(String... keys) {
Jedis jedis = null;
try {
jedis = pool.getResource();
Transaction trans = jedis.multi();
for (String key : keys) {
trans.del(key.getBytes());
}
trans.exec();
pool.returnResource(jedis);
} catch (Exception e) {
LOGGER.warn("Failed to delete key from cache {0}", keys, e);
pool.returnBrokenResource(jedis);
return false;
}
return true;
}
示例2: doRelease
import redis.clients.jedis.Transaction; //导入方法依赖的package包/类
@Override
protected void doRelease(String token) {
jedisClient.watch(lockName);
String currentToken = jedisClient.get(lockName);
if (currentToken == null){
jedisClient.unwatch();
return;
}
if (currentToken.equals(token)) {
Transaction t = jedisClient.multi();
t.del(lockName);
t.exec();
} else {
jedisClient.unwatch();
}
}
示例3: remove
import redis.clients.jedis.Transaction; //导入方法依赖的package包/类
@Override
public <E extends EntityType, T extends TokenType> AuthenticationToken<E, T> remove(final TokenProxy<E, T> tokenProxy) throws IOException {
try(final Jedis jedis = jedisPool.getResource()) {
final byte[] keyBytes = serialize(tokenProxy);
final Transaction transaction = jedis.multi();
final Response<byte[]> oldTokenResponse = transaction.get(keyBytes);
transaction.del(keyBytes);
transaction.exec();
//noinspection unchecked
return (AuthenticationToken<E, T>) deserialize(oldTokenResponse.get());
}
}
示例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: releaseLock
import redis.clients.jedis.Transaction; //导入方法依赖的package包/类
/**
* 释放锁
*
* @param lockName 锁的key
* @param identifier 释放锁的标识
*/
public boolean releaseLock(String lockName, String identifier){
Jedis conn = null;
String lockKey = lockPrefix + lockName;
boolean retFlag = false;
ShardedJedis shardedJedis = jedisPool.getResource();
try {
conn = shardedJedis.getShard(lockKey);
while (true) {
// 监视lock,准备开始事务
conn.watch(lockKey);
// 通过前面返回的value值判断是不是该锁,若是该锁,则删除,释放锁
if (identifier.equals(conn.get(lockKey))) {
Transaction transaction = conn.multi();
transaction.del(lockKey);
List<Object> results = transaction.exec();
if (results == null) {
continue;
}
retFlag = true;
}
conn.unwatch();
break;
}
} catch (JedisException e) {
LOGGER.error("releaseLock found exception", e);
} finally {
if (conn != null) {
jedisPool.returnResource(shardedJedis);
}
}
return retFlag;
}
示例6: unlock
import redis.clients.jedis.Transaction; //导入方法依赖的package包/类
@Override
public boolean unlock(String key, String identifier) {
Preconditions.checkNotNull(key);
Preconditions.checkNotNull(identifier);
String fullKey = RedisKey.fullKey(group, key) + LOCKER_NAME_SUFFIX;
Jedis jedis = RedisHandler.getJedis();
while (true) {
// 监视lock,准备开始事务
jedis.watch(fullKey);
// 看看是不是自己的锁
if (identifier.equals(jedis.get(fullKey))) {
Transaction transaction = jedis.multi();
transaction.del(fullKey);
List<Object> results = transaction.exec();
if (results == null) {
continue;
}
jedis.close();
return true;
}
jedis.unwatch();
break;
}
jedis.close();
return false;
}
示例7: invalidate
import redis.clients.jedis.Transaction; //导入方法依赖的package包/类
@Override
public void invalidate(HttpServerExchange exchange) {
try (Jedis jedis = sessionManager.jedisPool.getResource()) {
Transaction transaction = jedis.multi();
transaction.del(sessionId);
transaction.del(sessionId + CREATED_FIELD);
transaction.exec();
}
if (exchange != null) {
sessionConfig.clearSession(exchange, this.getId());
}
}
示例8: del
import redis.clients.jedis.Transaction; //导入方法依赖的package包/类
@Test public void del() {
// GIVEN
this.jedis.lpush(KEY, VALUE);
Transaction tr = this.jedis.multi();
// WHEN
tr.del(KEY);
tr.exec();
// THEN
assertFalse(this.jedis.exists(KEY));
}
示例9: del
import redis.clients.jedis.Transaction; //导入方法依赖的package包/类
@Override
public void del(String sessionsKey, String key) {
try(Jedis jedis = this.jedisPool.getResource()) {
Transaction t = jedis.multi();
t.srem(sessionsKey, key);
t.del(key);
t.exec();
}
}
示例10: clean
import redis.clients.jedis.Transaction; //导入方法依赖的package包/类
@Override
public void clean(String sessionsKey) {
try(Jedis jedis = this.jedisPool.getResource()) {
Set<String> sessions = jedis.smembers(sessionsKey);
String[] sessionsArray = sessions.toArray(new String[sessions.size()]);
Transaction t = jedis.multi();
t.srem(sessionsKey, sessionsArray);
t.del(sessionsArray);
t.exec();
}
}
示例11: delete
import redis.clients.jedis.Transaction; //导入方法依赖的package包/类
@Override
public boolean delete(int space, ByteString key, Modifier... modifiers) throws IOException {
try (Pooled<RedisClient> lease = clientPool.borrow()) {
Jedis client = lease.get().getClient();
if (client.getDB().intValue() != space) {
client.select(space);
}
byte[] keyBytes = key.toByteArray();
if (modifiers == null || modifiers.length == 0) {
long deleted = client.del(keyBytes);
return deleted == 1;
}
Object ifVersion = null;
for (Modifier modifier : modifiers) {
if (modifier instanceof IfVersion) {
Preconditions.checkArgument(ifVersion == null);
ifVersion = ((IfVersion) modifier).version;
Preconditions.checkArgument(ifVersion != null);
} else {
Preconditions.checkArgument(false);
}
}
Preconditions.checkState(ifVersion != null);
try (Atomic atomic = Atomic.start(client)) {
client.watch(keyBytes);
byte[] existing = client.get(keyBytes);
if (existing == null) {
return false;
}
if (!Arrays.equals(existing, ((ByteString) ifVersion).toByteArray())) {
return false;
}
Transaction writes = atomic.startWrites();
Response<Long> deletedCount = writes.del(keyBytes);
if (!atomic.commit()) {
return false;
}
return deletedCount.get().longValue() == 1;
}
}
}