This commit is contained in:
root 2025-07-10 20:54:35 +08:00
parent a5381e5305
commit 855a3bc757
1 changed files with 9 additions and 8 deletions

View File

@ -7,7 +7,7 @@
import { CloudflareKVClient, cloudflareKV } from './cloudflareKV' import { CloudflareKVClient, cloudflareKV } from './cloudflareKV'
// Example 1: Using the default instance // Example 1: Using the default instance
export async function basicUsageExample() { async function basicUsageExample() {
try { try {
// Store a simple string value // Store a simple string value
await cloudflareKV.put('user:123', 'John Doe') await cloudflareKV.put('user:123', 'John Doe')
@ -47,7 +47,7 @@ export async function basicUsageExample() {
} }
// Example 2: Using a custom configuration // Example 2: Using a custom configuration
export async function customConfigExample() { async function customConfigExample() {
const customKV = new CloudflareKVClient({ const customKV = new CloudflareKVClient({
// You can override any configuration values // You can override any configuration values
apiKey: 'your-custom-api-key', apiKey: 'your-custom-api-key',
@ -64,7 +64,7 @@ export async function customConfigExample() {
} }
// Example 3: Batch operations // Example 3: Batch operations
export async function batchOperationsExample() { async function batchOperationsExample() {
try { try {
// Store multiple values at once // Store multiple values at once
const entries = [ const entries = [
@ -88,7 +88,7 @@ export async function batchOperationsExample() {
} }
// Example 4: Working with metadata // Example 4: Working with metadata
export async function metadataExample() { async function metadataExample() {
try { try {
const value = { content: 'Important data' } const value = { content: 'Important data' }
const metadata = { const metadata = {
@ -109,7 +109,7 @@ export async function metadataExample() {
} }
// Example 5: Error handling and edge cases // Example 5: Error handling and edge cases
export async function errorHandlingExample() { async function errorHandlingExample() {
try { try {
// Try to get a non-existent key // Try to get a non-existent key
const nonExistent = await cloudflareKV.get('does-not-exist') const nonExistent = await cloudflareKV.get('does-not-exist')
@ -134,7 +134,7 @@ export async function errorHandlingExample() {
} }
// Example 6: Video template storage use case // Example 6: Video template storage use case
export async function videoTemplateStorageExample() { async function videoTemplateStorageExample() {
try { try {
const templateData = { const templateData = {
id: 'template-001', id: 'template-001',
@ -182,7 +182,7 @@ export async function videoTemplateStorageExample() {
} }
// Run all examples // Run all examples
export async function runAllExamples() { async function runAllExamples() {
console.log('🚀 Running Cloudflare KV Examples...\n') console.log('🚀 Running Cloudflare KV Examples...\n')
console.log('1. Basic Usage Example:') console.log('1. Basic Usage Example:')
@ -219,5 +219,6 @@ export {
batchOperationsExample, batchOperationsExample,
metadataExample, metadataExample,
errorHandlingExample, errorHandlingExample,
videoTemplateStorageExample videoTemplateStorageExample,
runAllExamples
} }