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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | package test.redis; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import redis.clients.jedis.Jedis; /* * ************************************************************************************ * * RedisHashTest.java * * ************************************************************************************ * * @version 1.0.00 2017-02-10 dorbae Initialize * @since 2017-02-10 * @author dorbae * * ************************************************************************************ */ public class RedisHashTest { public RedisHashTest() { // TODO Auto-generated constructor stub } public static void main(String[] args) { Jedis jedis = new Jedis( "btcxen.esb.broker1"); System.out.println( "Connection to server sucessfully"); jedis.hset( "hs1", "col1", "val1"); jedis.hset( "hs1", "col2", "val2"); jedis.hset( "hs1", "col3", "val3"); jedis.hset( "hs1", "col4", "val4"); java.util.Map< String, String> map = new java.util.HashMap< String, String>(); map.put( "col1", "mval1"); map.put( "col2", "mval2"); map.put( "col3", "mval3"); jedis.hmset( "hs1", map); jedis.hdel( "hs1", "col2", "col3"); System.out.println( "len=" + jedis.hlen( "hs1")); System.out.println( "hs1.col2="+ jedis.hget( "hs1", "col2")); map = jedis.hgetAll( "hs1"); Iterator< Entry< String, String>> iterator = map.entrySet().iterator(); Entry< String, String> entry = null; while ( iterator.hasNext()) { entry = iterator.next(); System.out.printf( "key:%s, value:%s%n", entry.getKey(), entry.getValue()); } jedis.close(); } } |
Thursday, 16 February 2017
[Redis] Hash in Java
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment