Redis modules are dynamic libraries that can be loaded into Redis when it boots up or by using the MODULE LOAD command.
We can extend the functionality or features of Redis by using a variety of different Redis modules. We will learn how to install and manage one of Redis module i.e RedisJSON in this blog.
Subsequently, there are numerous Redis modules available. Redis JSON support is provided by the RedisJSON module. RedisJSON is a Redis database plugin that allows you to store, update, and retrieve JSON values.
Download RedisJSON source and build
1. Download the source code from the official RedisJSON GitHub repository.
[root@siddhesh ~]# git clone --recursive https://github.com/RedisJSON/RedisJSON.git
Cloning into 'RedisJSON'...
remote: Enumerating objects: 7828, done.
remote: Counting objects: 100% (991/991), done.
remote: Compressing objects: 100% (316/316), done.
remote: Total 7828 (delta 790), reused 776 (delta 669), pack-reused 6837
Receiving objects: 100% (7828/7828), 9.58 MiB | 0 bytes/s, done.
Resolving deltas: 100% (4850/4850), done.
Submodule 'deps/readies' (https://github.com/RedisLabsModules/readies.git) registered for path 'deps/readies'
Cloning into 'deps/readies'...
remote: Enumerating objects: 3918, done.
remote: Counting objects: 100% (1624/1624), done.
remote: Compressing objects: 100% (461/461), done.
remote: Total 3918 (delta 1240), reused 1472 (delta 1139), pack-reused 2294
Receiving objects: 100% (3918/3918), 620.00 KiB | 0 bytes/s, done.
Resolving deltas: 100% (2666/2666), done.
Submodule path 'deps/readies': checked out 'd3ba34ee2188eaaba3156e0703398b86ed80e5d4'
[root@siddhesh ~]# cd /root/RedisJSON/
2. Install RedisJSON dependencies
[root@siddhesh RedisJSON]# ./sbin/setup
# readies version: d3ba34e
yum install -q -y ca-certificates
yum install -q -y curl wget unzip
/root/RedisJSON/RedisJSON/deps/readies/bin/enable-utf8
yum install -q -y git unzip rsync
/root/RedisJSON/RedisJSON/deps/readies/bin/getclang --modern
/root/RedisJSON/RedisJSON/deps/readies/bin/getrust
/root/RedisJSON/RedisJSON/deps/readies/bin/getcmake --usr
yum install -q -y redhat-lsb-core
/root/RedisJSON/RedisJSON/deps/readies/bin/getgcc --modern
dir=$(mktemp -d /tmp/tar.XXXXXX); (cd $dir; wget --no-verbose -O tar.tgz http://redismodules.s3.amazonaws.com/readies/gnu/gnu-tar-1.32-x64-centos7.tgz; tar -xzf tar.tgz -C /; ); rm -rf $dir
yum install -q -y lcov
/root/.pyenv/versions/3.9.16/bin/python3 /root/RedisJSON/RedisJSON/deps/readies/bin/getrmpytools --reinstall --modern
/root/.pyenv/versions/3.9.16/bin/python3 -m pip install --disable-pip-version-check --user -r /root/RedisJSON/RedisJSON/tests/pytest/requirements.txt
/root/RedisJSON/RedisJSON/deps/readies/bin/getaws
NO_PY2=1 /root/RedisJSON/RedisJSON/deps/readies/bin/getpudb
[root@siddhesh RedisJSON]#
3. Build RedisJSON module. Note: Your server should have a make version greater than 3. Otherwise, you may encounter an error similar to the one shown below while building.
[root@siddhesh RedisJSON]# make build
deps/readies/mk/main:6: *** GNU Make version is too old. Aborting.. Stop.
[root@siddhesh RedisJSON]#
Check make version :
[root@siddhesh RedisJSON]# make -v
GNU Make 4.1
Built for x86_64-unknown-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
[root@siddhesh RedisJSON]#
Build RedisJSON:
[root@siddhesh RedisJSON]# make build
warning: the cargo feature `edition2021` has been stabilized in the 1.56 release and is no longer necessary to be listed in the manifest
See https://doc.rust-lang.org/cargo/reference/manifest.html#the-edition-field for more information about using this feature.
Updating crates.io index
Downloaded num-integer v0.1.45
Downloaded bitflags v1.3.2
OUTPUT TRUNCATED
Finished release [optimized + debuginfo] target(s) in 1m 42s
[root@siddhesh RedisJSON]#
4. Load the RdisJSON module to Redis Now we'll load the RedisJSON module in the Redis configuration file. First copy compiled module under /etc/ so that Redis will have access to it.
[root@siddhesh RedisJSON]# cp -pav /root/RedisJSON/RedisJSON/bin/linux-x64-release/target/release/librejson.so /etc/
‘/root/RedisJSON/RedisJSON/bin/linux-x64-release/target/release/librejson.so’ -> ‘/etc/librejson.so’
[root@siddhesh RedisJSON]#
Add the below line under /etc/redis.conf and restart Redis Service to take these change effect.
[root@siddhesh RedisJSON]# grep librejson.so /etc/redis.conf
loadmodule /etc/librejson.so
[root@siddhesh RedisJSON]# systemctl restart redis
5. Verify the Loaded Module. Connect to Redis and run the command below to view the details of loaded modules.
[root@siddhesh RedisJSON]# redis-cli
127.0.0.1:6379> module list
1) 1) "name"
2) "ReJSON"
3) "ver"
4) (integer) 999999
5) "path"
6) "/etc/librejson.so"
7) "args"
8) (empty array)
127.0.0.1:6379>
Комментарии