Thursday, 16 February 2017

[Redis] List in Java

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package test.redis;

import java.util.List;

import redis.clients.jedis.Jedis;

/*
 * ************************************************************************************
 *
 * RedisListTest.java
 * 
 * ************************************************************************************
 * 
 * @version 1.0.00 2017-02-10 dorbae Initialize
 * @since 2017-02-10
 * @author dorbae
 * 
 * ************************************************************************************
 */
public class RedisListTest {

 public RedisListTest() {
  // TODO Auto-generated constructor stub
 }

 public static void main(String[] args) {
  //Connecting to Redis server on localhost 
       Jedis jedis = new Jedis("btcxen.esb.broker1"); 
       System.out.println("Connection to server sucessfully"); 
       
       //store data in redis list 
       jedis.lpush("tutorial-list", "Redis"); 
       jedis.lpush("tutorial-list", "Mongodb"); 
       jedis.lpush("tutorial-list", "Mysql"); 
       // Get the stored data and print it 
//       List<String> list = jedis.lrange("tutorial-list", 0 ,1); 
       List<String> list = jedis.lrange("tutorial-list", 0 ,6); 
       
       for(int i = 0; i<list.size(); i++) { 
          System.out.println("Stored string in redis:: "+list.get(i)); 
       }
       
       jedis.close();

 }

}

No comments:

Post a Comment