How to Install Latest Redis on CentOS 7

CentOS 7

Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries and streams. Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.Redis can be used as a database server, as a message broker or for caching data in memory for faster retrieval

In this tutorial, we will cover step by step ways to install Redis on CentOS 7.

Step 1: Update your CentOS 7

#yum -y update

Step 2: Add REMI repisitory

#yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

Step 3: Install Redis on CentOS 7

#yum --enablerepo=remi install redis

Verify it

#rpm -qi redis 

Step 4: Start Redis Service on CentOS 7

#systemctl enable --now redis

Step 5: Enable network Listen for Redis Service

#vi /etc/redis.conf

change line bind 127.0.0.1 to below

bind 0.0.0.0

Configure Redis Authentication

Configure Redis Authentication for clients to require AUTH <PASSWORD> before processing any other commands.

requirepass <AuthPassword>

Eg: requirepass poi123!@#

Set Persistent Store for Recovery

Set persistence mode by changing the appendonlyvalue to yes

appendonly yes

appendfilename “appendonly.aof”

Save and Exit

#systemctl restart redis

# netstat -pant | grep :6379
[root@syam ~]# redis-cli
127.0.0.1:6379> 

Test authentication:

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

127.0.0.1:6379> AUTH po123!@#
OK

+Check redis information.

127.0.0.1:6379> INFO
# Server
redis_version:5.0.4
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:ca295adcd8964025
redis_mode:standalone
os:Linux 4.15.0-43-generic x86_64
arch_bits:64
multiplexing_api:epoll
atomicvar_api:atomic-builtin
gcc_version:4.8.5
process_id:5777
run_id:96c33ce71e7f1637ce0eb792b4e82fa2a231ca7f
tcp_port:6379
uptime_in_seconds:122
uptime_in_days:0
hz:10
configured_hz:10
lru_clock:10352798
executable:/usr/bin/redis-server
config_file:/etc/redis.conf

# Clients
connected_clients:1
client_recent_max_input_buffer:2
client_recent_max_output_buffer:0
blocked_clients:0

# Memory
used_memory:854056
used_memory_human:834.04K
used_memory_rss:3334144
used_memory_rss_human:3.18M
used_memory_peak:854056
used_memory_peak_human:834.04K
used_memory_peak_perc:100.12%
used_memory_overhead:840854
used_memory_startup:791160
used_memory_dataset:13202
used_memory_dataset_perc:20.99%
allocator_allocated:1108376
allocator_active:1355776
allocator_resident:3948544
total_system_memory:8219459584
total_system_memory_human:7.65G
used_memory_lua:37888
used_memory_lua_human:37.00K
used_memory_scripts:0
used_memory_scripts_human:0B
number_of_cached_scripts:0
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
allocator_frag_ratio:1.22
allocator_frag_bytes:247400
allocator_rss_ratio:2.91
allocator_rss_bytes:2592768
rss_overhead_ratio:0.84
rss_overhead_bytes:-614400
mem_fragmentation_ratio:4.11
mem_fragmentation_bytes:2522080
mem_not_counted_for_evict:0
mem_replication_backlog:0
mem_clients_slaves:0
mem_clients_normal:49694
mem_aof_buffer:0
mem_allocator:jemalloc-5.1.0
active_defrag_running:0
lazyfree_pending_objects:0

# Persistence
loading:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1553856548
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:-1
rdb_current_bgsave_time_sec:-1
rdb_last_cow_size:0
aof_enabled:1
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok
aof_last_cow_size:0
aof_current_size:0
aof_base_size:0
aof_pending_rewrite:0
aof_buffer_length:0
aof_rewrite_buffer_length:0
aof_pending_bio_fsync:0
aof_delayed_fsync:0

# Stats
total_connections_received:1
total_commands_processed:2
instantaneous_ops_per_sec:0
total_net_input_bytes:112
total_net_output_bytes:128
instantaneous_input_kbps:0.00
instantaneous_output_kbps:0.00
rejected_connections:0
sync_full:0
sync_partial_ok:0
sync_partial_err:0
expired_keys:0
expired_stale_perc:0.00
expired_time_cap_reached_count:0
evicted_keys:0
keyspace_hits:0
keyspace_misses:0
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:0
migrate_cached_sockets:0
slave_expires_tracked_keys:0
active_defrag_hits:0
active_defrag_misses:0
active_defrag_key_hits:0
active_defrag_key_misses:0

