Reputation: 59
I have stored some data in Redis using Jedis
.
Now I want to retrieve set values if the key exists in the set.
I'm using get
function but I end up getting this error:
WRONGTYPE Operation against a key holding the wrong kind of value.
String str = jedis.get(word);
To store data I have serialized my Node
class using toString
function.
jedis.sadd(word, toString(node));
node
is an instance of Node
class.
Upvotes: 2
Views: 4181
Reputation: 33637
You are creating a set
in redis hence you need to use set
related functions like smembers
.
OR
You should be using set
instead of sadd
and then use get
to read the value back.
Upvotes: 1
Reputation: 158
step 1 : You need to autowired redish
@Autowired
private RedisTemplate<String, Test> redisTemplate;
step 2 : KEY -> your key value for redis. ex. Your class name "Test" ,
testObj.id --> id of your obj and testObj --> your object
redisTemplate.opsForHash().put(KEY, testObj.id, testObj);
step 3 : get Your object from redis. your key and object id. if you are
need all object means
get single obj --> redisTemplate.opsForHash().get(KEY, id);
get need all object means Map<Object, Object> obj=
redisTemplate.opsForHash().entries(KEY);
Upvotes: 0