其他分享
首页 > 其他分享> > string类型数据的命令操作

string类型数据的命令操作

作者:互联网

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 StringTest {
    @Autowired
    private JedisPool jedisPool;

    //string类型数据的命令操作
    //设置键值
    @Test
    public void test01(){
        jedisPool.getResource().set("lhh","1");
        jedisPool.getResource().set("lhh","2");
    }

    //读取键值
    @Test
    public void test02(){
        jedisPool.getResource().get("lhh");
        System.out.println("jedisPool = " + jedisPool);
    }

    //数值类型自增1
    @Test
    public void test03(){
        Long lhh = jedisPool.getResource().incr("lhh");
        System.out.println("lhh = " + lhh);
    }

    //数值类型自减1
    @Test
    public void test04(){
        Long lhh1 = jedisPool.getResource().decr("lhh");
        System.out.println("lhh1 = " + lhh1);
    }

    //查看值的长度
    @Test
    public void test05(){
        Long lhh2 = jedisPool.getResource().strlen("lhh");
        System.out.println("lhh2 = " + lhh2);
    }


}

标签:string,getResource,lhh,命令,jedisPool,Test,类型,import,public
来源: https://blog.csdn.net/qqyang_/article/details/120447672