Crates.io | commitlog |
lib.rs | commitlog |
version | 0.2.0 |
source | src |
created_at | 2016-11-26 01:19:59.729109 |
updated_at | 2021-11-06 18:28:29.44899 |
description | Sequential, disk-backed commit log library. |
homepage | https://github.com/zowens/commitlog |
repository | https://github.com/zowens/commitlog |
max_upload_size | |
id | 7364 |
size | 133,148 |
Sequential, disk-backed commit log library for Rust. The library can be used in various higher-level distributed abstractions on top of a distributed log such as Paxos, Chain Replication or Raft.
First, add this to your Cargo.toml
:
[dependencies]
commitlog = "0.1"
extern crate commitlog;
use commitlog::*;
fn main() {
// open a directory called 'log' for segment and index storage
let opts = LogOptions::new("log");
let mut log = CommitLog::new(opts).unwrap();
// append to the log
log.append("hello world").unwrap(); // offset 0
log.append("second message").unwrap(); // offset 1
// read the messages
let messages = log.read(0, ReadLimit::default()).unwrap();
for msg in messages.iter() {
println!("{} - {}", msg.offset(), String::from_utf8_lossy(msg.payload()));
}
// prints:
// 0 - hello world
// 1 - second message
}