Learn Basic Redis Commands
Redis is an in-memory database that persists on disk. The data model is key-value, but many different kinds of values are supported: Strings, Lists, Sets, Sorted Sets, Hashes, HyperLogLogs, Bitmaps.
We wrote a few guides on Redis in past few months. You can find them in our Redis blog category here. Today we will show you some basic Redis Commands that will be helpful when working on Redis.
- Start redis with the related configuration file from SSH
- Open a redis prompt from SSH
Redis Log Location
Redis Log File –
- Check configuration loaded on redis-server
cat /var/log/redis_6379.log | grep Configuration
The output will be as the following image.
Here you can check timings when you stared redis-server and see if logs have the “Configuration Loaded”. If configuration loaded
You can use nano to manually view full log.
Below Commands Should be run inside redis-cli
- Check Redis Server status
The output should be ‘PONG’ if server status is active
- Set value in the key
SET key value
- Get value in the key
- Get the length of the value stored in a key
- Increment value in the key
- Increment the integer value of a key by the given amount
INCRBY key increment
- Decrement the integer value of the key by one
- Decrement the integer value of a key by the given number
DECRBY key decrement
- Delete key
- List of all active configuration variables you can change
CONFIG GET *
- Get the value of maxmemory configuration for Redis
CONFIG GET maxmemory
- Get the value of dbfilename
CONFIG GET dbfilename
- Change key by issuing a “CONFIG SET” command like
CONFIG SET timeout 500
500 is new value
- Change the key value for maxmemory
CONFIG SET maxmemory 4157683648
4157683648 is new value
- Check the number of keys in the database.
- Check if a key exists
Output will be in 0 or 1
Here, 0 and: 1 mean false and true, respectively.
- Purge all of the keys from the database
- Close both Redis and our telnet session