redisTemplate 封装bitcout

@Repository
public class RedisServiceExtend {
@Autowired
private RedisTemplate<String, String> redisTemplate;

private static String redisCode = "utf-8";

public long bitCount(final String key) {
return redisTemplate.exec((RedisCallback<Long>) con -> con.bitCount(key.getBytes()));
}

public Long bitCount(String key, int start, int end) {
return redisTemplate.execute((RedisCallback<Long>) con -> con.bitCount(key.getBytes(), start, end));
}

public Long bitOp(RedisStringCommands.BitOperation op, String saveKey, String... desKey) {
byte[][] bytes = new byte[desKey.length][];
for (int i = 0; i < desKey.length; i++) {
bytes[i] = desKey[i].getBytes();
}
return redisTemplate.execute((RedisCallback<Long>) con -> con.bitOp(op, saveKey.getBytes(), bytes));
}

}
posted @ 2019-06-11 18:19  雷神约  阅读(2066)  评论(0编辑  收藏  举报