Search code examples
springspring-data-redis

Does Spring data redis support pop multiple elements for set operations?


As the title, i found jedis support pop multiple elements jedis commands source code

I reviewed spring-data-redis project's source code, and cant't find any method support this.

How could i do for pop multiple elements in spring data redis?


Solution

  • RedisSetCommands#spop(key, count) and its counterpart in SetOperations is currently not implemented in Spring Data Redis. I've opened DATAREDIS-668 to add support for the count option.

    Meanwhile you can use RedisTemplate#execute to obtain the value via the underlying connection, having the template take care of resource handling.

    redisTemplate.execute((RedisCallback<Set<String>>) conn -> {
    
      Jedis jedis = (Jedis) conn.getNativeConnection(); // access native driver 
      return jedis.spop(key, count);
    });