package com.xiexin.redistest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import redis.clients.jedis.JedisPool;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath:applicationContext.xml"})
public class ListTest {
@Autowired
private JedisPool jedisPool;
//list类型数据的命令操作
//对列表city插入元素:nanjing Suzhou Hangzhou wuxi
@Test
public void test01(){
Long lpush = jedisPool.getResource().lpush("city", "nanjing", "suzhou", "hangzhou", "wuxi");
System.out.println("lpush = " + lpush);
}
//将列表city里的头部的元素移除
@Test
public void test02(){
String city = jedisPool.getResource().rpop("city");
System.out.println("city = " + city);
}
//将name列表的尾部元素移除到number列表的头部
@Test
public void test03(){
Long lpush1 = jedisPool.getResource().lpush("name", "wawa", "wawa2");
Long lpush2 = jedisPool.getResource().lpush("number", "wawa2", "wawa4");
String rpoplpush = jedisPool.getResource().rpoplpush("name", "number");
System.out.println("rpoplpush = " + rpoplpush);
}
//对一个已存在的列表插入新元素
@Test
public void test04(){
Long rpush = jedisPool.getResource().rpush("name", "xiaohuihui");
System.out.println("rpush = " + rpush);
}
//查看list的值长度
@Test
public void test05(){
Long city = jedisPool.getResource().llen("city");
System.out.println("city = " + city);
}
}