Redis Module #62 Flashcards
What kind of database is Redis, generally speaking?
NoSQL Yay! And it uses a key/value store model to store data.
Redis has a reputation for being very fast. What makes the software work so quickly?
Redis is fast because it is an in-memory database. In other words, instead of storing data on a hard drive it saves in memory(RAM). Must use quite a lot of RAM eh?
How do you make sure that Redis starts automatically when the computer is rebooted?
brew services start redis
alternatively, maybe even better you can start it manually
redis-server /usr/local/etc/redis.conf
Important detail: on which port does Redis listen?
Redis listens on port 6379
What’s the basic syntax/structure to access a remote Redis server?
From the command line:
redis-cli -h -p -a
Important detail: how do you drop into the Redis CLI?
Type: redis-cli
then you will know you’re in the redis-cli when you see the local host IP and port number.
tomphillips@Toms-MBP-2 Redis % redis-cli
127.0.0.1:6379>
How can we store data into the Redis CLI?
Use the syntax SET
Example: SET name “Flavio”
In the above keyname = name value = Flavio
How can we retrieve a value from the DB?
GET
What if we’re not sure if a particular key exists?
EXISTS
If a 1 is returned, the key exists
0 means there was no match, key doesn’t exist
How are keys deleted?
Use DEL name
What if we want to set up a key only if it doesn’t yet exist?
SETNX name
How can we see a list of keys?
You can see all keys by typing:
KEYS* (big list) or you can filter by this pattern
KEYS n* to find all keys that start with an “n”
How can we create a temporary key that expires at a predefined span of time?
SETEX
Also, you can find the remaining time before a key expires by calling TTL
How much data can a single key store?
512mb
How is null represented in Redis and when might you expect to see this value?
Null is represented in Redis as nil and you’d see this when returning a key that has expired.
How does Redis define a list?
A list is a set of key-values pairs linked to each other.