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));
}
}
技术改变一切