跳转到主要内容

二进制数据日志库

项目描述

binlog

Test crates.io API docs

一个用于创建和管理任意二进制数据日志的Rust库。目前它用于收集传感器数据。但在需要以几乎(但不完全)追加方式存储时间序列数据的情况下,它通常很有用。

日志的底层存储可以通过几个特质进行插件式配置。Binlog通过sqlite、redis和内存只读方式内置了实现。此外,Python绑定允许您从Python中使用(Binlog的子集)。

用法

Rust中

一个小例子

use binlog::{Entry, Error, Range, RangeableStore, SqliteStore, Store};
use std::borrow::Cow;
use string_cache::Atom;

/// Demonstrates the sqlite store, with results in `example.db`. You may want to delete that before
/// running this to see the results of this on an empty database.
fn main() -> Result<(), Error> {
    // Create a new datastore with sqlite backing. The result will be stored in example.db, with
    // default compression options. In-memory is also possible via
    // `binlog::MemoryStore::default()`.
    let store = SqliteStore::new("example.db", None)?;

    // Add 10 entries.
    for i in 1..11u8 {
        let entry = Entry::new_with_timestamp(i as i64, Atom::from("sqlite_example"), vec![i]);
        store.push(Cow::Owned(entry))?;
    }

    // Queries are done via `range`. Here we grab entries with any timestamp and any name.
    let range = store.range(.., Option::<String>::None)?;
    // Count the number of entries.
    println!("initial count: {}", range.count()?);
    // We can also iterate on the entries.
    for entry in range.iter()? {
        println!("entry: {:?}", entry?);
    }

    // Remove the entries with 4 <= ts <= 6 and with the name `sqlite_example`.
    store.range(4..=6, Some(Atom::from("sqlite_example")))?.remove()?;

    // Now get the range of entries with 5 <= ts and with the name `sqlite_example`.
    let range = store.range(5.., Some(Atom::from("sqlite_example")))?;
    println!("count after range deletion: {}", range.count()?);
    for entry in range.iter()? {
        println!("entry: {:?}", entry?);
    }

    Ok(())
}

Python中

一个小例子

from binlog import binlog
store = binlog.SqliteStore("example.db")
store.push(binlog.Entry(1, "pytest_push", [1, 2, 3]))

存储

存储实现Store特质,以及零个或多个可选扩展,具体取决于它们支持的功能。一些存储实现内置于binlog

内存只读

内存只读存储没有持久化手段,但提供了完整的日志功能。这还用于对其他实现进行模糊测试。

Redis

Redis实现可以通过redis-store功能启用。底层使用Redis流。它支持订阅,但不支持范围。

Sqlite

Sqlite实现可以通过sqlite-store功能启用。它支持范围,但不支持订阅。

测试

单元测试

可以通过make test运行测试。这也会在CI中运行。

基准测试

可以通过make bench运行基准测试。

模糊测试

有一个模糊测试工具,确保sqlite和内存数据存储操作相同。通过make fuzz运行它。

检查

可以通过make check运行代码检查和格式化检查。CI中也会运行等效检查。

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码发行版

binlog-0.5.0.tar.gz (34.6 kB 查看哈希值)

上传时间 源代码

构建发行版

binlog-0.5.0-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.whl (2.5 MB 查看哈希值)

上传时间 PyPy manylinux: glibc 2.5+ x86-64

binlog-0.5.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.whl (2.5 MB 查看哈希值)

上传时间 CPython 3.10 manylinux: glibc 2.5+ x86-64

binlog-0.5.0-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (2.0 MB 查看哈希值)

上传时间 CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

binlog-0.5.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl (2.5 MB 查看哈希值)

上传时间 CPython 3.9 manylinux: glibc 2.5+ x86-64

binlog-0.5.0-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (2.0 MB 查看哈希值)

上传时间 CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

binlog-0.5.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl (2.5 MB 查看哈希值)

上传时间 CPython 3.8 manylinux: glibc 2.5+ x86-64

binlog-0.5.0-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (2.0 MB 查看哈希值)

上传于 CPython 3.8 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

binlog-0.5.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (2.5 MB 查看哈希值)

上传于 CPython 3.7m manylinux: glibc 2.5+ x86-64

binlog-0.5.0-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (2.0 MB 查看哈希值)

上传于 CPython 3.7m macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

支持者