Redis Cached Installing and Configuring on FreeBSD via PKG or Ports

Redis (Remote Dictionary Server) is an in-memory data structure store, used as a key-value database, in-memory distributed cache and messaging, with optional durability. Redis supports various types of abstract data structures, such as strings, lists, maps, sets, ordered sets, HyperLogLog, bitmaps, streams, and spatial indexes.

The Redis project started when Salvatore Sanfilippo, the original developer of Redis, wanted to improve the scalability of his Italian startup. From there he developed Redis which is now used as a database, cache, message broker and queue. Redis delivers sub-millisecond response times, enabling millions of requests per second for real-time applications in industries such as gaming, ad tech, financial services, healthcare, and IoT.

Today, Redis is one of the most popular and loved open source engines. Even Stack Overflow was named the "Most Loved" database for five years in a row. Due to its fast performance, Redis is a popular choice for caching, session management, gaming, leaderboards, real-time analytics, geospatial, ride-hailing, chat/messaging, media streaming, and pub/sub applications.

All Redis data is stored in memory, which enables low latency and high throughput data access. Unlike traditional databases, storing data in memory does not require a trip to disk, reducing machine latency to microseconds. Therefore, in-memory data storage can support more operations and faster response times. The result is blazing fast performance with an average read and write operation of less than one millisecond and support for millions of operations per second.

In this article we will discuss how to install and configure Redis on a FreeBSD 13.2 system. Not only that, this article will also discuss how to test Redis.

List of contents

1. Redis installation

2. Configure Redis

3. Connect and perform basic operations in Redis


1. Redis installation

To install Redis, this article will only explain how to install Redis with a ports system. Before we install Reist, first update the FreeBSD ports system. Here's how to update ports and PKG on FreeBSD.

root@ns1:~ # portmaster -af
root@ns1:~ #
portupgrade -af

root@ns1:~ # pkg update -f
root@ns1:~ #
pkg upgrade -f

After the ports system has been successfully updated, continue with the Redis installation. Here's how to install Redis.

root@ns1:~ # pkg install redis

If you want to install Redis with the FreeBSD Ports system, below are the commands.

root@ns1:~ # cd /usr/ports/databases/redis

root@ns1:/usr/ports/databases/redis #
make install clean

====> Compressing man pages (compress-man)
===> Staging rc.d startup script(s)
===> Installing for redis-7.0.12
===> Checking if redis is already installed
===> Registering installation for redis-7.0.12

Installing redis-7.0.12...
===> Creating groups.

Using existing group 'redis'.
===> Creating users

Using existing user 'redis'.

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.

===> SECURITY REPORT:

This port has installed the following files which may act as network
servers and may therefore pose a remote security risk to the system.


From the installation display above, we can see that Redis has the user and group name "redis", and we can see the script to activate Redis, namely "redis_enable="YES"

2. Configure Redis

After you have successfully installed Redis, the next step so that Redis can be used according to its function, must be configured. The Redis config file is located at /usr/local/etc/redis.conf. The redis.conf file is where we have to edit the script in it. The following is a script that you must change in the /usr/local/etc/redis.conf file.

bind 127.0.0.1
requirepass
gunungrinjani
daemonize yes
port 6379
maxmemory-policy volatile-lru
maxmemory 64mb


The script above is a script that you must activate in the /usr/local/etc/redis.conf file, by removing the "#" sign in front of the script. The script above means that the IP address used by Redis is 127.0.0.1 on port 6379 with a password gunung rinjani.

After the "redis.conf" config file has been configured, the next step is to create a Startup script in the /etc/rc.conf file. This script is useful for activating Redis automatically, so you don't need to do it manually. To activate Redis, just type the script below. Redis will automatically activate. The following is the Redis script that you must type in the /etc/rc.conf file.

root@ns1:~ # ee /etc/rc.conf
redis_enable="YES"

Then type the following script so that Redis will automatically activate.

root@ns1:~ # service redis restart
Stopping redis.
Waiting for PIDS: 913.
Starting redis.



3. Connect and perform basic operations in Redis

a. Connecting to Redis Local Server

root@ns1:~ # redis-cli
127.0.0.1:6379>


b. Password Authentication

root@ns1:~ # redis-cli
127.0.0.1:6379> auth gunungrinjani
OK


c. Check Redis Information

127.0.0.1:6379> info

# Server
redis_version:7.0.12
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:59718b2dab3b47c2
redis_mode:standalone
os:FreeBSD 13.2-RELEASE amd64
arch_bits:64
monotonic_clock:POSIX clock_gettime
multiplexing_api:kqueue
atomicvar_api:c11-builtin
gcc_version:4.2.1
process_id:50533
process_supervised:no
run_id:aafb54938038bfe082b75a9b719b8229583f5d2c
tcp_port:6379
server_time_usec:1691552810868548
uptime_in_seconds:502
uptime_in_days:0
hz:10
configured_hz:10
lru_clock:13831210
executable:/usr/local/bin/redis-server
config_file:/usr/local/etc/redis.conf
io_threads_active:0

# Clients
connected_clients:1
cluster_connections:0
maxclients:10000
client_recent_max_input_buffer:8
client_recent_max_output_buffer:0
blocked_clients:0
tracking_clients:0
clients_in_timeout_table:0

# Memory
used_memory:1504008
used_memory_human:1.43M
used_memory_rss:8265728
used_memory_rss_human:7.88M
used_memory_peak:1504008
used_memory_peak_human:1.43M
used_memory_peak_perc:100.16%
used_memory_overhead:1405160


d. Viewing Redis Server Information

127.0.0.1:6379> info server

# Server
redis_version:7.0.12
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:59718b2dab3b47c2
redis_mode:standalone
os:FreeBSD 13.2-RELEASE amd64
arch_bits:64
monotonic_clock:POSIX clock_gettime
multiplexing_api:kqueue
atomicvar_api:c11-builtin
gcc_version:4.2.1
process_id:50533
process_supervised:no
run_id:aafb54938038bfe082b75a9b719b8229583f5d2c
tcp_port:6379
server_time_usec:1691552929519441
uptime_in_seconds:621
uptime_in_days:0
hz:10
configured_hz:10
lru_clock:13831329
executable:/usr/local/bin/redis-server
config_file:/usr/local/etc/redis.conf
io_threads_active:0


e. Redis Benchmark Tests

root@ns1:~ # redis-benchmark -h 127.0.0.1 -p 6379 -n 10000 -c 15 -a gunungrinjani

The script above is only part of the basic Redis script, to explore Redis in depth you can read other articles. The main point in this article only focuses on the Redis installation and configuration process. By practicing this article, it means you have successfully run Redis on a FreeBSD server.
Iwan Setiawan

I Like Adventure: Mahameru Mount, Rinjani Mount I Like Writer FreeBSD

Post a Comment

Previous Post Next Post