Monthly Archives: April 2023

Setting up Redis Stack on AWS Lightsail using Docker

I’ve been using Bitnami’s redis server on the default NodeJS instance on Lightsail but unfortunately, it’s not the full stack so it’s missing GEO, JSON and full text search support which is a bit of a bummer. So, to solve that problem I decided to see if I could setup Redis Stack using docker on a Lightsail instance. I decided not to use LS container support as I can get an 8GB instance for $40/month, vs. a similar container instance at $100/month.

Redis Stack Cloud on us-west-2 for 5GB of RAM runs $105/month (as of April ’23) without HA.

To start, I created a Debian OS only instance and installed docker:

Install Docker Engine on Debian

Start docker at boot:

$ sudo systemctl enable docker.service
$ sudo systemctl enable containerd.service

And install docker-compose:

$ sudo apt install docker-compose

Next, install both make and gcc to build redis-cli:

Debian Linux Install GNU GCC Compiler

Basically, use this:

$ sudo apt-get update
$ sudo apt-get install build-essential

Next, I wanted just redis-cli installed so here are the steps for building redis-cli:

Install just redis-cli on Ubuntu, Debian

$ cd /tmp
$ wget http://download.redis.io/redis-stable.tar.gz
$ tar xvzf redis-stable.tar.gz
$ cd redis-stable
$ make
$ cp src/redis-cli /usr/local/bin/
$ chmod 755 /usr/local/bin/redis-cli

BUT, I ran into this error running make:

Error jemalloc/jemalloc.h: No such file or directory when making Redis

…and fixed it following the instructions:

$ cd /tmp/redis-stable
$ make distclean
$ make

Next, I copied my docker-compose.yaml (see below) and redis.conf files to the instance at:

~/conf/redis/redis.conf
~/docker-compose.yaml

Here’s my docker-compose.yaml

version: '3'
services:
  redis:
    restart: always
    container_name: redis-stack
    command: redis-server /usr/local/etc/redis/redis.conf
    environment:
      - REDIS_AOF_ENABLED=no
    image: redis/redis-stack-server:latest
    ports:
      - '6379:6379'
    volumes:
      - ./redis-data:/data
      - ./conf/redis/redis.conf:/usr/local/etc/redis/redis.conf

I’m not going to replicate my redis.conf file as it’s too long but I set “requirepass” with the password I’m using which is picked up by redis-server.

For redis-cli you’ll want to set REDISCLI_AUTH variable in /etc/environment:

REDISCLI_AUTH=<password>

Next, start docker and run docker-compose:

$ sudo systemctl start docker
$ sudo docker-compose up -d

Test using the CLI:

$ export REDISCLI_AUTH=<password>
$ redis-cli
127.0.0.1:6379> ping
PONG

Update May 8, 2023
I found that the various modules included as part of Redis Stack were not loading due to my overriding redis.conf so I had to add the following to my conf file:

loadmodule /opt/redis-stack/lib/rejson.so
loadmodule /opt/redis-stack/lib/redisgraph.so
loadmodule /opt/redis-stack/lib/redistimeseries.so
loadmodule /opt/redis-stack/lib/redisbloom.so
loadmodule /opt/redis-stack/lib/redisearch.so

Enjoy.

511.org API Rate Limit

I use the 511.org API and one question I see come up frequently on the support forum are requests to increase the number of API requests possible using an API key. The answer is pretty straightforward, the 511 API is not intended to serve as your application’s backend. If you want to serve the data to large numbers of users you’ll need to use your API key, fetch the data, cache it on your own backend and serve it from there. You can then use your API key to refresh your own cached data and serve your application.

Another question that often comes up is access to historic data which, as of this writing, the API simply doesn’t provide. I would doubt the 511.org team will offer historic data anytime soon (if ever). If you’re looking for historic data the answer would be to build your own backend and archive the data.

To request an increased rate limit, you can provide the following information to transitdata@511.org:

  • your API key
  • the rate limit you need
  • a description of the use case
  • data endpoints you intend to use
  • a brief justification for the requested rate limit