2

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.

2
  • What code u used to store the data? Commented Mar 3, 2018 at 8:24
  • @Ankur updated the question Commented Mar 3, 2018 at 8:26

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

smembers returns a set but I guess the value should be a String!
@Cyber: Then you should not use sadd. Use set and then use get.
0
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);

1 Comment

Why would I need to use Spring?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.