@Override @Nullable public E poll() { return listOps.leftPop(); }
@Override public void add(int index, E element) { if (index == 0) { listOps.leftPush(element); cap(); return; } int size = size(); if (index == size()) { listOps.rightPush(element); cap(); return; } if (index < 0 || index > size) { throw new IndexOutOfBoundsException(); } throw new IllegalArgumentException("Redis supports insertion only at the beginning or the end of the list"); }
@Override public List<E> range(long start, long end) { return listOps.range(start, end); }
/** * Constructs a new {@link DefaultRedisList} instance. * * @param boundOps {@link BoundListOperations} for the value type of this list. * @param maxSize */ public DefaultRedisList(BoundListOperations<String, E> boundOps, int maxSize) { super(boundOps.getKey(), boundOps.getOperations()); listOps = boundOps; setMaxSize(maxSize); }
byte[] value = null; try { value = this.boundListOperations.rightPop(this.receiveTimeout, TimeUnit.MILLISECONDS); if (value != null) { if (!this.active) { this.boundListOperations.rightPush(value); return; value = this.template.boundListOps(uuid).rightPop(this.receiveTimeout, TimeUnit.MILLISECONDS); if (value != null) { if (!this.active) { this.template.boundListOps(uuid).rightPush(value); byte[] serialized = stringSerializer.serialize(uuid); if (serialized != null) { this.boundListOperations.rightPush(serialized); this.template.boundListOps(uuid + QUEUE_NAME_SUFFIX).leftPush(value);
@Override public int size() { Long size = listOps.size(); checkResult(size); return size.intValue(); }
@Override @Nullable public E pollLast() { return listOps.rightPop(); }
@Override public void addFirst(E e) { listOps.leftPush(e); cap(); }
private byte[] popForValue() { byte[] value = null; try { if (this.rightPop) { value = this.boundListOperations.rightPop(this.receiveTimeout, TimeUnit.MILLISECONDS); } else { value = this.boundListOperations.leftPop(this.receiveTimeout, TimeUnit.MILLISECONDS); } } catch (Exception e) { this.listening = false; if (this.active) { logger.error("Failed to execute listening task. Will attempt to resubmit in " + this.recoveryInterval + " milliseconds.", e); publishException(e); sleepBeforeRecoveryAttempt(); } else { logger.debug("Failed to execute listening task. " + e.getClass() + ": " + e.getMessage()); } } return value; }
@Override public boolean add(E value) { listOps.rightPush(value); cap(); return true; }
@Override public RedisList<E> trim(int start, int end) { listOps.trim(start, end); return this; }
@Override @Nullable public E peekLast() { return listOps.index(-1); }
/** * Returns the size of the Queue specified by {@link #boundListOperations}. The queue is * represented by a Redis list. If the queue does not exist <code>0</code> * is returned. See also http://redis.io/commands/llen * @return Size of the queue. Never negative. */ @ManagedMetric public long getQueueSize() { return Optional.ofNullable(this.boundListOperations.size()) .orElse(0L); }
@Override @Nullable public E pollLast(long timeout, TimeUnit unit) throws InterruptedException { return listOps.rightPop(timeout, unit); }
/** * Clear the Redis Queue specified by {@link #boundListOperations}. */ @ManagedOperation public void clearQueue() { this.boundListOperations.getOperations().delete(this.boundListOperations.getKey()); }
@Override public MessageGroup addMessageToGroup(Object groupId, Message<?> message) { this.redisTemplate.boundListOps(groupId).leftPush(message); return null; }
private byte[] popForValue() { byte[] value = null; try { if (this.rightPop) { value = this.boundListOperations.rightPop(this.receiveTimeout, TimeUnit.MILLISECONDS); } else { value = this.boundListOperations.leftPop(this.receiveTimeout, TimeUnit.MILLISECONDS); } } catch (Exception e) { this.listening = false; if (this.active) { logger.error("Failed to execute listening task. Will attempt to resubmit in " + this.recoveryInterval + " milliseconds.", e); publishException(e); sleepBeforeRecoveryAttempt(); } else { logger.debug("Failed to execute listening task. " + e.getClass() + ": " + e.getMessage()); } } return value; }