| name | redis-strings |
| description | Master Redis Strings - SET, GET, INCR, DECR, atomic counters, binary-safe operations, and caching patterns |
| sasmp_version | 1.3.0 |
| bonded_agent | 02-redis-data-structures |
| bond_type | PRIMARY_BOND |
| version | 2.1.0 |
| last_updated | 2025-01 |
| parameters | {"key":{"type":"string","required":true,"pattern":"^[a-zA-Z0-9:_-]+$","max_length":512},"value":{"type":"string","required":true,"max_size":"512MB"},"ttl_seconds":{"type":"integer","required":false,"min":1,"max":31536000},"nx_xx":{"type":"string","required":false,"enum":["NX","XX"],"description":"NX=only if not exists, XX=only if exists"}} |
| retry_config | {"max_retries":3,"backoff_strategy":"exponential","backoff_base_ms":100,"retryable_errors":["connection_timeout","BUSY"]} |
| observability | {"logging":{"level":"debug","include_key_pattern":true},"metrics":["operation_latency_ms","cache_hit_ratio","key_size_bytes"]} |
| validation | {"key_naming":{"pattern":"object:id:field","examples":["user:123:profile","cache:api:users"]},"value_limits":{"warn_size_kb":100,"max_size_kb":10240}} |
Redis Strings Skill
Overview
Production-grade String operations for Redis. Master atomic counters, caching patterns, and binary-safe string manipulation.
Core Commands
Basic Operations
SET key value [EX seconds] [PX milliseconds] [NX|XX] [KEEPTTL]
GET key
GETEX key [EX seconds|PX ms|EXAT ts|PXAT ts|PERSIST] # Get + set TTL
DEL key [key ...]
EXISTS key [key ...]
Atomic Counters
INCR key # +1 (creates if missing, starts at 0)
DECR key # -1
INCRBY key increment # +N
DECRBY key decrement # -N
INCRBYFLOAT key increment # Float increment
String Manipulation
APPEND key value # Append to value
STRLEN key # Get length
GETRANGE key start end # Substring (0-indexed, inclusive)
SETRANGE key offset value # Replace from offset
Batch Operations
MSET key value [key value ...] # Set multiple
MGET key [key ...] # Get multiple
MSETNX key value [key value ...] # Set multiple if none exist
Advanced Options (Redis 6.2+)
SET key value GET # Set and return old value
SET key value IFEQ oldvalue # Set if current equals (Redis 7.4+)
GETDEL key # Get and delete
SETEX key seconds value # Set with TTL (deprecated, use SET EX)
Production Patterns
Pattern 1: Cache with TTL
# Set with 1-hour TTL
SET cache:user:123 '{"name":"John","email":"john@example.com"}' EX 3600
# Get (returns nil if expired)
GET cache:user:123
# Refresh TTL on access
GETEX cache:user:123 EX 3600
Pattern 2: Rate Limiter (Fixed Window)
# Increment counter, set TTL on first request
INCR ratelimit:user:123:minute
EXPIRE ratelimit:user:123:minute 60 NX
# Check count
GET ratelimit:user:123:minute
Pattern 3: Distributed Lock
# Acquire lock (NX = only if not exists)
SET lock:resource:123 "holder-uuid" NX EX 30
# Release lock (only if we own it) - use Lua
EVAL "if redis.call('get',KEYS[1])==ARGV[1] then return redis.call('del',KEYS[1]) else return 0 end" 1 lock:resource:123 "holder-uuid"
Pattern 4: Session Storage
# Create session
SET session:abc123 '{"user_id":1,"created":1704067200}' EX 86400
# Touch session (reset TTL)
GETEX session:abc123 EX 86400
# Invalidate session
DEL session:abc123