Girish NJ
Girish NJ

Reputation: 119

Redis BITOP using Spring data Redis

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

Answers (3)

Girish NJ
Girish NJ

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

Might be useful for someone with above issue.

Upvotes: 0

gosaint
gosaint

Reputation: 11

    long count=redisTemplate.execute((RedisCallback<Long>)
            con->con.bitOp(RedisStringCommands.BitOperation.AND,
                    "20210428".getBytes(),
                    "20210429".getBytes(),
                    "20210430".getBytes()
            )
    );

Upvotes: 1

NappingRabbit
NappingRabbit

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

Related Questions