Redis
Redis module built with ioredis
#
Installation#
Optionskey | Description | Type | Default |
---|---|---|---|
id | redisProvider injection id | string | redisProvider |
connection | redis connection string | string | null |
opts | redis connection options | object | {} |
scripts | redis lua scripts | object | {} |
#
Scrips Optionskey | Description | Type | Default |
---|---|---|---|
name | name of the script | string | `` |
path | path of the script | string | `` |
lua | path or the lua string | string | `` |
args | number of script arguments | number | 0 |
in config/modules/all.ts
#
Usage#
RedisProvider#
getget<T>(key: string): Promise<T>
#
get item from redis by key
#
setset<T>(key: string, value: T): Promise<T>
#
set value by key the value converted to string with JSON.stringify
before set
#
getAllHashgetAllHash<T>(key: string): Promise<{ [index: string]: T }>
#
get all items in hash map in key value object
#
getHashKeysgetHashKeys<T>(key: string): Promise<string[]>
#
get all hash keys as array
#
getHashValuesgetHashValues<T>(key: string): Promise<T[]>
#
get all hash value as array
#
getByExpiregetByExpire<T>(key: string, expire: number): Promise<{ value: T, validExpire: boolean }>
#
get item by key with expire if current ttl is less then expire/2 then validExpire will be false
#
setHashsetHash<T>(hashMap: string, key: string, value: T): Promise<T>
#
set value in hash map
#
getHashgetHash<T>(hashMap: string, key: string): Promise<T>
#
get value from hash map
#
delHashdelHash(hashMap: string, ...keys: string[]): Promise<void>
#
delete value from hash map
#
deldel(...keys: string[]): Promise<void>
#
delete item by key
#
delPatterndelPattern(pattern: string): Promise<void>
#
delete item by pattern
#
setWithExpiresetWithExpire<T>(key: string, value: T, seconds: number): Promise<T>
#
set item with expire in seconds
#
expireexpire(key: string, seconds: number): Promise<void>
#
set key expire in seconds
#
scanscan(pattern: string): Promise<string[]>
#
return array for keys
#
scanHashscanHash<T>(key: string, pattern: string = '*'): Promise<{ [index: string]: T }>
#
return hash keys by pattern in key value object
#
scanHashValuesscanHashValues<T>(key: string, pattern: string = '*'): Promise<T[]>
#
return hash values by pattern in array
#
ttlttl(key: string): Promise<number>
#
return key ttl
#
incrementincrement(key: string, count: number = 1): Promise<void>
#
increment value by count
#
incrementExpireincrementExpire(key: string, seconds: number, count: number = 1): Promise<void>
#
increment value by count and expire in seconds
#
locklock(key: string, seconds: number, updateLockTime: boolean = false): Promise<boolean>
#
return true if value locked, if not lock it for x seconds
#
unlockunlock(key: string): Promise<void>
#
unlock key
#
runScriptrunScript<T>(name: string, keys: string[], values: any[], parse: boolean = true): Promise<T>
#
run lua script by script name