Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix redis types #262

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 40 additions & 12 deletions src/redis.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,37 @@
//@ts-ignore
import * as spinRedis from 'fermyon:spin/[email protected]';

export type payload = Uint8Array;
export type redisParameter = number | Uint8Array;
export type redisResult = number | Uint8Array | null | string;
export type Payload = Uint8Array;
export type RedisParameter = RedisParameterInt64 | RedisParameterBinary;
export interface RedisParameterInt64 {
tag: 'int64';
val: bigint;
}
export interface RedisParameterBinary {
tag: 'binary';
val: Payload;
}

export type RedisResult =
| RedisResultNil
| RedisResultStatus
| RedisResultInt64
| RedisResultBinary;
export interface RedisResultNil {
tag: 'nil';
}
export interface RedisResultStatus {
tag: 'status';
val: string;
}
export interface RedisResultInt64 {
tag: 'int64';
val: bigint;
}
export interface RedisResultBinary {
tag: 'binary';
val: Payload;
}

/**
* Interface representing a Redis connection with various methods for interacting with Redis.
Expand All @@ -16,29 +44,29 @@ export interface RedisConnection {
* @param {payload} payload - The message payload.
* @returns {void}
*/
publish: (channel: string, payload: payload) => void;
publish: (channel: string, payload: Payload) => void;

/**
* Get a value for the given key. Returns null if the key does not exist.
* @param {string} key - The key to retrieve the value for.
* @returns {payload | null}
* @returns {Payload | null}
*/
get: (key: string) => payload | null;
get: (key: string) => Payload | undefined;

/**
* Set a value for the given key.
* @param {string} key - The key to set the value for.
* @param {payload} value - The value to set.
* @param {Payload} value - The value to set.
* @returns {void}
*/
set: (key: string, value: payload) => void;
set: (key: string, value: Payload) => void;

/**
* Increment the value of a key.
* @param {string} key - The key to increment.
* @returns {number}
*/
incr: (key: string) => number;
incr: (key: string) => bigint;

/**
* Deletes the given key.
Expand Down Expand Up @@ -73,10 +101,10 @@ export interface RedisConnection {
/**
* Execute an arbitrary Redis command and receive the result.
* @param {string} command - The Redis command to execute.
* @param {redisParameter[]} args - The arguments for the Redis command.
* @returns {redisResult[]}
* @param {RedisParameter[]} args - The arguments for the Redis command.
* @returns {RedisResult[]}
*/
execute: (command: string, args: redisParameter[]) => redisResult[];
execute: (command: string, args: RedisParameter[]) => RedisResult[];
}

/**
Expand Down
Loading