Redis Basics

Redis Basics Here are my notes on Redis. Installation, Start, and Shutdown I installed WSL and then installed Redis using sudo. To start Redis, cd to /usr/bin and run sudo ./redis-server To connect to Redis, cd to /usr/bin and run sudo ./redis-cli To shutdown Redis, run shutdown in the redis-cli, and Redis will save an RDB snapshot before exiting To check whether Redis is running, run ps -ef | grep redis To kill the process, run kill -9 <pid> Commands keys * returns all keys. This command also supports regex patterns dbsize returns the number of keys expire key sets the TTL of the key in seconds pexpire sets the TTL in milliseconds expireat sets the absolute time when the key will expire ttl key returns the remaining time of the key -1 means it won’t expire -2 means it has already expired Non-negative values show the countdown in seconds set key value setnx key value only sets the value when a key does not exist mset k1 v1 k2 v2 k3 v3 ... sets multiple key-value pairs This can save network bandwidth! get key mget k1 k2 k3 gets multiple keys rename old_key new_key renames the old key to the new key Use renamenx for safer operation, so it won’t override existing keys Naming Convention Naming convention for keys is very important. ...

July 13, 2025