H5P-Nodejs-Library
  • README
  • Basic usage
    • Architecture
    • Integrating the core library
    • H5P Ajax Endpoints
    • Constructing H5PEditor
    • REST Example
  • Advanced usage
    • Authorization
    • User content state
    • Multiple user states per object
    • Impersonating users
    • Basic completion tracking
    • Localization
    • Cluster
    • Addons
    • Customization
    • Performance optimizations
    • Privacy
    • Forward proxy support
    • Security
  • NPM packages
    • h5p-mongos3
      • Mongo/S3 Content Storage
      • S3 Temporary File Storage
      • Mongo Library Storage
      • Mongo/S3 Library Storage
    • h5p-webcomponents
    • h5p-react
    • h5p-redis-lock
    • h5p-svg-sanitizer
    • h5p-clamav-scanner
  • Development
    • Getting started
    • Testing & code quality
    • Core updates
    • Project Status
Powered by GitBook
On this page

Was this helpful?

  1. NPM packages

h5p-redis-lock

This package provides a lock mechanism that can be used if the library runs in multi-process or cluster-mode. The locks are needed to avoid race conditions when installing libraries.

import { createClient } from '@redis/client';
import { H5PEditor, H5PPlayer } from '@lumieducation/h5p-server';
import RedisLockProvider from '@lumieducation/h5p-redis-lock';

// Create a regular redis connection
const redisClient = createClient({
    socket: {
        port,
        host,
    },
    database
});
try {
    await redisClient.connect();
}
catch (error) {
    // handle error
}

// Create the lock provider
const lockProvider = new RedisLockProvider(redisClient);

// Pass it to the editor and player object
const h5pEditor = new H5PEditor( /*other parameters*/, options: { lockProvider } );
const h5pPlayer = new H5PPlayer( /*other parameters*/, options: { lockProvider } );

It is important to make sure that all instances of H5PEditor use a redis lock provider that points to the same database. Otherwise race conditions can happen.

Previoush5p-reactNexth5p-svg-sanitizer

Last updated 2 months ago

Was this helpful?