Java Code Examples for org.redisson.api.RDeque#addFirst()

The following examples show how to use org.redisson.api.RDeque#addFirst() . 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: RedissionUtilsTest.java    From Redis_Learning with Apache License 2.0 5 votes vote down vote up
/** 
 * RDeque ӳ��Ϊ redis server �� list���� 
 * ˫�˶���--��ͷ�Ͷ�β������ӻ����Ƴ���Ҳ��ѭ���е������ȳ� 
 *  redis server ����: 
 * �鿴���м�---->keys * 
 * �鿴key������--->type testDeque 
 * �鿴key��ֵ ---->lrange testDeque 0 10   
 */  
@Test  
public void testGetRDeque() {  
    RDeque<Integer> rDeque=RedissionUtils.getInstance().getRDeque(redisson, "testDeque");  
    //���˫�˶���  
    rDeque.clear();  
    Collection<Integer> c=Arrays.asList(12,45,12,34,56,78);  
    rDeque.addAll(c);  
    //��ͷ���Ԫ��  
    rDeque.addFirst(100);  
    //��β���Ԫ��  
    rDeque.addLast(200);  
    System.out.println(Arrays.toString(rDeque.toArray()));  
    //�鿴��ͷԪ��  
    System.out.println(rDeque.peek());  
    System.out.println(rDeque.peekFirst());  
    //�鿴��βԪ��  
    System.out.println(rDeque.peekLast());  
    System.out.println(Arrays.toString(rDeque.toArray()));  
    //�Ƴ���ͷԪ��  
    System.out.println(rDeque.poll());  
    System.out.println(rDeque.pollFirst());  
    //�Ƴ���βԪ��  
    System.out.println(rDeque.pollLast());  
    System.out.println(Arrays.toString(rDeque.toArray()));  
    //��Ӷ�βԪ��  
    System.out.println(rDeque.offer(300));  
    System.out.println(rDeque.offerFirst(400));  
    System.out.println(Arrays.toString(rDeque.toArray()));  
    //�Ƴ���ͷԪ��  
    System.out.println(rDeque.pop());  
    //��ʾ˫�˶��е�Ԫ��  
    System.out.println(Arrays.toString(rDeque.toArray()));  
      
}
 
Example 2
Source File: RedissonDequeTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveLastOccurrence() {
    RDeque<Integer> queue1 = redisson.getDeque("deque1");
    queue1.addFirst(3);
    queue1.addFirst(1);
    queue1.addFirst(2);
    queue1.addFirst(3);

    queue1.removeLastOccurrence(3);

    assertThat(queue1).containsExactly(3, 2, 1);
}
 
Example 3
Source File: RedissonDequeTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveFirstOccurrence() {
    RDeque<Integer> queue1 = redisson.getDeque("deque1");
    queue1.addFirst(3);
    queue1.addFirst(1);
    queue1.addFirst(2);
    queue1.addFirst(3);

    queue1.removeFirstOccurrence(3);

    assertThat(queue1).containsExactly(2, 1, 3);
}
 
Example 4
Source File: RedissonDequeTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveLast() {
    RDeque<Integer> queue1 = redisson.getDeque("deque1");
    queue1.addFirst(1);
    queue1.addFirst(2);
    queue1.addFirst(3);

    Assert.assertEquals(1, (int)queue1.removeLast());
    Assert.assertEquals(2, (int)queue1.removeLast());
    Assert.assertEquals(3, (int)queue1.removeLast());
}
 
Example 5
Source File: RedissonDequeTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveFirst() {
    RDeque<Integer> queue1 = redisson.getDeque("deque1");
    queue1.addFirst(1);
    queue1.addFirst(2);
    queue1.addFirst(3);

    Assert.assertEquals(3, (int)queue1.removeFirst());
    Assert.assertEquals(2, (int)queue1.removeFirst());
    Assert.assertEquals(1, (int)queue1.removeFirst());
}
 
Example 6
Source File: RedissonDequeTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testPeek() {
    RDeque<Integer> queue1 = redisson.getDeque("deque1");
    Assert.assertNull(queue1.peekFirst());
    Assert.assertNull(queue1.peekLast());
    queue1.addFirst(2);
    Assert.assertEquals(2, (int)queue1.peekFirst());
    Assert.assertEquals(2, (int)queue1.peekLast());
}
 
Example 7
Source File: RedissonDequeTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testPollLastAndOfferFirstTo() {
    RDeque<Integer> queue1 = redisson.getDeque("deque1");
    queue1.addFirst(3);
    queue1.addFirst(2);
    queue1.addFirst(1);

    RDeque<Integer> queue2 = redisson.getDeque("deque2");
    queue2.addFirst(6);
    queue2.addFirst(5);
    queue2.addFirst(4);

    queue1.pollLastAndOfferFirstTo(queue2.getName());
    assertThat(queue2).containsExactly(3, 4, 5, 6);
}
 
Example 8
Source File: RedissonDequeTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddFirst() {
    RDeque<Integer> queue = redisson.getDeque("deque");
    queue.addFirst(1);
    queue.addFirst(2);
    queue.addFirst(3);

    assertThat(queue).containsExactly(3, 2, 1);
}
 
Example 9
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();
}