0
votes

I have two keys in the Redis. First key contains set of strings as a value.Second key contains the sorted set of object(String as a value and score ). I want to fetch elements where string in first key and string field of the object in the second key are similar.

If I replace object with a string in the second key,I am able to fetch but I want to fetch list of strings along with their score.

I am using Spring-data-redis and jedis for Redis handling.

Is it possible to fetch list of common strings and their corresponding score? If yes, how.

1
Can you add an example of what you describe (with actual redis values)? - zenbeni
[x1, x2, x3, x4, x5, x6] for first key and [POJO[field1=x1, field2=y1], POJO [field1=x2, field2=y2], POJO [field1=x3, field2=y3], POJO [field1=x4, field2=y4], POJO [field1=x5, field2=y5]] for the second key - abhijeet

1 Answers

0
votes

How you are storing your data will affect how you want to retrieve it. By storing your keys as listed in the comment, you are basically limited to string manipulation to determine anything useful, and that really isn't the value of using Redis. (It's not meant for "searching", its meant for fast lookups.)

Consider something like this:

The keys used in Redis will be your first set of strings, each containing a list of values. The values in those lists will be your second set of strings, and may be duplicated in different lists (as you see fit).

LPUSH "x1" "POJO[field1=x1, field2=y1]" "POJO[field1=x1, field2=y2]"

LPUSH "x2" "POJO[field1=x2, field2=y2]"

etc...

When you want the values of your first number

LRANGE x1 0 1000 (or LLEN x1 --> "result", then LRANGE x1 0 "result")