Get started with FoundationDB in your preferred language.
pip install foundationdbgo get github.com/apple/foundationdb/bindings/goAdd to pom.xml:
<dependency>
<groupId>com.apple</groupId>
<artifactId>foundationdb</artifactId>
<version>7.4.5</version>
</dependency>gem install fdbDownload client libraries from FoundationDB releases
import fdb
# Select API version (required first)
fdb.api_version(740)
# Open database connection
db = fdb.open()
# Use transactional decorator for automatic retry
@fdb.transactional
def set_value(tr, key, value):
tr[key] = value
result = tr[key] # Read within same transaction
return result
# Execute transaction
result = set_value(db, b'hello', b'world')
print(result) # b'world'
# Manual transaction with range read
tr = db.create_transaction()
try:
# Write operations
tr[b'key1'] = b'value1'
tr[b'key2'] = b'value2'
# Range read
for key, value in tr[b'key1':b'key3']:
print(f"{key}: {value}")
# Commit
tr.commit().wait()
except fdb.FDBError as e:
print(f"Error: {e.description}")package main
import (
"fmt"
"github.com/apple/foundationdb/bindings/go/src/fdb"
)
func main() {
// Select API version (required first)
fdb.MustAPIVersion(740)
// Open database
db := fdb.MustOpenDefault()
// Use Transact for automatic retry
result, err := db.Transact(func(tr fdb.Transaction) (interface{}, error) {
tr.Set(fdb.Key("hello"), []byte("world"))
return tr.Get(fdb.Key("hello")).MustGet(), nil
})
if err != nil {
panic(err)
}
fmt.Println(string(result.([]byte))) // "world"
}import com.apple.foundationdb.*;
public class Example {
public static void main(String[] args) {
// Select API version (required first)
FDB fdb = FDB.selectAPIVersion(740);
// Open database
try (Database db = fdb.open()) {
// Use run() for automatic retry
String result = db.run(tr -> {
tr.set("hello".getBytes(), "world".getBytes());
return new String(tr.get("hello".getBytes()).join());
});
System.out.println(result); // "world"
}
}
}Required first step - Must select API version before any other operation:
fdb.api_version(740)fdb.MustAPIVersion(740)FDB.selectAPIVersion(740)All operations must occur within transactions:
Read operations return Future objects:
.wait() to block.MustGet() or .Get().join() or .get()FoundationDB uses error codes:
1007 (timeout), 1020 (conflict), 1021 (unknown result)