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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@invertase/genkit-plugin-redis

v0.0.1

Published

A Redis Plugin for Firebase GenKit that integrates Redis for state storage, trace storage, caching, and rate limiting.

Downloads

4

Readme


About

This plugin facilitates seamless interaction with Redis in GenKit for storing flow states and traces, managing cached data, and implementing rate limiting mechanisms, enhancing the scalability and performance of applications built with the GenKit AI framework.

npm install @invertase/genkit-plugin-redis

Examples

See the examples directory for sample code demonstrating how to use the Redis plugin in a GenKit application.

API Reference

redis

Initializes the Redis plugin.

import { configureGenkit } from "@genkit-ai/core";
import { redis } from "@invertase/genkit-plugin-redis";

configureGenkit({
  plugins: [
    redis({
      // Tell the plugin where to connect, if not provided
      // it defaults to localhost:6379 as below:
      // connectionString: "redis://localhost:6379",

      // Optional
      flowStateStore: {
        // The Redis key to use for storing flow states.
        storageKey: "flowState",
      },

      // Optional
      traceStore: {
        // The Redis key to use for storing trace data.
        storageKey: "trace",
      },
    }),
  ],
  enableTracingAndMetrics: true,
  // Tell GenKit to use the Redis plugin for flow state.
  flowStateStore: "redis",
  // Tell GenKit to use the Redis plugin for trace data.
  traceStore: "redis",
});

Parameters:

  • params (optional): RedisPluginParams configuration for initializing the Redis client.

Returns:

  • An object containing:
    • flowStateStore: An instance of RedisFlowStateStore.
    • traceStore: An instance of RedisTraceStore.

Store Operations

clearTraceStore

Clears all entries in the trace store. Caution: This will delete all traces from the store.

Usage:

await clearTraceStore();

clearFlowStore

Clears all entries in the flow state store. Caution: This will delete all flow states from the store.

Usage:

await clearFlowStore();

Cache Operations

clearCache

Clears all values from the cache or those matching a specific prefix.

Parameters:

  • prefix (optional): A string prefix to filter which keys to clear from the cache. If not provided, all keys will be deleted.

Usage:

await clearCache(prefix);

cacheSet

Sets a value in the cache.

Parameters:

  • key: The key to set in the cache.
  • value: The value to set in the cache. If null, the key will be deleted from the cache.
  • ttlSeconds (optional): The time to live for the key in seconds. If not provided, the key will not expire.

Usage:

await cacheSet(key, value, ttlSeconds);

cacheGet

Gets a value from the cache.

Parameters:

  • key: The key to get from the cache.

Returns:

  • The value from the cache, or null if the key does not exist or has expired.

Usage:

const value = await cacheGet<T>(key);

cacheFunction

Caches the result of a function.

Parameters:

  • key: The key to cache the result under.
  • fn: The callback function to execute and cache the result of.
  • ttlSeconds (optional): The time to live for the cached result in seconds. If not provided, the result will not expire.

Returns:

  • The result of the cached function.

Usage:

const result = await cacheFunction(key, () => myFunction(), ttlSeconds);

Rate Limiting Operations

rateLimit

Checks if a rate limit is exceeded for a given identifier. This counts as a single request for the given identifier.

Parameters:

  • identifier: The identifier to check the rate limit for, e.g., a user ID or a session ID.
  • limit: The maximum number of requests allowed in a given time period.
  • limitIntervalSeconds: The time period in seconds for which the limit is applied.

Returns:

  • true if the rate limit is exceeded, false otherwise.

Usage:

const isRateLimited = await rateLimit(identifier, limit, limitIntervalSeconds);

rateLimitWithStatus

Checks the rate limit status for a given identifier. This counts as a single request for the given identifier.

Parameters:

  • identifier: The identifier to check the rate limit for, e.g., a user ID or a session ID.
  • limit: The maximum number of requests allowed in a given time period.
  • limitIntervalSeconds: The time period in seconds for which the limit is applied.

Returns:

  • The rate limit status for the identifier.

Usage:

const status = await rateLimitWithStatus(
  identifier,
  limit,
  limitIntervalSeconds,
);

resetRateLimit

Resets the rate limit for a given identifier.

Parameters:

  • identifier: The identifier to reset the rate limit for, e.g., a user ID or a session ID.

Usage:

await resetRateLimit(identifier);

clearRateLimits

Clears all rate limits.

Usage:

await clearRateLimits();