Home >> Interviews Q & A >> Redis Cache Interview Questions

Redis Cache Interview Questions

Redis Cache: Redis Interview Questions for beginners and professionals. Redis mostly used for Cache Solutions and Session Management | Redis Cache.
Redis Cache | Redis Interview Questions | Basic
Q:- What is Redis?
Redis is an open source, in-memory data store, used as a database, cache and message broker.

Redis 5.0.3 is the latest stable version. Official Download Link

Redis mostly used for cache solutions and Session Management.

Q:- What is in-memory Database?

The in-memory database is a database where it keeps the dataset in RAM. Means that for every interaction with the database, you will only access the Main memory; No DISK operations involved during this interaction. Hence the operation will be faster as it directly access main memory instead of any disk operation.

Q:- What is Redis Stand For?

Redis stands for REmote DIctionary Server.

Q:- List programming language supported by Redis?
  • C/C++
  • Node.js
  • PHP
  • Go
  • Java
  • Ruby
  • Scala
  • Swift
  • Perl
Q:- What is the default port for Redis?
6379
Q:- In which Language Redis has been Written?

Written in: ANSI C

Q:- List Some useful Redis Commands?

Following are some useful Redis commands:

  • redis-server: runs the Redis Server itself.
  • redis-sentinel: runs Redis Sentinel, a tool for monitoring and failover.
  • redis-cli: runs a command line interface utility to interact with Redis.
  • redis-cli --help: to check all the commands that can be used with redis-cli.
  • redis-benchmark: checks Redis performance.
  • redis-cli info: checks Redis Info.
Q:- How to check redis instance version?
redis-server --version

OR

redis-server -v

OR

redis-cli -v
Q:- What are the features of Redis?

Following are the features that redis offers to be used as a "real" data store instead of just a cache.

  1. Powerful data types and powerful commands:
    • Strings
    • Lists
    • Sets
    • Hashes
    • Bitmaps
    • HyperLogLogs
  2. Persistence to disk, by default.
  3. Transactions with optimistic locking (WATCH/MULTI/EXEC)
  4. Pub/sub. Extremely fast.
  5. Values up to 512MB in size (memcached limited to 1MB per key)
  6. Lua scripting (as of V2.6)
  7. Built in clustering (as of V3.0)
  8. Extremely fast at everything
Redis Cache | Redis Interview Questions | Intermediate
Q:- How to Install Redis in Node.js

Using Redis with Node.js: You can use redis - a node.js redis client

npm install redis

In Node.js Code, you can Check like this

var redis = require('redis');
var client = redis.createClient();

client.on('connect', function() {
    console.log('Redis client connected');
});

client.on('error', function (err) {
    console.log('Something went wrong ' + err);
});

client.set('redis_key', 'JSON or String Values', redis.print);
client.get('redis_key', function (error, result) {
    if (error) {
        console.log(error);
        throw error;
    }
    console.log(result);
});
Q:- How to check whether the Redis server is Running

We can use the redis-cli to send a command to it directly. To test that Redis is working properly. If everything is working well, we should get PONG as a reply in the shell.

redis-cli ping

//Output: PONG

In PHP Code, you can Check like this

$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
echo $redis->ping();

//Output: PONG
Q:- How to stop Redis?
/etc/init.d/redis-server stop
Q:- How to run Redis in Background?
redis-server &

Note:

The limitation of this approach is that you can't run any 2nd command in the same bash command after the '&'

For Example: you can't run redis-server & && do-something-else-in-redis

Redis Cache | Redis Interview Questions | Advanced
Q:- How can we move a redis database from one server to another?
  1. You can use BGSAVE command to save a spanshot of the database into a dump.rdb
  2. Now, copy this dump.rdb file into another server.
Q:- How to delete everything in Redis?

You can use Redis FLUSHDB command to delete all the keys of the currently selected database.

redis-cli FLUSHDB	//Removes data from your connection's current database
redis-cli FLUSHALL //Removes data from all databases
redis-cli -n database_number FLUSHDB //Removes all keys of the specified Redis database
Q:- How to fetch all redis keys from database?

Redis command for fetching all keys in the database

redis-cli keys "*"
Q:- How to find all redis process?

Find Redis Process:

ps aux | grep redis-server
Full Stack Tutorials

Author @FullStackTutorials | View all Articles