wip: oci
This commit is contained in:
66
example/redis-cache/k8s/test-configmap.yaml
Normal file
66
example/redis-cache/k8s/test-configmap.yaml
Normal file
@@ -0,0 +1,66 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: test-script
|
||||
namespace: redis-demo
|
||||
data:
|
||||
test.sh: |
|
||||
#!/bin/sh
|
||||
|
||||
echo "=== Redis Cache Demo Test ==="
|
||||
echo "Testing Redis connectivity..."
|
||||
|
||||
# 测试 Redis 连接
|
||||
redis-cli -h redis-headless.redis-demo.svc.cluster.local ping
|
||||
|
||||
echo ""
|
||||
echo "Testing basic cache operations..."
|
||||
|
||||
# 设置值
|
||||
redis-cli -h redis-headless.redis-demo.svc.cluster.local set test-key "hello-world"
|
||||
echo "SET test-key 'hello-world'"
|
||||
|
||||
# 获取值
|
||||
VALUE=$(redis-cli -h redis-headless.redis-demo.svc.cluster.local get test-key)
|
||||
echo "GET test-key: $VALUE"
|
||||
|
||||
# 设置 Hash
|
||||
redis-cli -h redis-headless.redis-demo.svc.cluster.local hset user:1 name "张三"
|
||||
redis-cli -h redis-headless.redis-demo.svc.cluster.local hset user:1 age "25"
|
||||
echo "HSET user:1 name '张三', age '25'"
|
||||
|
||||
# 获取 Hash
|
||||
NAME=$(redis-cli -h redis-headless.redis-demo.svc.cluster.local hget user:1 name)
|
||||
AGE=$(redis-cli -h redis-headless.redis-demo.svc.cluster.local hget user:1 age)
|
||||
echo "HGET user:1 name: $NAME, age: $AGE"
|
||||
|
||||
# 获取所有 Hash 字段
|
||||
ALL_HASH=$(redis-cli -h redis-headless.redis-demo.svc.cluster.local hgetall user:1)
|
||||
echo "HGETALL user:1: $ALL_HASH"
|
||||
|
||||
# 计数器测试
|
||||
redis-cli -h redis-headless.redis-demo.svc.cluster.local set counter 0
|
||||
COUNTER1=$(redis-cli -h redis-headless.redis-demo.svc.cluster.local incr counter)
|
||||
COUNTER2=$(redis-cli -h redis-headless.redis-demo.svc.cluster.local incrby counter 5)
|
||||
echo "COUNTER: initial=0, +1=$COUNTER1, +5=$COUNTER2"
|
||||
|
||||
# 测试过期
|
||||
redis-cli -h redis-headless.redis-demo.svc.cluster.local set expire-key "will-expire" EX 5
|
||||
echo "SET expire-key 'will-expire' with TTL 5s"
|
||||
sleep 2
|
||||
EXPIRED=$(redis-cli -h redis-headless.redis-demo.svc.cluster.local get expire-key)
|
||||
echo "GET expire-key after 2s: $EXPIRED"
|
||||
|
||||
sleep 4
|
||||
EXPIRED2=$(redis-cli -h redis-headless.redis-demo.svc.cluster.local get expire-key)
|
||||
echo "GET expire-key after 6s: $EXPIRED2 (should be nil)"
|
||||
|
||||
echo ""
|
||||
echo "=== Test Summary ==="
|
||||
echo "✅ Basic SET/GET operations"
|
||||
echo "✅ Hash operations (HSET/HGET/HGETALL)"
|
||||
echo "✅ Counter operations (INCR/INCRBY)"
|
||||
echo "✅ TTL operations"
|
||||
echo "✅ Redis cluster connectivity"
|
||||
echo ""
|
||||
echo "All tests completed successfully!"
|
||||
Reference in New Issue
Block a user