Skip to content

Commit

Permalink
Allow Redis client as argument for storage
Browse files Browse the repository at this point in the history
  • Loading branch information
paulomarg committed Aug 12, 2024
1 parent bdb7817 commit 25dc094
Show file tree
Hide file tree
Showing 5 changed files with 305 additions and 154 deletions.
5 changes: 5 additions & 0 deletions .changeset/grumpy-kings-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/shopify-app-session-storage-redis': minor
---

Added support for passing in a `RedisClient` instance as argument in addition to connection URL.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

This package implements the `SessionStorage` interface that works with an instance of [Redis](https://redis.io/).

You can create an instance of `RedisSessionStorage` in several ways:

## Using a connection URL

```js
import {shopifyApp} from '@shopify/shopify-app-express';
import {RedisSessionStorage} from '@shopify/shopify-app-session-storage-redis';
Expand All @@ -12,18 +16,22 @@ const shopify = shopifyApp({
),
// ...
});
```

// OR
## Using a URL object

```js
const shopify = shopifyApp({
sessionStorage: new RedisSessionStorage(
new URL('redis://username:password@host/database'),
),
// ...
});
```

// OR
## Using credential components

```js
const shopify = shopifyApp({
sessionStorage: RedisSessionStorage.withCredentials(
'host.com',
Expand All @@ -35,4 +43,20 @@ const shopify = shopifyApp({
});
```

## Using a RedisClient instance

> [!NOTE]
> Remember that `RedisSessionStorage` will connect to the database, but won't disconnect from it.
> If you need to restart the connection, you'll need to manually connect again for the storage to continue working.
```js
import {RedisClientOptions, createClient} from 'redis';
const client = createClient({url: 'redis://username:password@host/database'});

const shopify = shopifyApp({
sessionStorage: new RedisSessionStorage(client),
// ...
});
```

If you prefer to use your own implementation of a session storage mechanism that is compatible with the `@shopify/shopify-app-express` package, see the [implementing session storage guide](../shopify-app-session-storage/implementing-session-storage.md).
Loading

0 comments on commit 25dc094

Please sign in to comment.