sono in grado di recuperare i valori da Redis
utilizzando Jedis
:Get Set valore da Redis utilizzando RedisTemplate
public static void main(String[] args) {
Jedis jedis = new Jedis(HOST, PORT);
jedis.connect();
Set<String> set = jedis.smembers(KEY);
for (String s : set) {
System.out.println(s);
}
jedis.disconnect();
jedis.close();
}
Ma quando sto cercando di utilizzare Primavera di RedisTemplate
, non ricevo alcun dato. I miei dati vengono memorizzati in Redis
come Set
.
// inject the actual template
@Autowired
private RedisTemplate<String, Object> template;
// inject the template as SetOperations
@Resource(name="redisTemplate")
private SetOperations<String,String> setOps;
public String logHome() {
Set<String> set = setOps.members(KEY);
for(String str:set){
System.out.println(str); //EMPTY
}
Set<byte[]> keys = template.getConnectionFactory().getConnection().keys("*".getBytes());
Iterator<byte[]> it = keys.iterator();
while(it.hasNext()){
byte[] data = (byte[])it.next();
System.out.println(new String(data, 0, data.length)); //KEYS are printed.
}
Set<Object> mySet = template.boundSetOps(KEY).members();
System.out.println(mySet); //EMPTY
return "";
}
Qualcuno può indicare a me che cosa mi manca?
MODIFICA: La mia configurazione xml per RedisTemplate.
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"
p:connection-factory-ref="jedisConnectionFactory"/>
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="myhostname" p:port="6379" />
È possibile pubblicare la configurazione XML/@ Configurazione di RedisTemplate? – mp911de
@ mp911de aggiunto. – Zeeshan
Grazie, conferma la mia ipotesi. – mp911de