npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

expo-redis-client

v0.1.6

Published

React native redis client

Readme

Expo Redis Client

A native Redis client module for Expo and React Native applications on Android. This module provides a simple and efficient way to interact with Redis servers, supporting pub/sub, pattern subscriptions, and more.

Note: Currently, this module only supports Android platforms. iOS support is planned for future releases.

Features

  • ✅ Connect to Redis servers with secure authentication
  • ✅ Publish and subscribe to Redis channels
  • ✅ Pattern-based subscription support
  • ✅ Robust error handling with helpful error messages
  • ✅ Android toast notifications for errors
  • ✅ TypeScript definitions included
  • ✅ Works in Expo managed and bare workflow

Installation

# Using npm
npm install expo-redis-client

# Using Yarn
yarn add expo-redis-client

# Using Expo
expo install expo-redis-client

For Expo managed workflow projects, you need to rebuild your app:

expo prebuild

Usage

Connecting to Redis

import RedisClient, { RedisConfig } from 'expo-redis-client';

// Connect using configuration object
const config: RedisConfig = {
  host: 'your-redis-server.com',
  port: 6379,
  password: 'your-password', // Optional
  useSSL: true, // Optional, defaults to false
  database: 0 // Optional, defaults to 0
};

async function connectToRedis() {
  try {
    await RedisClient.connect(config);
    console.log('Connected to Redis!');
  } catch (error) {
    console.error('Failed to connect:', error);
  }
}

// Or connect using a URL string
async function connectWithUrl() {
  try {
    await RedisClient.connectWithUrl('redis://username:[email protected]:6379/0');
    console.log('Connected to Redis!');
  } catch (error) {
    console.error('Failed to connect:', error);
  }
}

Publishing Messages

async function publishMessage() {
  try {
    const result = await RedisClient.publish('channel-name', 'Hello from Expo!');
    console.log(result); // Shows delivery status
  } catch (error) {
    console.error('Failed to publish:', error);
  }
}

Subscribing to Channels

async function subscribeToChannel() {
  try {
    // Subscribe to one or more channels
    await RedisClient.subscribe('channel-name');
    // or multiple channels
    await RedisClient.subscribe(['channel-1', 'channel-2']);
    
    // Add a listener for messages
    const removeListener = RedisClient.addMessageListener((channel, message) => {
      console.log(`Received message from ${channel}:`, message);
    });
    
    // Later, when you want to stop listening
    removeListener();
    
    // Unsubscribe when done
    await RedisClient.unsubscribe('channel-name');
  } catch (error) {
    console.error('Subscription error:', error);
  }
}

Pattern Subscriptions

async function subscribeToPattern() {
  try {
    // Subscribe to a pattern (e.g., all channels starting with "user:")
    await RedisClient.psubscribe('user:*');
    
    // Add a pattern message listener
    const removeListener = RedisClient.addPatternMessageListener((pattern, channel, message) => {
      console.log(`Pattern ${pattern} matched channel ${channel}:`, message);
    });
    
    // Later, when you want to stop listening
    removeListener();
    
    // Unsubscribe when done
    await RedisClient.punsubscribe('user:*');
  } catch (error) {
    console.error('Pattern subscription error:', error);
  }
}

Disconnecting

async function disconnect() {
  try {
    await RedisClient.disconnect();
    console.log('Disconnected from Redis');
  } catch (error) {
    console.error('Disconnect error:', error);
  }
}

Safe Execution Wrapper

// Use the safeExecute helper for custom operations with built-in error handling
async function doSomethingWithRedis() {
  try {
    const result = await RedisClient.safeExecute(async () => {
      await RedisClient.subscribe('my-channel');
      return await RedisClient.publish('my-channel', 'Hello');
    });
    console.log('Operation completed:', result);
  } catch (error) {
    // Error already handled with toast notification
    // Additional error handling if needed
  }
}

API Reference

Configuration

interface RedisConfig {
  host: string;
  port: number;
  password?: string;
  useSSL?: boolean;
  database?: number;
}

Methods

| Method | Description | |--------|-------------| | connect(config: RedisConfig) | Connect to a Redis server using a configuration object | | connectWithUrl(url: string) | Connect to a Redis server using a URL string | | disconnect() | Disconnect from the Redis server | | publish(channel: string, message: string) | Publish a message to a Redis channel | | subscribe(channels: string \| string[]) | Subscribe to one or more Redis channels | | unsubscribe(channels: string \| string[]) | Unsubscribe from one or more Redis channels | | psubscribe(patterns: string \| string[]) | Subscribe to one or more Redis patterns | | punsubscribe(patterns: string \| string[]) | Unsubscribe from one or more Redis patterns | | addMessageListener(callback) | Add a listener for channel messages | | addPatternMessageListener(callback) | Add a listener for pattern messages | | removeAllMessageListeners() | Remove all channel message listeners | | removeAllPatternMessageListeners() | Remove all pattern message listeners | | isConnectedToRedis() | Check if client is currently connected | | safeExecute(operation) | Safely execute a Redis operation with error handling |

Error Handling

The client includes robust error handling with toast notifications. Errors will display as Android toast messages.

You can also handle errors manually:

try {
  await RedisClient.connect(config);
} catch (error) {
  if (error instanceof Error) {
    // Handle specific error
    console.error('Connection error:', error.message);
  }
}

Requirements

  • Expo SDK 45 or later
  • Android API level 21 or later

Under the Hood

This module uses the Lettuce Redis client for Android.

License

MIT