String Operations
DBX provides a complete set of string operations through its REST API. These operations allow you to store, retrieve, and manage string values with optional TTL (Time To Live) support.
Overview
String operations are the most basic data type in DBX, supporting simple key-value storage with additional features like expiration and existence checks.
Endpoints
GET /redis/string/{key}
Retrieve a string value by key.
Parameters:key
(path) - The key to retrieve
{
"value": "Hello, World!",
"ttl": 3600
}
curl http://localhost:8080/redis/string/my-key
404 Not Found
- Key doesn't exist400 Bad Request
- Invalid key format
POST /redis/string/{key}
Create or update a string value.
Parameters:key
(path) - The key to storevalue
(body) - The string value to storettl
(optional, body) - Time to live in seconds
{
"value": "Hello, World!",
"ttl": 3600
}
{
"success": true,
"key": "my-key"
}
curl -X POST http://localhost:8080/redis/string/my-key \
-H "Content-Type: application/json" \
-d '{"value": "Hello, World!", "ttl": 3600}'
DELETE /redis/string/{key}
Delete a string value by key.
Parameters:key
(path) - The key to delete
{
"success": true,
"deleted": true
}
curl -X DELETE http://localhost:8080/redis/string/my-key
GET /redis/string/{key}
/exists
Check if a key exists.
Parameters:key
(path) - The key to check
{
"exists": true
}
curl http://localhost:8080/redis/string/my-key/exists
GET /redis/string/{key}
/ttl
Get the remaining TTL for a key.
Parameters:key
(path) - The key to check
{
"ttl": 1800
}
curl http://localhost:8080/redis/string/my-key/ttl
POST /redis/string/{key}
/expire
Set or update the TTL for a key.
Parameters:key
(path) - The key to updatettl
(body) - New TTL in seconds
{
"ttl": 7200
}
{
"success": true,
"ttl": 7200
}
curl -X POST http://localhost:8080/redis/string/my-key/expire \
-H "Content-Type: application/json" \
-d '{"ttl": 7200}'
Batch Operations
POST /redis/string/batch
Perform multiple string operations in a single request.
Request Body:{
"operations": [
{
"type": "set",
"key": "key1",
"value": "value1",
"ttl": 3600
},
{
"type": "get",
"key": "key2"
},
{
"type": "delete",
"key": "key3"
}
]
}
{
"results": [
{
"type": "set",
"success": true,
"key": "key1"
},
{
"type": "get",
"success": true,
"value": "value2"
},
{
"type": "delete",
"success": true,
"deleted": true
}
]
}
Use Cases
1. Simple Caching
# Store a cached value
curl -X POST http://localhost:8080/redis/string/cache:user:123 \
-H "Content-Type: application/json" \
-d '{"value": "{\"name\":\"John\",\"email\":\"john@example.com\"}", "ttl": 300}'
# Retrieve cached value
curl http://localhost:8080/redis/string/cache:user:123
2. Session Storage
# Store session data
curl -X POST http://localhost:8080/redis/string/session:abc123 \
-H "Content-Type: application/json" \
-d '{"value": "{\"user_id\":123,\"permissions\":[\"read\",\"write\"]}", "ttl": 3600}'
# Check session exists
curl http://localhost:8080/redis/string/session:abc123/exists
3. Rate Limiting
# Track API calls
curl -X POST http://localhost:8080/redis/string/rate:ip:192.168.1.1 \
-H "Content-Type: application/json" \
-d '{"value": "10", "ttl": 60}'
# Check remaining calls
curl http://localhost:8080/redis/string/rate:ip:192.168.1.1
Error Handling
All endpoints return consistent error responses:
{
"error": "not_found",
"message": "Key 'my-key' not found",
"status": 404
}
Common error types:
not_found
- Key doesn't existinvalid_key
- Key format is invalidinvalid_value
- Value format is invalidinvalid_ttl
- TTL value is invalidserver_error
- Internal server error
Performance Considerations
- Key Naming - Use descriptive, hierarchical keys (e.g.,
user:123:profile
) - TTL Management - Set appropriate TTL values to prevent memory bloat
- Batch Operations - Use batch endpoints for multiple operations
- Connection Pooling - Reuse HTTP connections for better performance
Rate Limits
String operations are subject to the same rate limiting as other API endpoints:
- Default: 100 requests per minute per IP
- Configurable via environment variables