Database / REDIS
Redis is an open source in-memory data structure store which can be used as a database and/or a cache and message broker.
NoSQL Key/Value Store.
Supports Multiple data structures.
Built in Replication.
Redis supports,
- Strings,
- Lists,
- Sets,
- Sorted Sets,
- Hashes,
- Bitmaps,
- Hyperlogs,
- and Geospatial indexes.
- Very Flexible.
- No Schema and column names.
- Very fast, can perform around 110K Set per second and 81K GETS per second.
- Rich Datatype support,
- command level Atomic Operation,
- Caching & Disk Persistence.
REDIS supports most of the programming languages including Java, C#, Python, Scala, C++, R, PHP and many more.
Redis supports simple master to slave replication. When a relationship is established, data from the master is replicated to the slave.
Redis is designed to be accessed by trusted clients.
REDIS can be restricted to certain interfaces.
Data encryption not supported and hence do not allow external access/internet exposure.
Redis stands for REmote DIctionary Server.
Redis is developed using ANSI C and mostly used for cache solution and session management. It creates unique keys for store values.
SET command creates one key-value pair while using MSET command, multiple key-value pairs can be created.
LPUSH inserts all the specified values at the head of the list stored at key. If the key does not exist, it is created as an empty list before performing the push operations. When key holds a value that is not a list, an error is returned.
Usage: LPUSH key value [value ...]
redis> LPUSH mylist "World" (integer) 1 redis> LPUSH mylist "Hello" (integer) 2 redis> LRANGE mylist 0 -1 1) "Hello" 2) "World" redis>
REDIS is single threaded.
It has got limited client support for consistent hashing.
It has significant overhead for persistence.
It cannot be deployed widely.
No. Redis compromises with durability to enhance the speed. In Redis, in the case of system failure or crash, it writes to disk but may fall behind and lose the data which is not stored.
Memcached. | REDIS. |
Memcached is multi-threaded. | Redis is single threaded. |
Memcached only does caching information. | Redis does caching information and also supports persistence and replication. |
Memcached supports the functionality of LRU (Least Recently Used) eviction of values. | Redis does not support the functionality of LRU eviction of values. |
In Memcached when they overflow memory, the one you have not used recently (LRU- Least Recently Used) will get deleted. | In Redis you can set a time out on everything, when memory is full, it will look at three random keys and deletes the one which is closest to expiry. |
Memcached supports CAS(Check And Set). It is useful for maintaining cache consistency. | Redis does not support CAS ( Check And Set). |
Add the specified members to the set stored at key. Specified members that are already a member of this set are ignored. If key does not exist, a new set is created before adding the specified members.
An error is returned when the value stored at key is not a set.
Usage: SADD key member [member ...]
Example: redis> SADD myset "Hello" (integer) 1 redis> SADD myset "World" (integer) 1 redis> SADD myset "World" (integer) 0 redis> SMEMBERS myset 1) "World" 2) "Hello"
LPUSH adds an element to the beginning of a list.
RPUSH add an element to the end of a list.
LPOP removes the first element from a list and returns it.
RPOP removes the last element from a list and returns it.
LLEN gets the length of a list.
LRANGE gets a range of elements from a list.