Javatpoint Logo
Javatpoint Logo

Install Redis on Ubuntu

Introduction to Redis

Redis can be defined as an in-memory store of data structure, used as an in-memory key-value database, distributed, message and cache broker using optional durability. It stands for Remote Dictionary Server and supports many types of abstract data structures, including spatial indices, streams, bitmaps, HyperLogLogs, sorted sets, sets, maps, lists, and strings. The project was created and handled by Salvatore Sanfilippo, initiated in 2009. From 2015 until 2020, he led a core team of the project approved by Redis Labs.

Redis is an open-source application published upon a BSD 3-clause license. Not long after the actual author and primary maintainer left, in 2021, Redis Labs abandoned the Labs from the name and now is called simply "Redis".

History of Redis

The Redis project started when Salvatore Sanfilippo, the actual maintainer of Redis, was attempting to develop his Italian startup scalability, improving a real-time analyzer of web log. After encountering serious issues in scaling a few kinds of workloads with traditional database systems, Salvatore Sanfilippo started in 2009 to prototype the first proof of the Redis concept version in Tcl.

Later he converted that prototype into the C language and developed the first "list" data type. After some weeks of internally utilizing the project with success, Sanfilippo determined to open-source it, introducing the project on the Hacker News website. The project started gaining traction, specifically in the Ruby community, with Instagram and GitHub being among the initial organizations adopting it.

  • In March 2010, Sanfilippo was employed by VMware.
  • Redis was approved by Pivotal Software (VMware spin-off) in May 2013.
    Development was approved by Redis Labs in June 2015.
  • The Redis 5.0 version was published in October 2018, announcing Redis Stream, which was a data structure that permits the storage of two or more string and field values with a time-based, automatic order at one key.
  • Salvatore Sanfilippo left as Redis Maintainer in June 2020.

Difference between Redis and other database systems

Redis affected a system idea that can be treated as a cache and a store simultaneously. It was developed so that the data is always changed and accessed from the primary computer memory, although also saved on disk in a way that's not compatible with irregular data access. This changed data is just restored into memory when the system reboots.

Also, Redis offers a data model that's very curious than an RDBMS. The commands of the user don't define a query to be run via the database engine but instead, special tasks that are implemented on provided abstract data types. Hence, data has to be saved in a format that is compatible later with fast recovery.

The recovery is implemented without support from the database system in aggregations, secondary indexes, or other basic aspects of traditional RDBMS. The implementation of Redis uses the fork system call to copy the data holding process, so the parent process can continue to manage clients, and the child process makes an in-memory data copy on disk.

Supported languages of Redis

Since the 2.6 version, Redis has offered a server-client scripting aspect in the Lua language. On the client side, several programming languages include Redis language bindings, including Tcl, Swift, Smalltalk, Scala, Rust, Ruby, Racket, R, Python, Pure Data, PHP, Perl, OCaml, Objective-C, Lua, Julia, JavaScript (Node.js), Nim, Java, Io, Haxe, Haskell, Go, Erlang, Elixir, Delphi[30], Dart, D, Crystal, Common Lisp, Clojure Chicken, C#, C++, C, and ActionScript. Various client software programs are available in these languages.

Data types of Redis

Redis outlines keys to value types. An essential difference between many structured storage systems and Redis is that Redis not only supports strings but abstract data types as well:

  • Lists of strings
  • Sorted group of strings (sets of non-repeating components ordered via a floating-point number known as score)
  • Sets of strings (groups of non-repeating unsorted components)
  • HyperLogLogs has been available since the 2.8.9 version of Redis in April 2014, used for closed set cardinality size evaluation.
  • Hash tables where values and keys are strings.
  • Geospatial data from the geohash technique implementation, available since the 3.2 version of Redis.
  • Stream of entries using consumer groups permits us to store two or more string and field values with a time-based, automatic order at one key, available since the 5.0 version of Redis in October 2018.

A value type decides what operations (known as commands) are present for the value. Redis provides its support for server-side, atomic, and high-level operations, such as difference, union, and the intersection between sets of a list sorted, sorted sets and sets.

Other data types are also supported that are Redis Modules API-based:

  • JSON: RedisJSON operates ECMA-404 as a natural data type.
  • Time series: RedisTimeSeries operates the data structure of a time series.
  • Graph: RedisGraph operates a graph of queryable properties.
  • Top-K, Count-min sketch, Cuckoo filter, and Bloom filter: RedisBloom operates a group of probabilistic data structures.

