Skip to content

Commit afd8373

Browse files
committed
feat: initial commit
0 parents  commit afd8373

25 files changed

+3787
-0
lines changed

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.github/workflows/ci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
env:
9+
CARGO_TERM_COLOR: always
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
submodules: recursive
18+
19+
- uses: dtolnay/rust-toolchain@stable
20+
with:
21+
components: clippy, rustfmt
22+
23+
- uses: Swatinem/rust-cache@v2
24+
25+
- run: cargo fmt --all -- --check
26+
- run: cargo clippy --all-targets -- -D warnings
27+
- run: cargo test --all

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/target
2+
.direnv/
3+
.DS_Store
4+
.idea/
5+
result

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "librdb-sys/librdb"]
2+
path = librdb-sys/librdb
3+
url = https://github.com/redis/librdb.git

.pre-commit-config.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
repos:
2+
- repo: local
3+
hooks:
4+
- id: cargo-fmt
5+
name: cargo fmt
6+
entry: cargo fmt --all --
7+
language: system
8+
pass_filenames: false
9+
10+
- id: cargo-clippy
11+
name: cargo clippy
12+
entry: cargo clippy --all-targets --all-features -- -D warnings
13+
language: system
14+
pass_filenames: false
15+
16+
- id: cargo-test
17+
name: cargo test
18+
entry: cargo test --all
19+
language: system
20+
pass_filenames: false

Cargo.lock

Lines changed: 95 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[workspace]
2+
members = ["librdb-sys", "librdb"]
3+
resolver = "2"
4+
5+
[workspace.lints.rust]
6+
unsafe_code = "deny"
7+
unused_results = "warn"
8+
9+
[workspace.lints.clippy]
10+
pedantic = { level = "warn", priority = -1 }
11+
nursery = { level = "warn", priority = -1 }

README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# rust-librdb
2+
3+
Rust wrapper for [librdb](https://github.com/redis/librdb), the Redis RDB file parser.
4+
5+
Parses RDB dump files and delivers Redis data types (strings, lists, hashes,
6+
sets, sorted sets, streams) through a callback trait, without loading the
7+
entire file into memory.
8+
9+
| Crate | Description |
10+
|-------|-------------|
11+
| [`librdb`](librdb/) | Safe, high-level wrapper |
12+
| [`librdb-sys`](librdb-sys/) | Raw FFI bindings |
13+
14+
## Installation
15+
16+
```toml
17+
[dependencies]
18+
librdb = "0.1"
19+
```
20+
21+
By default, librdb is compiled from the vendored source (git submodule).
22+
A C compiler is required.
23+
24+
```sh
25+
git clone --recurse-submodules https://github.com/funcpp/rust-librdb
26+
cd rust-librdb
27+
cargo build
28+
```
29+
30+
### Linking options
31+
32+
| Method | How |
33+
|--------|-----|
34+
| Source build (default) | No extra steps |
35+
| System shared library | `--features librdb-sys/dynamic-linking` |
36+
| Pre-built static library | Set `DEP_LIBRDB_STATIC_ROOT`, use `--features librdb-sys/static-linking` |
37+
38+
## Example
39+
40+
```rust
41+
use librdb::{Parser, RdbHandlers, KeyInfo, Result};
42+
43+
struct MyHandler {
44+
keys: Vec<String>,
45+
}
46+
47+
impl RdbHandlers for MyHandler {
48+
fn handle_new_key(&mut self, key: &[u8], _info: &KeyInfo) -> Result<()> {
49+
self.keys.push(String::from_utf8_lossy(key).into_owned());
50+
Ok(())
51+
}
52+
}
53+
54+
fn main() -> librdb::Result<()> {
55+
let mut parser = Parser::new(MyHandler { keys: vec![] })?;
56+
parser.parse_file("dump.rdb")?;
57+
let handler = parser.into_handler();
58+
println!("{} keys parsed", handler.keys.len());
59+
Ok(())
60+
}
61+
```
62+
63+
`&[u8]` callback parameters borrow directly from librdb's internal buffer and
64+
are only valid for the duration of the callback. Clone if you need to retain
65+
the data.
66+
67+
## License
68+
69+
MIT

flake.lock

Lines changed: 96 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
inputs = {
3+
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
4+
rust-overlay.url = "github:oxalica/rust-overlay";
5+
flake-utils.url = "github:numtide/flake-utils";
6+
};
7+
8+
outputs = { self, nixpkgs, rust-overlay, flake-utils }:
9+
flake-utils.lib.eachDefaultSystem (system:
10+
let
11+
pkgs = import nixpkgs {
12+
inherit system;
13+
overlays = [ rust-overlay.overlays.default ];
14+
};
15+
rust = pkgs.rust-bin.stable.latest.default.override {
16+
extensions = [ "rust-src" "rust-analyzer" "clippy" "rustfmt" ];
17+
};
18+
in {
19+
devShells.default = pkgs.mkShell {
20+
buildInputs = with pkgs; [
21+
rust
22+
cargo-edit
23+
cargo-watch
24+
clang
25+
libclang
26+
pkg-config
27+
pre-commit
28+
cmake
29+
gnumake
30+
];
31+
32+
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
33+
};
34+
});
35+
}

0 commit comments

Comments
 (0)