# Replication
role:master
connected_slaves:0
master_replid:1a08f8059c027be91aa62d8d066b790cfde8b1da
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:0
second_repl_offset:-1
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0

# CPU
used_cpu_sys:0.085360
used_cpu_user:0.081480
used_cpu_sys_children:0.000000
used_cpu_user_children:0.000000

# Cluster
cluster_enabled:0

# Keyspace
127.0.0.1:6379> 

Step 6: Perform Redis Benchmarking

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

[root@syam ~]# redis-benchmark -h 127.0.0.1 -p 6379 -n 5000 -c 20
====== PING_INLINE ======
  5000 requests completed in 0.04 seconds
  20 parallel clients
  3 bytes payload
  keep alive: 1

100.00% <= 0 milliseconds
131578.95 requests per second

====== PING_BULK ======
  5000 requests completed in 0.04 seconds
  20 parallel clients
  3 bytes payload
  keep alive: 1

100.00% <= 0 milliseconds
131578.95 requests per second

====== SET ======
  5000 requests completed in 0.04 seconds
  20 parallel clients
  3 bytes payload
  keep alive: 1

100.00% <= 0 milliseconds
128205.12 requests per second

====== GET ======
  5000 requests completed in 0.04 seconds
  20 parallel clients
  3 bytes payload
  keep alive: 1

100.00% <= 0 milliseconds
131578.95 requests per second

====== INCR ======
  5000 requests completed in 0.04 seconds
  20 parallel clients
  3 bytes payload
  keep alive: 1

100.00% <= 0 milliseconds
131578.95 requests per second

====== LPUSH ======
  5000 requests completed in 0.04 seconds
  20 parallel clients
  3 bytes payload
  keep alive: 1

100.00% <= 0 milliseconds
131578.95 requests per second

====== RPUSH ======
  5000 requests completed in 0.04 seconds
  20 parallel clients
  3 bytes payload
  keep alive: 1

100.00% <= 0 milliseconds
131578.95 requests per second

====== LPOP ======
  5000 requests completed in 0.04 seconds
  20 parallel clients
  3 bytes payload
  keep alive: 1

100.00% <= 0 milliseconds
131578.95 requests per second

====== RPOP ======
  5000 requests completed in 0.04 seconds
  20 parallel clients
  3 bytes payload
  keep alive: 1

100.00% <= 0 milliseconds
131578.95 requests per second

====== SADD ======
  5000 requests completed in 0.04 seconds
  20 parallel clients
  3 bytes payload
  keep alive: 1

100.00% <= 0 milliseconds
131578.95 requests per second

====== HSET ======
  5000 requests completed in 0.04 seconds
  20 parallel clients
  3 bytes payload
  keep alive: 1

100.00% <= 0 milliseconds
135135.14 requests per second

====== SPOP ======
  5000 requests completed in 0.04 seconds
  20 parallel clients
  3 bytes payload
  keep alive: 1

100.00% <= 0 milliseconds
128205.12 requests per second

====== LPUSH (needed to benchmark LRANGE) ======
  5000 requests completed in 0.04 seconds
  20 parallel clients
  3 bytes payload
  keep alive: 1

100.00% <= 0 milliseconds
131578.95 requests per second

====== LRANGE_100 (first 100 elements) ======
  5000 requests completed in 0.04 seconds
  20 parallel clients
  3 bytes payload
  keep alive: 1

100.00% <= 0 milliseconds
128205.12 requests per second

====== LRANGE_300 (first 300 elements) ======
  5000 requests completed in 0.04 seconds
  20 parallel clients
  3 bytes payload
  keep alive: 1

100.00% <= 0 milliseconds
128205.12 requests per second

====== LRANGE_500 (first 450 elements) ======
  5000 requests completed in 0.04 seconds
  20 parallel clients
  3 bytes payload
  keep alive: 1

100.00% <= 0 milliseconds
128205.12 requests per second

====== LRANGE_600 (first 600 elements) ======
  5000 requests completed in 0.04 seconds
  20 parallel clients
  3 bytes payload
  keep alive: 1

100.00% <= 0 milliseconds
128205.12 requests per second

====== MSET (10 keys) ======
  5000 requests completed in 0.04 seconds
  20 parallel clients
  3 bytes payload
  keep alive: 1

100.00% <= 0 milliseconds
135135.14 requests per second

Thats All.