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类型数据的命令操作
最新推荐文章于 2024-09-07 12:59:11 发布