noo
noo

Reputation: 41

How to load rejson.so with docker-compose

I want to store json type in Redis, so I set up for using RedisJSON module with docker-compose. But, I keep failing on running it. The code is below. I also tried to use redis.conf that is filled with same parameters as command, but Segmentation fault was occured. What's wrong on my step?

docker-compose.yml

version: '3.8'
services:
  redis:
    container_name: redis
    hostname: redis
    image: redis:7.0.0-alpine
    command: redis-server --loadmodule /etc/redis/modules/rejson.so
    volumes:
      - /etc/redis/redis.conf:/etc/redis/redis.conf
      - /etc/redis/modules/rejson.so:/etc/redis/modules/rejson.so

Environment

Node.js Version: 16.14.1
Node Redis Version: 4.0.6
Platform: Mac OS 12.3.1


Edited

Segmentation fault was because of unexisting includes option. Below messages were repeated. What it means Exec format error?

# oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
# Redis version=7.0.0, bits=64, commit=00000000, modified=0, pid=1, just started
# Configuration loaded
* monotonic clock: POSIX clock_gettime
# Warning: Could not create server TCP listening socket ::1:6380: bind: Address not available
* Running mode=standalone, port=6380.
# Server initialized
# Module /etc/redis/modules/rejson.so failed to load: Error loading shared library /etc/redis/modules/rejson.so: Exec format error
# Can't load module from /etc/redis/modules/rejson.so: server aborting

Upvotes: 4

Views: 5477

Answers (1)

LordOfTheSnow
LordOfTheSnow

Reputation: 326

After a lot of trial and error, I found out that as of this time, the redis v7 docker images seem to lack the rejson module.

I am now using redis/stack-server which already includes all modules (including) rejson. It is based upon redis v6, see:

My compose.yaml now looks like this:

version: "3"

services:
  redis:
    image: redis/redis-stack
    volumes:
      - redis_data:/data:rw
    ports:
      - 6379:6379
    restart: unless-stopped

volumes:
  redis_data:

In the redis-cli you can then give it a try:

127.0.0.1:6379> JSON.SET employee_profile $ '{ "employee": { "name": "alpha", "age": 40,"married": true }  } '
OK
127.0.0.1:6379> JSON.GET employee_profile
"{\"employee\":{\"name\":\"alpha\",\"age\":40,\"married\":true}}"

If you still have Docker volumes from previous installations, you should delete them first. Otherwise your new container might get problems reading an older database.

Upvotes: 8

Related Questions