# 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.

```ts
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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.lumi.education/npm-packages/h5p-redis-lock.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
