3

I have a Java Spring application that uses Redisson client to store some data in redis in a hash. The stored keys are strings (e.g. "key1") and the values are java objects. The codec used is the default, so FSTCodec. What I want to do is use a python script (I am using redis-py client) to find a key in redis and delete it. When I get the keys from redis, their format is something like: [b'\xfc\x07key1', b'\xfc\x05key2', b'\xfc\x02key3']. When I do something like this

r = redis.StrictRedis()
hash = r.keys(pattern='*key*')  # to get the hash
hk = r.hkeys(hash[0])
print(hk) # returns [b'\xfc\x07key1', b'\xfc\x05key2', b'\xfc\x02key3']
for key in hk:
   print("key ", key)
   print("value", r.hget(hash[0], key)) #None

the result is none. I have tried multiple ways to get the value but to no avail. (no familiarity with python)

If I do the same in the command line using the redis-cli, the keys are in a bit different format "\xfc\akey1" and when I do HGET test_key "\xfc\akey1", it returns the value correctly.

I should note here that I must be able to find the key with the known being "key1". So, my input is "key1" and I have to go get all the keys and scan through them to find and delete the one that has "key1" in it, in this case, \xfc\x07key1.

I have also tried to decode via decode_responses but I am getting UnicodeDecodeError: 'utf-8' codec can't decode byte in position 0: invalid start byte

Is there a way that I can decode the keys from my python script? As in, remove the \xfc... part added by the FSTCodec. Or else, how can I hget the right key? Is the only solution to change the codec that redisson uses to JsonJacksonCodec? Any help will be much appreciated

Arno
  • 61
  • 3
  • Why don't you change serialization in Redission to use msgpack or JSON? – sonus21 Apr 28 '21 at 02:42
  • That I could do, indeed. But the whole point of the question is that I don't want to make any redis-related changes in the application. – Arno Apr 28 '21 at 10:18

0 Answers0