我正在试验 Spring Data Redis。我编写了一个 Java 类,它允许我连接到 Redis 服务器,但不会在服务器中保留数据。有人会知道可能有什么问题吗?以下是一些细节——
我的弹簧配置看起来像-
<bean id="jedisConnFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:use-pool="true" p:host-name="127.0.0.1" p:port="6379"/>
<!-- redis template definition -->
<bean id="redisTemplate"
class="org.springframework.data.redis.core.RedisTemplate"
p:connection-factory-ref="jedisConnFactory"/>
Run Code Online (Sandbox Code Playgroud)
我的 Java 代码看起来像这样 -
public class CacheClient {
@Autowired
private RedisTemplate<String, String> template;
public void setValue(String key, String value){
template.boundValueOps(key).set(value);
}
}
Run Code Online (Sandbox Code Playgroud)
一旦我调用了 template.setValue(key,value),我就会在 redis-cli 上执行“获取密钥”,但我没有看到为该密钥设置的任何值。
有人可以帮忙吗?
谢谢