spacejam /sled

the champagne of beta embedded databases

★ 9,112⑂ 428👁 123⑃ 933● 605▤ 22
RustApache-2.0Created 2016-01-11
下载:0.34.70.34.7 ↓0.34.72021-09-12
+0
日增长
9,112
stars
428
forks
123
watchers
933
prs
605
issues
22
releases

README

key 
         value 
      
      
        documentation
        
      
      
        chat about databases with us
        
      
     
  
  

  
  
  
 



 sled - ~~it's all downhill from here!!!~~

An embedded database.

rust
let tree = sled::open("/tmp/welcome-to-sled")?;

// insert and get, similar to std's BTreeMap
let old_value = tree.insert("key", "value")?;

assert_eq!(
  tree.get(&"key")?,
  Some(sled::IVec::from("value")),
);

// range queries
for kv_result in tree.range("key_1".."key_9") {}

// deletion
let old_value = tree.remove(&"key")?;

// atomic compare and swap
tree.compare_and_swap(
  "key",
  Some("current_value"),
  Some("new_value"),
)?;

// block until all operations are stable on disk
// (flush_async also available to get a Future)
tree.flush()?;


$${\color{red}This \space README \space is \space out \space of \space sync \space with \space the \space main \space branch \space which \space contains \space a \space large \space in-progress \space rewrite }$$

If you would like to work with structured data without paying expensive deserialization costs, check out the structured example!

 features

 API similar to a threadsafe BTreeMap
 serializable (ACID) transactions
  for atomically reading and writing to multiple keys in multiple keyspaces.
 fully atomic single-key operations, including compare and swap
 zero-copy reads
 write batches
 subscribe to changes on key
  prefixes
 multiple keyspaces
 merge operators
 forward and reverse iterators over ranges of items
 a crash-safe monotonic ID generator
  capable of generating 75-125 million unique ID's per second
 zstd compression (use the
  compression build feature, disabled by default)
 cpu-scalable lock-free implementation
 flash-optimized log-structured storage
 uses modern b-tree techniques such as prefix encoding and suffix
  truncation for reducing the storage costs of long keys with shared
  prefixes. If keys are the same length and sequential then the
  system can avoid storing 99%+ of the key data in most cases,
  essentially acting like a learned index

 expectations, gotchas, advice

 Maybe one of the first things that seems weird is the IVec type.
  This is an inlinable Arced slice that makes some things more efficient.
 Durability: sled automatically fsyncs every 500ms by default,
  which can be configured with the flush_every_ms configurable, or you may
  call flush / flush_async manually after operations.
 Transactions are optimistic - do not interact with external state
  or perform IO from within a transaction closure unless it is
  idempotent.
 Internal tree node optimizations: sled performs prefix encoding
  on long keys with similar prefixes that are grouped together in a range,
  as well as suffix truncation to further reduce the indexing costs of
  long keys. Nodes will skip potentially expensive length and offset pointers
  if keys or values are all the same length (tracked separately, don't worry
  about making keys the same length as values), s

Top issues

Latest release

0.34.7 v0.34.7 2021-09-12
Bug Fixes

 1314 Fix a bug in Subscriber's Future impl.

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON