Telescope uses the Redis database and cache server to store all project data. We use the ioredis JavaScript module to interact with Redis in our code. In our tests, we use ioredis-mock to provide mocks for Redis.
NOTE: if you need to use an in-memory, mock version of Redis vs. a real database, use the environment variable
MOCK_REDIS=1
. Our tests use this.
For information about installing Redis, see our environment setup guide.
Telescope uses Elasticsearch as a search engine for full-text indexing. It is used to search posts indexed by Telescope by author or post keyword.
- Use the
redis-cli
command to run commands. Link to the docs for it are at https://redis.io/topics/rediscli. - Redis stores key/value pairs, where a key is a string, and a value is one of a number of data types. We mainly use hashes (like an Object in JavaScript) and sets, and sorted sets (like an array with no duplicates, or a Set in JavaScript).
- If you need to see a list of all keys in the database, from the CLI use
keys *
- Our Telescope keys are namespaced, and use the
t:
prefix. Any keys that start withbull:
are part of the Bull feed queue (i.e., our jobs for processing feeds into posts). - If you need to see what's in the set of all feeds, use
smembers t:feeds
. The values returned areid
s, which you can use withhgetall
(see below). A set is a list with no duplicates. - If you need to see what's in the sorted set of all posts, use
zrange t:posts 0 -1
, where0
is the starting position and-1
the end (e.g., get everything). An ordered set is a set which orders its members by some value (we use the post's publish date, so that they are in chronological order). - If you need to see just the post keys, use
keys t:post:*
. Each post key ends with anid
, for example:t:post:a501d01b94
is the key for a post with anid
ofa501d01b94
. - If you need to see just the feed keys, use
keys t:feed:*
. Each feed key ends with anid
, for examplet:feed:f73dcb2226
. As with posts,t:feed:f73dcb2226
is the key for a feed with anid
off73dcb2226
- If you need to see what's stored in a post or feed key, (they are Redis Hashes) use
hgetall t:post:a501d01b94
where12345
is theid
of a post,hgetall t:feed:f73dcb2226
where12345
is theid
of a feed. - If you need to delete all data in the database (e.g., when a change affects our data layout or keys), use
flushall
. This is generally safe to run, sincenpm start
will regenerate all the data.