jedis调用redis源码Demo,直接导入工程就可以运行。
redis目录下有redis安装文件和入门电子书
redis64-2.8.9.zip
redisbin_x32.zip
Redis入门指南(JB51.NET).pdf
Redis设计与实现.pdf
src:
FirestJedisTest.java
JedisClusterTest.java
RedisClient.java
RedisShardPoolTest.java
import redis.clients.jedis.Jedis;
import redis.clients.jedis.exceptions.JedisConnectionException;
public class FirestJedisTest
{
private static Jedis jedis = new Jedis("127.0.0.1");
public void testConn()
{
try
{
jedis.connect();
jedis.ping();
jedis.quit();
}
catch (JedisConnectionException e)
{
e.printStackTrace();
}
}
public void setTest()
{
try
{
for (int i = 0; i < 100; i++)
{
jedis.set("key" + i, "value" + i);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void setStrTest(String key, String value)
{
try
{
jedis.set(key, value);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void getTest()
{
try
{
for (int i = 0; i < 100; i++)
{
System.out.println(jedis.get("key" + i));
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void delTest()
{
try
{
for (int i = 0; i < 100; i++)
{
System.out.println(jedis.del("key" + i));
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
FirestJedisTest client = new FirestJedisTest();
client.setTest();
client.getTest();
// client.delTest();
System.out.println(jedis.dbSize());
}
}
1