Redis is a distributed in-memory database. It stores data in key, value pairs. There are no tables, schema, or collections.
Redis processes data in memory but stores it on disk. Processing it in memory means it is very fast, because there are no mechanical moving parts as there is no disk I/O.
Of course in memory processes that spill over to other servers in the cluster would be limited by the speed of the ethernet connection between the servers (which is usually 1 GBPS). But that is true with any distributed architecture.
Redis makes the analogy between their distributed memory system and memcached, which its authors say “Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.” So, memcached is temporary storage and Redis is permanent.
You can try Redis online from here or install it.
Redis does not promote installing their server from packages. Instead make sure you
have installed build-essential, so that you can compile code, then download from source then issue this command to compile the code:
if you have any problems look here.
Now, start it:
open the command line interface (cli):
Add Key->Value pairs
Add a key value pair then retrieve it. Here the key is walker and the value is walker.
set walker "walker"
127.0.0.1:6379> get walker
Redis will let you add to numeric values using the incr function. The function is atomic meaning it will work even when two people are adding to the same key at the same time.
set age 10
127.0.0.1:6379> incr age
Lists are a data structure that contains lists of items. The items are stored in the order you add them.
rpush students "walker" "stephen" "ellen"
You can remove the right-most element by popping it from the list:
Now look at the list. First we need to get the length so that we can list then as the lrange function requires that you tell it where to stop. List commands start with l while set commands start with s. The first element is 0.
lrange students 0 1
You can also list elements starting from the end of the list using negative numbers. This lists the last element:
lrange students -1 1
Sets are lists that do not allow duplicate values. Use SADD to add elements.
See below. Here we show you cannot add the same element twice to a set as the second command returns 0 elements added:
sadd numbers 1
127.0.0.1:6379> sadd numbers 1
Here is the union of two sets. We use odd and even numbers as the set names.
sadd odd 1
sadd odd 3
sadd odd 5
sadd even 2
sadd even 4
sadd even 6
sunion odd even
And the intersection should be empty since no number can be both even and odd:
sinter odd even
(empty list or set)
Redis also supports sorted sets and many other data structures.
Redis scripting uses the Lua programming language. Lua’s authors say “Lua is a powerful and fast programming language that is easy to learn and use and to embed into your application.” In the next blog post we will explore how to use Lua with Redis. But if you don’t want to use Lua you can use any of the many Redis clients listed here.
- Redefining process and data automation in the era of big data
- Hadoop vs HBase: What’s The Difference?
- Apache Spark: Working with Streams
- BMC Sets Out to Land the Big “Data” Catch at Hadoop Summit
- Reading Streaming Twitter feeds into Apache Spark