More detailed overview of Redis data types:

  • Strings: These are the most common Redis data types, showing an order of bytes.
  • Lists: These are string lists sorted using insertion order.
  • Sets: These sets are unordered groups of special strings that behave like the sets through our preferred programming language (e.g., Python sets, Java HashSets, etc.). We can add, test, and remove with Redis set for O(1) existence time (despite the total set elements).
  • Hashes: These are described as record types formed as groups of field-value pairs. Fundamentally, Redis hashes simulate Ruby hashes, Java HashMaps, and Python dictionaries.
  • Sorted sets: These are groups of special strings that manage all associated scores of string order by.
  • Streams: Redis streams are a data structure that behaves the same as an append-only log. They help in recording events in the sequence they appear and syndicate them to process.
  • Geospatial indexes: These are helpful to find locations in a bounding box or geographic radius.
  • Bitmaps: Bitmaps let us implement bitwise operations for strings.
  • Bitfields: Bitfields encode two or more counters efficiently in a string value. They offer atomic get, set, and increase operations and help in many overflow policies.
  • HyperLogLog: HyperLogLog are data structures that offer probabilistic evaluations of the cardinality of broad sets.
  • Extensions: We can use the following options to extend the aspects given by the added data types:
    • Write our Redis module with the modules API and go through the community-supported modules.
    • Write our server-side programs in Lua.
    • Use time series, querying, JSON, and other features given by Redis Stack.

How can we secure Redis?

Redis binds to every interface, and it doesn't include authentication at all. If we use Redis in a highly controller environment, isolated from the outside internet and attackers, that is fine. However, it's a great security concern if any unhardened Redis is disclosed to the internet. If we are not 100% sure that our environment is properly secured, we can follow the below steps to get a more secure Redis. To enhance security, some steps are mentioned below:

  • We need to ensure that the port Redis utilizes to listen for many connections (6379 by default, 26379 for sentinel, and 16379 additionally if we execute Redis in the cluster mode) is firewalled so that it isn't possible to connect to Redis through the external world.
  • We can use the configuration file in which the bind directive is configured to ensure Redis just listens on the network interfaces we are using, e.g., the loopback interface if we are locally using Redis from a similar computer.
    We can use the option, i.e., requirepass, to add an extra security layer so that users will need to verify with the AUTH command.
  • We can use the spiped option or other SSL tunneling applications to encrypt traffic among Redis clients and Redis servers if our environment needs encryption.

Remember that any Redis instance disclosed to the Internet is very easy to exploit without security, so ensure that we follow the above and use a firewall layer. We can try to link to redis-cli from any outside host to prove ourselves the instance is not reachable after the firewall is set.

User interfaces of Redis

The redis-cli (Command line interface) is a terminal function used for sending commands to and seeing replies through the Redis server. It contains two primary modes: the first one is an interactive REPL (Read Eval Print Loop) mode in which the user enters Redis commands and gets replies, and the second one is the command mode in which redis-cli runs with extra arguments and the response is displayed on the standard output.

To let us work with the Redis deployment, RedisInsight merges the graphical user interface with Redis CLI. Visually, we can browse and collaborate with data, understand by example, take benefits of diagnostic tools, and others.

  • Redis CLI: synopsis of redis-cli, the Redis CLI.
  • RedisInsight: Optimize and visualize Redis data.

Installation of Redis on Ubuntu

Follow the steps given below to install Redis on Ubuntu:

First setup a non-root user using sudo and then install build and test dependencies:


Redis Installation on Ubuntu 1
Redis Installation on Ubuntu 2

To continue press Y

Redis Installation on Ubuntu 3

Install Redis Server

Use the following command to install Redis server:


Redis Installation on Ubuntu 4
Redis Installation on Ubuntu 5

Now Redis Server is installed. You can start the Redis server:


Start Redis Server

You the following command to start redis server:


Redis Installation on Ubuntu 6

Start Redis Client

Redis server is started so you can start redis client to make communication between them.


Redis Installation on Ubuntu 7

Verify if Redis is working

Execute the following command:

This will open a redis prompt.

redis 127.0.0.1:6379>

In the above prompt, 127.0.0.1 is machine's IP address and 6379 is the port on which Redis server is running.

Now type the following PING command.

It specifies that Redis is successfully installed on your system.

Redis Installation on Ubuntu 8





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA