spring-date-redis-demo list集合篇

package text;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:spring/applicationContext-redis.xml")
public class TestList {

    @Autowired
    private RedisTemplate redisTemplate;


    @Test
    public void setValue(){
        redisTemplate.boundListOps("namelist1").rightPush("刘备");
        redisTemplate.boundListOps("namelist1").rightPush("关羽");
        redisTemplate.boundListOps("namelist1").rightPush("张飞");
    }

    /**
     * 显示右压栈的值
     */
    @Test
    public void testGetValue(){
        List list = redisTemplate.boundListOps("namelist1").range(0, 10);
        System.out.println("显示的值是:"+list);
    }


    /**
     * 删除
     */
    @Test
    public void  delete(){
        redisTemplate.delete("namelist1");
    }


    /**
     * 左压栈
     */
    @Test
    public void testSetValue2(){
        redisTemplate.boundListOps("namelist2").leftPush("杂毛超");
        redisTemplate.boundListOps("namelist2").leftPush("杂毛黄");
        redisTemplate.boundListOps("namelist2").leftPush("杂毛程");
    }

    /**
     * 显示左栈
     */
    @Test
    public void testGetValue2(){
            List list=redisTemplate.boundListOps("namelist2").range(0,10);
    }

    //删除值
    @Test
    public void removeValue(){
        redisTemplate.boundListOps("namelist2").remove(0,"杂毛黄");
    }




}

你可能感兴趣的:(spring-date-redis-demo list集合篇)