springDataRedisAPI操作之String

前言:

本文运行环境在项目整合好了springDataRedis,如果整合可参考https://mp.csdn.net/postedit/83350488


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;

/**
 * 值类型操作   key-value(string)
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring/applicationContext-redis.xml")
public class ValueTest {

    @Autowired
    private RedisTemplate redisTemplate;

    @Test
    public void setValue() throws Exception {
        redisTemplate.boundValueOps("valuename13").set("李四");
    }

    @Test
    public void getValue() throws Exception {
        String name = (String) redisTemplate.boundValueOps("valuename13").get();
        System.out.println(name);
    }

    @Test
    public void name() throws Exception {
        redisTemplate.delete("valuename13");
    }
}

猜你喜欢

转载自blog.csdn.net/qq_15076569/article/details/83350573