Fast, reliable storage for simple key-value pairs with B-tree indexing
The Key-Value Engine in ShibuDB provides fast, reliable storage for simple key-value pairs. It's built on top of a B-tree index for efficient lookups and includes Write-Ahead Logging (WAL) for data durability.
┌─────────────────────────────────────┐
│ Key-Value Space │
├─────────────────────────────────────┤
│ B-Tree Index (for fast lookups) │
├─────────────────────────────────────┤
│ In-Memory Buffer (for performance) │
├─────────────────────────────────────┤
│ Write-Ahead Log (for durability) │
├─────────────────────────────────────┤
│ Data Files (persistent storage) │
└─────────────────────────────────────┘
Key-value data is organized in spaces, which provide isolation and access control.
# Create a basic key-value space
CREATE-SPACE users --engine key-value
# Create with custom name
CREATE-SPACE product_catalog --engine key-value
Note: Only admin users can create spaces.
# List all available spaces
LIST-SPACES
Response:
{
"status": "OK",
"spaces": ["users", "product_catalog", "session_data"]
}
# Switch to a specific space
USE users
# Verify current space (prompt will show current space)
[users]>
# Delete a space (admin only)
DELETE-SPACE users
Warning: This permanently removes all data in the space.
Core key-value operations for storing, retrieving, and managing data.
# Store a simple value
PUT user:1 "John Doe"
# Store with complex key
PUT user:profile:123 "{\"name\":\"John\",\"age\":30}"
# Store multiple values
PUT user:2 "Jane Smith"
PUT user:3 "Bob Johnson"
# Get a single value
GET user:1
# Get multiple values
GET user:1 user:2 user:3
# Get with complex key
GET user:profile:123
# Delete a single key
DELETE user:1
# Delete multiple keys
DELETE user:2 user:3
# Delete with complex key
DELETE user:profile:123
# Check if key exists
EXISTS user:1
# Check multiple keys
EXISTS user:1 user:2 user:3
Advanced features for efficient data management and querying.
# Batch PUT operations
PUT user:1 "John Doe" user:2 "Jane Smith" user:3 "Bob Johnson"
# Batch GET operations
GET user:1 user:2 user:3 user:4 user:5
# Batch DELETE operations
DELETE user:1 user:2 user:3
# Get all user keys
GET user:*
# Get all profile keys
GET user:profile:*
# Get keys with specific pattern
GET user:profile:1*
Understanding the data types and formats supported by the key-value engine.
# String values
PUT name "John Doe"
PUT email "john@example.com"
# JSON data
PUT user:profile "{\"name\":\"John\",\"age\":30,\"city\":\"New York\"}"
# Numeric values (as strings)
PUT user:age "30"
PUT user:score "95.5"
# Complex nested data
PUT user:preferences "{\"theme\":\"dark\",\"notifications\":true,\"language\":\"en\"}"
Optimizing performance for key-value operations.
The key-value engine uses memory efficiently with:
Recommended practices for using the key-value engine effectively.
user:123:profile
Common use cases and practical examples.
# Create sessions space
CREATE-SPACE sessions --engine key-value
USE sessions
# Store session data
PUT session:abc123 "{\"user_id\":123,\"login_time\":\"2024-01-01T10:00:00Z\",\"expires\":\"2024-01-01T18:00:00Z\"}"
# Retrieve session
GET session:abc123
# Delete expired session
DELETE session:abc123
# Create config space
CREATE-SPACE config --engine key-value
USE config
# Store application settings
PUT app:theme "dark"
PUT app:language "en"
PUT app:notifications "true"
PUT app:timezone "UTC"
# Get all config
GET app:*
# Create features space
CREATE-SPACE features --engine key-value
USE features
# Store feature flags
PUT feature:new_ui "true"
PUT feature:beta_mode "false"
PUT feature:analytics "true"
# Check feature status
GET feature:new_ui