0

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

Girish NJ
  • 99
  • 1
  • 7

3 Answers3

1

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.

NappingRabbit
  • 1,888
  • 1
  • 13
  • 18
1
    long count=redisTemplate.execute((RedisCallback<Long>)
            con->con.bitOp(RedisStringCommands.BitOperation.AND,
                    "20210428".getBytes(),
                    "20210429".getBytes(),
                    "20210430".getBytes()
            )
    );
gosaint
  • 11
  • 1
0

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(B‌​itOperation.AND,Jedi‌​sConverters.toBytes(‌​destination), JedisConverters.toBytes(firstKey),JedisConverters.toBytes(ls‌​econdKey)); 

Might be useful for someone with above issue.

Girish NJ
  • 99
  • 1
  • 7