Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2204

Get Set value from Redis using RedisTemplate

$
0
0

I am able to retrieve values from Redis using Jedis:

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();    }

But when I am trying to use Spring's RedisTemplate , I am not getting any data. My data is stored in Redis as a 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 "";    }

Can someone please point out to me what am I missing?

EDIT : My xml config for 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" />

Viewing all articles
Browse latest Browse all 2204

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>