Install Jedis on Ubuntu 10.04 본문

Programming

Install Jedis on Ubuntu 10.04

halatha 2011. 8. 12. 05:39

installation

$ git clone git://github.com/xetorthio/jedis.git

$ cd jedis

jedis$ mvn compile

# execute two redis servers for test

jedis$ redis-server jedis/conf/redis.conf

jedis$ redis-server jedis/conf/redis2.conf

jedis$ mvn package

 

basic usage

/*
javac -cp ../jedis/target/jedis-2.0.1-SNAPSHOT.jar:./commons-pool-1.5.6/commons-pool-1.5.6.jar TestJedis.java
java -cp .:../jedis/target/jedis-2.0.1-SNAPSHOT.jar:./commons-pool-1.5.6/commons-pool-1.5.6.jar TestJedis
 */
import java.util.Set;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class TestJedis	{
	public static void main(String[] args)	{
		JedisPool pool = new JedisPool(new JedisPoolConfig(), "localhost");
		Jedis jedis = pool.getResource();
		try {
			/// ... do stuff here ... for example
			jedis.set("foo", "bar");
			String foobar = jedis.get("foo");
			System.out.println("foobar = " + foobar);
			jedis.zadd("sose", 0, "car"); jedis.zadd("sose", 0, "bike"); 
			Set<String> sose = jedis.zrange("sose", 0, -1);
			System.out.println("sose = " + sose);
		} finally {
			/// ... it's important to return the Jedis instance to the pool
			//once you've finished using it
			pool.returnResource(jedis);
		}
		/// ... when closing your application:
		pool.destroy();
	}
}
Comments