Cache
The Peak SDK provides a CLI for interacting with the cache service. The cache CLI allows you to perform various operations such as setting, getting, and deleting cache keys.
Basic Operations
Setting a cache key
To set a cache key with a value:
peak cache set --key "my-key" --value "my-value"
You can also set a key with a TTL (time-to-live) in seconds:
peak cache set --key "my-key" --value "my-value" --ttl 3600
Getting a cache key
To retrieve a value from the cache:
peak cache get --key "my-key"
Deleting cache keys
To delete one or more cache keys:
peak cache delete --keys "key1,key2,key3"
Checking if keys exist
To check if keys exist in the cache:
peak cache exists --keys "key1,key2,key3"
Bulk Operations
Setting multiple keys at once
To set multiple key-value pairs using a JSON mapping:
peak cache mset --mapping '{"key1": "value1", "key2": "value2", "key3": "value3"}'
Getting multiple keys at once
To retrieve multiple keys:
peak cache mget --keys "key1,key2,key3"
Cache Management
Flushing keys by pattern
To flush all keys matching a pattern:
peak cache flush --pattern "user:*"
Flushing all tenant keys
To flush all keys for the current tenant:
peak cache flush --all
Testing connection
To test the cache connection:
peak cache ping
TTL Operations
Setting expiration for a key
To set an expiration time for an existing key:
peak cache expire --key "my-key" --ttl 3600
Getting TTL for a key
To check the remaining time-to-live for a key:
peak cache ttl --key "my-key"
Advanced Usage
Using additional prefixes
You can set additional prefixes for your cache keys:
peak cache set --key "my-key" --value "my-value" --prefix "app-name"
JSON data handling
The cache automatically handles JSON serialization and deserialization. You can store complex data structures:
peak cache set --key "user-data" --value '{"name": "John", "age": 30, "active": true}'
When retrieving the data, it will be automatically deserialized back to its original format.