Java Code Examples for org.redisson.api.RedissonClient#getQueue()

The following examples show how to use org.redisson.api.RedissonClient#getQueue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QueueExamples.java    From redisson-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    // connects to 127.0.0.1:6379 by default
    RedissonClient redisson = Redisson.create();

    RQueue<String> queue = redisson.getQueue("myQueue");
    queue.add("1");
    queue.add("2");
    queue.add("3");
    queue.add("4");
    
    queue.contains("1");
    queue.peek();
    queue.poll();
    queue.element();
    
    for (String string : queue) {
        // iteration through bulk loaded values
    }
    
    boolean removedValue = queue.remove("1");
    queue.removeAll(Arrays.asList("1", "2", "3"));
    queue.containsAll(Arrays.asList("4", "1", "0"));
    
    List<String> secondList = new ArrayList<>();
    secondList.add("4");
    secondList.add("5");
    queue.addAll(secondList);

    RQueue<String> secondQueue = redisson.getQueue("mySecondQueue");
    
    queue.pollLastAndOfferFirstTo(secondQueue.getName());
    
    redisson.shutdown();
}
 
Example 2
Source File: DequeExamples.java    From redisson-examples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    // connects to 127.0.0.1:6379 by default
    RedissonClient redisson = Redisson.create();

    RDeque<String> deque = redisson.getDeque("myQueue");
    deque.add("1");
    deque.add("2");
    deque.add("3");
    deque.add("4");
    
    deque.contains("1");
    deque.peek();
    deque.poll();
    deque.element();
    
    for (String string : deque) {
        // iteration through bulk loaded values
    }
    
    boolean removedValue = deque.remove("1");
    deque.removeAll(Arrays.asList("1", "2", "3"));
    deque.containsAll(Arrays.asList("4", "1", "0"));
    
    List<String> secondList = new ArrayList<>();
    secondList.add("4");
    secondList.add("5");
    deque.addAll(secondList);

    RQueue<String> secondQueue = redisson.getQueue("mySecondQueue");
    
    deque.pollLastAndOfferFirstTo(secondQueue.getName());
    
    deque.addLast("8");
    deque.addFirst("9");
    
    deque.addLast("30");
    deque.addFirst("80");
    
    String firstValue = deque.pollFirst();
    String lastValue = deque.pollLast();
    
    String peekFirstValue = deque.peekFirst();
    String peekLastValue = deque.peekLast();
    
    String firstRemoved = deque.removeFirst();
    String lastRemoved = deque.removeLast();
    
    redisson.shutdown();
}
 
Example 3
Source File: BlockingDequeExamples.java    From redisson-examples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws InterruptedException {
    // connects to 127.0.0.1:6379 by default
    RedissonClient redisson = Redisson.create();

    RBlockingDeque<String> deque = redisson.getBlockingDeque("myQueue");
    deque.add("1");
    deque.add("2");
    deque.add("3");
    deque.add("4");
    
    deque.contains("1");
    deque.peek();
    deque.poll();
    deque.element();
    
    for (String string : deque) {
        // iteration through bulk loaded values
    }
    
    boolean removedValue = deque.remove("1");
    deque.removeAll(Arrays.asList("1", "2", "3"));
    deque.containsAll(Arrays.asList("4", "1", "0"));
    
    List<String> secondList = new ArrayList<>();
    secondList.add("4");
    secondList.add("5");
    deque.addAll(secondList);

    RQueue<String> secondQueue = redisson.getQueue("mySecondQueue");
    
    deque.pollLastAndOfferFirstTo(secondQueue.getName());
    
    deque.addLast("8");
    deque.addFirst("9");
    
    deque.addLast("30");
    deque.addFirst("80");
    
    String firstValue = deque.pollFirst();
    String lastValue = deque.pollLast();
    
    String peekFirstValue = deque.peekFirst();
    String peekLastValue = deque.peekLast();
    
    String firstRemoved = deque.removeFirst();
    String lastRemoved = deque.removeLast();
    
    
    Thread t = new Thread(() -> {
        try {
            String element1 = deque.poll(10, TimeUnit.SECONDS);
            
            String element2 = deque.take();
            
            String element3 = deque.pollFirst(3, TimeUnit.SECONDS);
            
            String element4 = deque.pollLast(3, TimeUnit.SECONDS);
            
            String element5 = deque.takeFirst();
            
            String element6 = deque.takeLast();
            
            String element7 = deque.pollLastAndOfferFirstTo(secondQueue.getName(), 4, TimeUnit.SECONDS);
            
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    });
    
    t.start();
    t.join();

    redisson.shutdown();
}
 
Example 4
Source File: RedissionUtils.java    From Redis_Learning with Apache License 2.0 2 votes vote down vote up
/** 
 * ��ȡ���� 
 * @param redisson 
 * @param objectName 
 * @return 
 */  
public <V> RQueue<V> getRQueue(RedissonClient redisson,String objectName){  
    RQueue<V> rQueue=redisson.getQueue(objectName);  
    return rQueue;  
}