Unable to fetch redis nested hash key values from javascript that are stored using spring RedisTemplate

Viewed 196

The redis values is populated using Java spring package: RedisTemplate. Now i need to consume these values in express server. For which i am using npm package: redis.

The regular redis key values can be retrieved.

Ex: const redis = require("redis");

const client = redis.createClient();

Able to get value with client.get

I am not able to get the stored hash values. They are stored using spring: redisTemplate.opsForHash().putIfAbsent("key", "hashkey", "hashvalue") Here, the key also is stored by encrypting.

Since the key is encrypted, I am unable to retrieve this hash key value from javascript code. tried using: client.hget, client.hgetall.

Can you help me out in retrieving the hash key values that are stored using java spring package?

1 Answers

RedisTemplate by default will serialize the hash keys. if we do not specify the the type of serialization, then it will use a default RedisSerialization. And if this happens, then only the app with RedisTemplate package can access the hash structure. To overcome this, we have to specify the type of serialization while initializing the redisTemplate object. Ex:

redisTemplate.setHashKeySerializer(new StringRedisSerializer(StandardCharsets.UTF_8));

redisTemplate.setKeySerializer(new StringRedisSerializer(StandardCharsets.UTF_8));

With above serialization, we can access the hash structure from redis-cli as well as from any other web-app like node-js app.

Related