CoolFace
Apppublic

minhtudragon/redis_hf

sourceHugging Faceupdated 4mo agoView on Hugging Face
0likes
App README

hf-redis-rest

Self-hosted, Upstash-compatible Redis REST server that runs as a Hugging Face Docker Space. Drop-in replacement for Upstash Redis REST — change two env vars and your app keeps working.

Not for production. Data is ephemeral. Use for cache, rate limiting, dev/staging.

What It Does

  • —Runs Redis + a REST API inside a single Docker container
  • —Accepts Upstash-style JSON Redis commands over HTTPS
  • —Bearer-token authentication
  • —Pipeline support
  • —Health check endpoint

What It Does Not Do

  • —No data persistence across Space restarts/rebuilds
  • —No Redis Cluster
  • —No multi-tenant databases
  • —No raw TCP access
  • —No full Upstash feature parity
  • —Not a replacement for managed Redis in production

Quick Start

Deploy to Hugging Face Spaces

  1. 1.Create a new Docker Space on Hugging Face
  2. 2.Push this repo to the Space
  3. 3.Set the Space secret: REDIS_REST_TOKEN=your-secret-token
  4. 4.Wait for the build to complete

Configure Your App

Change your environment variables:

env
REDIS_URL="https://<your-hf-username>-<space-name>.hf.space"
REDIS_REST_TOKEN="your-secret-token"

That's it. No code changes needed.

Environment Variables

Your App (client side)

VariableDescription
REDIS_URLPublic HTTPS URL of your HF Space
REDIS_REST_TOKENBearer token matching the Space secret

Hugging Face Space Secrets

VariableDescription
REDIS_REST_TOKENAuthentication token (required)
API_TOKENAlternative name for the auth token
INTERNAL_REDIS_URLRedis connection URL (default: redis://127.0.0.1:6379)
REDIS_PERSISTENCESet to aof to enable append-only file persistence
MAX_BODY_SIZEMax request body in bytes (default: 5242880 = 5MB)
PORTREST server port (default: 7860)

Optional Persistence

Set REDIS_PERSISTENCE=aof in your Space secrets to enable AOF persistence. Warning: free HF Space disk is not guaranteed persistent across rebuilds/restarts. Do not rely on this for data durability.

Testing with curl

Health Check (no auth needed)

bash
curl https://<space>.hf.space/health

Expected:

json
{"status":"ok","redis":"connected"}

SET / GET

bash
curl -X POST "https://<space>.hf.space" \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '["SET","hello","world"]'
bash
curl -X POST "https://<space>.hf.space" \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '["GET","hello"]'

Pipeline

bash
curl -X POST "https://<space>.hf.space/pipeline" \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '[["SET","a","1"],["GET","a"]]'

Path-Style (optional)

bash
curl "https://<space>.hf.space/get/hello"
curl "https://<space>.hf.space/set/key/value"
curl "https://<space>.hf.space/del/key"

Note: path-style commands also require auth if REDIS_REST_TOKEN is set.

Supported Redis Commands

Phase 1 (fully supported)

GET SET DEL EXISTS EXPIRE TTL INCR DECR MGET MSET HGET HSET HDEL HGETALL LPUSH RPUSH LPOP RPOP LRANGE SADD SREM SMEMBERS ZADD ZREM ZRANGE PING

Phase 2 (supported)

SCAN KEYS FLUSHDB SETEX PSETEX GETDEL GETEX ZCARD ZSCORE ZREVRANGE XADD XREAD

Phase 3 (supported)

SETNX GETSET APPEND STRLEN INCRBY DECRBY EXPIREAT PEXPIRE PTTL PERSIST RENAME TYPE LINDEX LLEN LREM LTRIM HEXISTS HINCRBY HKEYS HVALS HLEN HMGET HMSET SISMEMBER SCARD SDIFF SINTER SUNION ZRANK ZCOUNT ZREMRANGEBYRANK ZREMRANGEBYSCORE SRANDMEMBER SPOP

Blocked Commands

FLUSHALL CONFIG SHUTDOWN SAVE BGSAVE CLIENT MONITOR DEBUG CLUSTER REPLICAOF SLAVEOF REPLCONF PFDEBUG

Local Development

bash
docker build -t hf-redis-rest .
docker run -p 7860:7860 -e REDIS_REST_TOKEN=test-token hf-redis-rest

Test:

bash
curl -X POST http://localhost:7860 \
  -H "Authorization: Bearer test-token" \
  -H "Content-Type: application/json" \
  -d '["PING"]'

Troubleshooting

ProblemSolution
401 UnauthorizedCheck that REDIS_REST_TOKEN matches between app and Space
Space shows "runtime error"Check Space logs; ensure Dockerfile built correctly
Redis disconnected in /healthRedis may have crashed; check logs for memory issues
Commands return errorsEnsure you're sending a JSON array: ["GET","key"]
Data disappearedNormal — HF Spaces are ephemeral. Don't store critical data.
Slow responsesFree tier has limited CPU. Not suitable for high throughput.

License

MIT