Redis Cache | Redis Interview Questions | Basic
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.
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.
Redis stands for REmote DIctionary Server.
Written in: ANSI C
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.
Following are the features that redis offers to be used as a "real" data store instead of just a cache.
- Powerful data types and powerful commands:
- Persistence to disk, by default.
- Transactions with optimistic locking (WATCH/MULTI/EXEC)
- Pub/sub. Extremely fast.
- Values up to 512MB in size (memcached limited to 1MB per key)
- Lua scripting (as of V2.6)
- Built in clustering (as of V3.0)
- Extremely fast at everything
Redis Cache | Redis Interview Questions | Intermediate
Using Redis with Node.js: You can use redis - a node.js redis client
In Node.js Code, you can Check like this
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.
In PHP Code, you can Check like this
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
- You can use BGSAVE command to save a spanshot of the database into a dump.rdb
- Now, copy this dump.rdb file into another server.
You can use Redis FLUSHDB command to delete all the keys of the currently selected database.
Redis command for fetching all keys in the database
Find Redis Process: