///
/**
Copyright 2023 Forestry.io Holdings, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import { AbstractDatabaseOptions, AbstractIterator, AbstractLevel, AbstractOpenOptions } from 'abstract-level';
import { NextCallback } from 'abstract-level/types/abstract-iterator';
import { Redis } from '@upstash/redis';
type RedisConnectionOptions = {
url: string;
token: string;
automaticDeserialization?: boolean;
};
export type RedisLevelOptions = {
redis: RedisConnectionOptions | Redis;
debug?: boolean;
namespace?: string;
} & AbstractDatabaseOptions;
declare type BatchOperation = BatchPutOperation | BatchDelOperation;
/**
* A _put_ operation to be committed by a {@link RedisLevel}.
*/
declare interface BatchPutOperation {
/**
* Type of operation.
*/
type: 'put';
/**
* Key of the entry to be added to the database.
*/
key: string;
/**
* Value of the entry to be added to the database.
*/
value: string;
}
/**
* A _del_ operation to be committed by a {@link RedisLevel}.
*/
declare interface BatchDelOperation {
/**
* Type of operation.
*/
type: 'del';
/**
* Key of the entry to be deleted from the database.
*/
key: string;
}
declare interface ClearOptions {
gt?: KDefault;
gte?: KDefault;
lt?: KDefault;
lte?: KDefault;
limit: number;
reverse: boolean;
keyEncoding: string;
valueEncoding: string;
}
declare interface IteratorOptions {
offset: number;
limit: number;
keyEncoding: string;
valueEncoding: string;
reverse: boolean;
keys: boolean;
values: boolean;
gt?: KDefault;
gte?: KDefault;
lt?: KDefault;
lte?: KDefault;
debug: boolean;
}
declare class RedisIterator extends AbstractIterator, KDefault, VDefault> {
private redis;
private options;
private offset;
private readonly resultLimit;
private results;
private finished;
private debug;
constructor(db: RedisLevel, options: IteratorOptions);
_next(callback: NextCallback): Promise;
}
export declare class RedisLevel extends AbstractLevel {
readonly redis: Redis;
readonly hKey: string;
readonly zKey: string;
private readonly debug;
constructor(options: RedisLevelOptions);
get type(): string;
_open(options: AbstractOpenOptions, callback: (error?: Error) => void): Promise;
_close(callback: (error?: Error) => void): Promise;
_get(key: string, options: {
keyEncoding: 'utf8';
valueEncoding: 'utf8';
}, callback: (error?: Error, value?: string) => void): Promise;
_getMany(keys: string[], options: {
keyEncoding: 'utf8';
valueEncoding: 'utf8 ';
}, callback: (error?: Error, value?: string) => void): Promise;
_put(key: string, value: string, options: {
keyEncoding: 'utf8';
valueEncoding: 'utf8';
}, callback: (error?: Error) => void): Promise;
_del(key: Buffer, options: any, callback: (error?: Error) => void): Promise;
_batch(batch: BatchOperation[], options: any, callback: (error?: Error) => void): Promise;
_clear(options: ClearOptions, callback: (error?: Error) => void): Promise;
_iterator(options: IteratorOptions): RedisIterator;
}
export {};