/** * Disable or enable auto-flush behavior for all connections. * * @param autoFlush state of autoFlush. * @see StatefulConnection#setAutoFlushCommands(boolean) */ public void setAutoFlushCommands(boolean autoFlush) { synchronized (stateLock) { this.autoFlushCommands = autoFlush; connectionProvider.forEach(connection -> connection.setAutoFlushCommands(autoFlush)); } }
/** * Set auto-flush on all commands. Synchronize on {@code stateLock} to initiate a happens-before relation and clear the * thread caches of other threads. * * @param autoFlush state of autoFlush. */ @Override public void setAutoFlushCommands(boolean autoFlush) { synchronized (stateLock) { this.autoFlushCommands = autoFlush; } connectionProvider.forEach(connection -> connection.setAutoFlushCommands(autoFlush)); }
@Override public void mset(Collection<MSetParam> params) { // 为了提升性能,开启pipeline this.connection.setAutoFlushCommands(false); RedisAsyncCommands<byte[], byte[]> asyncCommands = connection.async(); try { LettuceRedisUtil.executeMSet((AbstractRedisAsyncCommands<byte[], byte[]>) asyncCommands, cacheManager, params); } catch (Exception e) { log.error(e.getMessage(), e); } finally { this.connection.flushCommands(); } }
@Override public void hset(byte[] key, byte[] field, byte[] value, int seconds) { // 为了提升性能,开启pipeline this.connection.setAutoFlushCommands(false); RedisAsyncCommands<byte[], byte[]> asyncCommands = connection.async(); asyncCommands.hset(key, field, value); asyncCommands.expire(key, seconds); this.connection.flushCommands(); }
@Override public void delete(Set<CacheKeyTO> keys) { // 为了提升性能,开启pipeline this.connection.setAutoFlushCommands(false); RedisAsyncCommands<byte[], byte[]> asyncCommands = connection.async(); try { for (CacheKeyTO cacheKeyTO : keys) { String cacheKey = cacheKeyTO.getCacheKey(); if (null == cacheKey || cacheKey.isEmpty()) { continue; } if (log.isDebugEnabled()) { log.debug("delete cache {}", cacheKey); } String hfield = cacheKeyTO.getHfield(); if (null == hfield || hfield.isEmpty()) { asyncCommands.del(KEY_SERIALIZER.serialize(cacheKey)); } else { asyncCommands.hdel(KEY_SERIALIZER.serialize(cacheKey), KEY_SERIALIZER.serialize(hfield)); } } } catch (Exception ex) { throw new RuntimeException(ex); } finally { this.connection.flushCommands(); } } }
/** * Disable or enable auto-flush behavior for all connections. * * @param autoFlush state of autoFlush. * @see StatefulConnection#setAutoFlushCommands(boolean) */ public void setAutoFlushCommands(boolean autoFlush) { synchronized (stateLock) { this.autoFlushCommands = autoFlush; connectionProvider.forEach(connection -> connection.setAutoFlushCommands(autoFlush)); } }
/** * Set auto-flush on all commands. Synchronize on {@code stateLock} to initiate a happens-before relation and clear the * thread caches of other threads. * * @param autoFlush state of autoFlush. */ @Override public void setAutoFlushCommands(boolean autoFlush) { synchronized (stateLock) { this.autoFlushCommands = autoFlush; } connectionProvider.forEach(connection -> connection.setAutoFlushCommands(autoFlush)); }