redis-type
Version:
Redis type wrapper
117 lines (116 loc) • 4.34 kB
TypeScript
import { Base } from "./base";
/**
* Wrapper for HASHMAP Redis storage.
* Mocks JavaScript Maps and has most of the Map's methods.
*
* @example
* let human = new Hash(client, 'human', useJSON = true);
* await human.set('alice', { isHuman: 'definitely' });
* await human.set('damir', { isHuman: 'could be' });
*/
export declare class Hash<T> extends Base {
/**
* Get the length of the hash (keys length)
*
* - Redis command: [HLEN] {@link https://redis.io/commands/hlen}
* - JavaScript analogy: [Map.prototype.size] {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size}
*/
size(): Promise<number>;
/**
* Get array of keys in the hash
*
* - Redis command: [HKEYS] {@link https://redis.io/commands/hkeys}
* - JavaScript analogy: [Map.prototype.keys] {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys}
*/
keys(): Promise<string[]>;
/**
* Delete element in hash by it's key
*
* - Redis command: [HDEL] {@link https://redis.io/commands/hdel}
* - JavaScript analogy: [Map.prototype.delete] {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete}
*
* @param {String} key Name of the key to delete
*/
delete(key: string): Promise<void>;
/**
* Check whether key exists in hash
*
* - Redis command: [HEXISTS] {@link https://redis.io/commands/hexists}
* - JavaScript analogy: [Map.prototype.has] {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has}
*
* @param {String} key Key to check
*/
has(key: string): Promise<boolean>;
/**
* Set value under given key
*
* - Redis command: [HSET] {@link https://redis.io/commands/hset}
* - JavaScript analogy: [Map.prototype.set] {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set}
*
* @param {String} key Key to set
* @param {String} value Value to set under given key
*/
set(key: string, value: T): Promise<void>;
/**
* Get value by it's key
*
* - Redis command: [HGET] {@link https://redis.io/commands/hget}
* - JavaScript analogy: [Map.prototype.get] {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get}
*
* @param {String} key Key to get from hash
*/
get(key: string): Promise<T>;
/**
* Get array of values from the hash
*
* - Redis command: [HVALS] {@link https://redis.io/commands/hvals}
* - JavaScript analogy: [Map.prototype.values] {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values}
*/
values(): Promise<T[]>;
/**
* Returns 2-dimensional array of kind:
*
* ```JavaScript
* [[key1, value1], [key2, value2]]
* ```
* To support Object to Map transformation
*
* - Redis command: [HGETALL] {@link https://redis.io/commands/hgetall}
* - JavaScript analogy: [Map.prototype.entries] {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries}
*
*/
entries(): Promise<[string, T][]>;
/**
* Get multiple keys by passing an array of keys
* This command has no analogy in JS
*
* - Redis command: [HMGET] {@link https://redis.io/commands/hmget}
* - JavaScript analogy: none
*
* @param {String[]} keys Keys to get values for
*/
getMul(keys: string[]): Promise<T[]>;
/**
* Returns object representing hash structure
* This command has no analogy in JS
*
* - Redis command: [HGETALL] {@link https://redis.io/commands/hgetall}
* - JavaScript analogy: none
*/
getAll(): Promise<{
[key: string]: T;
}>;
/**
* Set multiple keys by passing an object with key-value structure
* This command has no analogy in JS
*
* - Redis command: [HMSET] {@link https://redis.io/commands/hmset}
* - JavaScript analogy: none
*
* @param {Object} valuesObj Object with key-value pairs to set
* @returns {Promise}
*/
setMul(valuesObj: {
[key: string]: T;
}): any;
}