How to install and configure Redis 6 on FreeBSD 13

Redis is an in-memory data structure store, used as a distributed, in-memory key value database, cache and message broker, with optional durability. Redis supports different kinds of abstract data structures, such as strings, lists, maps, sets, sorted sets, HyperLogLogs, bitmaps, streams, and spatial indices.

In this tutorial we are going to learn how to install Redis 6 on FreeBSD 13.

Related Content

# Prerequisites

To follow along, ensure that you have:

  • An updated FreeBSD 13 server
  • Access to the Internet
  • Root access to the server or user with sudo access

# Update FreeBSD 13 Server

Before proceeding, ensure that the server is updated using this command (as a root user):

1
2
pkg update
pkg upgrade

Let us also ensure vim is installed using this command since we will use it later:

1
pkg install -y vim

# Installing redis

Redis is available in the default FreeBSD repositories. To install it, use this command:

1
pkg install -y redis

This is the output on my server

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# pkg install -y redis

Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 1 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
	redis: 6.2.6

Number of packages to be installed: 1

The process will require 6 MiB more space.
729 KiB to be downloaded.
[1/1] Fetching redis-6.2.6.pkg: 100%  729 KiB 746.3kB/s    00:01
Checking integrity... done (0 conflicting)
[1/1] Installing redis-6.2.6...
===> Creating groups.
Creating group 'redis' with gid '535'.
===> Creating users
Creating user 'redis' with uid '535'.
[1/1] Extracting redis-6.2.6: 100%
=====
Message from redis-6.2.6:

--
To setup "redis" you need to edit the configuration file:
      /usr/local/etc/redis.conf

      To run redis from startup, add redis_enable="YES"
      in your /etc/rc.conf.

Use this command to confirm the redis package installed:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# pkg info redis

redis-6.2.6
Name           : redis
Version        : 6.2.6
Installed on   : Fri Nov 19 10:01:00 2021 UTC
Origin         : databases/redis
Architecture   : FreeBSD:13:amd64
Prefix         : /usr/local
Categories     : databases
Licenses       : BSD3CLAUSE
Maintainer     : osa@FreeBSD.org
WWW            : https://redis.io/
Comment        : Persistent key-value database with built-in net interface
Options        :
	JEMALLOC       : off
	LUA            : off
	LUAJIT         : off
	LUAJITOR       : off
	TESTS          : off
	TLS            : off
	TRIB           : off
Annotations    :
	FreeBSD_version: 1300139
	repo_type      : binary
	repository     : FreeBSD
Flat size      : 6.10MiB
Description    :
Redis is an open source, advanced key-value store.  It is often referred
to as a data structure server since keys can contain strings, hashes,
lists, sets and sorted sets.

You can run atomic operations on these types, like appending to a string;
incrementing the value in a hash; pushing to a list; computing set
intersection, union and difference; or getting the member with highest
ranking in a sorted set.

In order to achieve its outstanding performance, Redis works with an
in-memory dataset.  Depending on your use case, you can persist it either
by dumping the dataset to disk every once in a while, or by appending each
command to a log.

Redis also supports trivial-to-setup master-slave replication, with very
fast non-blocking first synchronization, auto-reconnection on net split
and so forth.

WWW: https://redis.io/

Now that the service has been installed, let’s start it with this command:

1
2
3
# service redis onestart

Starting redis.

Enable the service so it starts on boot:

1
2
3
# sysrc redis_enable="YES"

redis_enable:  -> YES

After the service starts, use this command to check the status of the service:

1
2
3
# service redis status

redis is running as pid 33056.

The above indicates that the service has been started successfully.

# Configuring Redis

The redis configuration file is located in this path /usr/local/etc/redis.conf. In this section, we are going to update the redis configuration file to allow remote access, to set an authentication password, to add a pid file and to Set Persistent Store for Recovery.

Edit redis config file using this:

1
vim /usr/local/etc/redis.conf

To allow remote access to the redis instance, bind redis to 0.0.0.0 using this line:

1
bind * -::*

To set password in redis, use this:

1
requirepass j2GfJuLFR8

To add a pid file to redis:

1
pidfile /var/run/redis/redis-server.pid

Set Persistent Store for Recovery by changing the appendonlyvalue to yes

1
2
appendonly yes
appendfilename "appendonly.aof"

Restart redis service to apply changes:

1
2
3
4
# service redis restart
Stopping redis.
Waiting for PIDS: 33056.
Starting redis.

# Connecting and performing basic operations in Redis

Connecting to redis locally:

1
redis-cli

To authenticate:

1
2
3
4
5
# redis-cli

127.0.0.1:6379> auth j2GfJuLFR8
OK
127.0.0.1:6379>

You should receive OK in the output. If you input a wrong password, Authentication should fail.

Check redis information.

1
127.0.0.1:6379> INFO

This will output a long list of data. You can limit the output by passing Section as an argument. E.g.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
127.0.0.1:6379> INFO Server
# Server
redis_version:6.2.6
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:74f6bda298c45b9e
redis_mode:standalone
os:FreeBSD 13.0-RELEASE-p4 amd64
arch_bits:64
multiplexing_api:kqueue
atomicvar_api:atomic-builtin
gcc_version:4.2.1
process_id:33134
process_supervised:no
run_id:7363d70d4e75fdaf28e8738a987f4b2ef2da6d8d
tcp_port:6379
server_time_usec:1637316624510229
uptime_in_seconds:56
uptime_in_days:0
hz:10
configured_hz:10
lru_clock:9926672
executable:/usr/local/bin/redis-server
config_file:/usr/local/etc/redis.conf
io_threads_active:0

# Performing Redis Benchmarking

Run the benchmark with 15 parallel connections, for a total of 10k requests, against local redis to test its performance.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$ redis-benchmark -h 127.0.0.1 -p 6379 -n 10000 -c 15 -a j2GfJuLFR8

====== PING_INLINE ======
  10000 requests completed in 0.23 seconds
  15 parallel clients
  3 bytes payload
  keep alive: 1
  host configuration "save": 3600 1 300 100 60 10000
  host configuration "appendonly": no
  multi-thread: no

Latency by percentile distribution:
0.000% <= 0.031 milliseconds (cumulative count 1)
50.000% <= 0.095 milliseconds (cumulative count 6342)
75.000% <= 0.103 milliseconds (cumulative count 7740)

..........

Cumulative distribution of latencies:
29.540% <= 0.103 milliseconds (cumulative count 2954)
99.810% <= 0.207 milliseconds (cumulative count 9981)
99.990% <= 0.303 milliseconds (cumulative count 9999)
100.000% <= 0.407 milliseconds (cumulative count 10000)

Summary:
  throughput summary: 91743.12 requests per second
  latency summary (msec):
          avg       min       p50       p95       p99       max
        0.121     0.032     0.127     0.167     0.183     0.319

For more options and examples, use:

1
redis-benchmark --help

# Conclusion

In this guide, we have managed to install and configure Redis 6 in FreeBSD 13.

comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy