Reputation: 119
I am looking for an option to perform Redis BITOP using Spring RedisTemplate. I tried searching internet for an example but couldn't find anything similar. I was able to get the bitOp function from JedisStringCommands class but not sure how to use it.
The requirement is to do AND operation between values stored in two key's in REDIS and save it into a different key.
Looking for Spring Redis implementation for - https://redis.io/commands/bitop
Upvotes: 0
Views: 205
Reputation: 119
I think I got a solution. Its not an elegant way but I was able to manage to get the bit operations performed on key. This is what I have used.
redisTemplate.getConnectionFactory().getConnection().bitOp(BitOperation.AND,JedisConverters.toBytes(destination), JedisConverters.toBytes(firstKey),JedisConverters.toBytes(lsecondKey));
Might be useful for someone with above issue.
Upvotes: 0
Reputation: 11
long count=redisTemplate.execute((RedisCallback<Long>)
con->con.bitOp(RedisStringCommands.BitOperation.AND,
"20210428".getBytes(),
"20210429".getBytes(),
"20210430".getBytes()
)
);
Upvotes: 1
Reputation: 1918
looking at the Spring Docs I do not see any built-in bitop commands.
You can I think use public <T> T execute(RedisCallback<T> action)
and then use Redis
native commands. Here is a link to that function's docs.
Upvotes: 1