Skip to main content

Redis

How to run Redis in CGC from the official image, how to give it a password, how to keep its data and how to reach it from inside your namespace.

Redis is listed by cgc db create --help, but it cannot be created that way: the licence does not allow CGC to serve it as a single click app. cgc db create redis stops with a message pointing you to a custom image and creates nothing. Run Redis yourself with cgc compute create custom.

How to run it

The official image starts without any password and with appendonly set to no, so pass a startup command that sets a password and turns the append-only file on. cgc compute create reads the startup command from standard input:

cgc volume create -s 5 -sc <storage_class> redis01-vol
echo 'redis-server --requirepass <your_password> --dir /data --appendonly yes' | cgc compute create custom -n redis01 -c 1 -m 2 --image redis:7 -v redis01-vol -fp /data

The server listens on port 6379. --dir /data points Redis at the mounted volume and --appendonly yes turns on the append-only file, so the data survives both cgc resource restart redis01 and deleting the app and creating it again with the same volume and the same startup command. cgc compute delete removes the app together with its service, so after recreating it you have to add the port again.

Always mount that volume and keep --dir pointing at it. Started without -v, Redis keeps its data on the pod's ephemeral disk and it is lost on every restart, not only when you delete the app: after cgc resource restart redis01 such an instance comes back with DBSIZE at 0.

Default configuration

  • The container runs exactly the command you pass on standard input. With no startup command the image runs plain redis-server *:6379: requirepass is empty and redis-cli PING answers PONG without any password, so every client in the namespace gets in.
  • The defaults of that server are dir /data, appendonly no and save 3600 1 300 100 60 10000. Without --appendonly yes only those periodic snapshots reach the volume, so the most recent writes can still be lost.
  • JUPYTER_PORT=8888 and JUPYTER_TOKEN: CGC adds these two variables to every custom app. Redis ignores them.
info

The startup command must not contain the | character: the client removes every | from it before sending, and what followed the pipe is handed to redis-server as extra arguments, which stops it with FATAL CONFIG FILE ERROR. The -ce app_token= flag sets the CGC app token of the app, the value shown in cgc compute list -d, not the Redis password: Redis keeps answering WRONGPASS to the app token and takes only the password from --requirepass.

How to connect

A custom app has no service until you publish a port, and until then its name does not resolve inside the namespace. Add the Redis port first:

cgc compute port add redis01 -p 6379 -n redis

The app is then reachable from any other app in your namespace as redis01:6379:

redis-cli -h redis01 -p 6379 -a <your_password> PING

The command answers PONG. Without -a Redis answers NOAUTH Authentication required.

caution

Adding a port also registers a public ingress address for it, and in CLI 1.5.1 the -ni/--no-ingress flag does not prevent that: the port is still listed with ingress True. Always start Redis with --requirepass, and check the result with cgc compute port list redis01.