본문 바로가기

Engineering/DB

jedis sample source

728x90

redis 서버를 실행시키고, java 클라이언트(jedis)로 서버에 접속 및 데이터 추가/조회를 위한 간단한 샘플


- maven dependency

<dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
    <version>2.6.0</version>
    <type>jar</type>
    <scope>compile</scope>
</dependency>


- sample source

package jedisTest;


import redis.clients.jedis.Jedis;

import redis.clients.jedis.JedisPool;

import redis.clients.jedis.JedisPoolConfig;


public class jedisConnect {

public static void main(String[] args)

    {

        JedisPool pool = new JedisPool(new JedisPoolConfig(), "192.168.1.230");

        

        Jedis jedis = pool.getResource();

        

        try

        {

            jedis.set("id1", "juju");

            jedis.set("id2", "jojo");

            jedis.hset("mediabucket:1155""12345""555");

            jedis.hset("mediabucket:1155""12346""666");

            

            System.out.println(jedis.get("id1"));

            System.out.println(jedis.get("id2"));


            System.out.println(jedis.hget("mediabucket:1155", "12345"));

            System.out.println(jedis.hget("mediabucket:1155", "12346"));

             

            System.out.println(jedis.dbSize());

        }

        finally

        { 

            pool.returnResource(jedis);

        } 

        pool.destroy();

    }

}


도움받은 곳 :

http://ash84.tistory.com/817