Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import q from 'q'
- import redisClient, { ClientOpts, RedisClient } from 'redis'
- ./**
- * [✓] Redis Keys
- * [✓] Redis String
- * [✓] Redis Hashes
- * [x] Redis List
- * [x] Redis Sets
- * [x] Redis Sorted Sets
- * [x] Publish Subscribe
- * [x] Redis Transaction
- */
- export class Redis {
- private clientRedis: RedisClient
- constructor(options: ClientOpts) {
- this.clientRedis = redisClient.createClient({ ...options })
- }
- async get(key: string): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.get(key, (err, reply) => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async set(key: string, value: string): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.set(key, value, (err, reply) => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async move(key: string, db: string | number): Promise<Record<string, any>> {
- return q.Promise(() => {
- this.clientRedis.move(key, db)
- })
- }
- async dump(key: string): Promise<Record<string, any>> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.dump(key, (err, reply) => {
- if (err) reject(err)
- resolve({ reply })
- })
- })
- }
- async setex(key: string, second: number, value: string): Promise<Record<string, any>> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.setex(key, second, value, (err, reply) => {
- if (err) reject(err)
- resolve({ reply })
- })
- })
- }
- async setnx(key: string, value: string): Promise<Record<string, any>> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.setnx(key, value, (err, reply) => {
- if (err) reject(err)
- resolve({ reply })
- })
- })
- }
- async expire(key: string, second: number): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.expire(key, second, (err, reply) => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async incrby(key: string, increment: number): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.incrby(key, increment, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async incr(key: string): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.incr(key, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async del(key: string): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.del(key, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async keys(pattern: string): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.keys(pattern, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async ttl(key: string): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.ttl(key, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async expireat(key: string, timestamp: number): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.expireat(key, timestamp, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async decr(key: string): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.decr(key, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async decrby(key: string, decrement: number): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.decrby(key, decrement, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async persist(key: string): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.persist(key, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async scan(arg: any | any[]): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.scan(arg, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async pexpire(key: string, milliseconds: number): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.pexpire(key, milliseconds, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async pexpireat(key: string): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.pttl(key, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async exists(arg: string | string[]): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.exists(arg, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async msetnx(arg: string | string[]): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.msetnx(arg, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async mset(arg: string | string[]): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.mset(arg, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async mget(arg: string | string[]): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.mget(arg, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async rename(key: string, newKey: string): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.rename(key, newKey, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async renamenx(key: string, newKey: string): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.renamenx(key, newKey, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async type(key: string): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.type(key, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async incrbyfloat(key: string, increment: number): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.incrbyfloat(key, increment, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async append(key: string, value: string): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.append(key, value, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async strlen(key: string): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.strlen(key, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async setrange(key: string, offset: number, value: string): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.setrange(key, offset, value, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async getset(key: string, value: string): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.getset(key, value, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async getrange(key: string, start: number, end: number): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.getrange(key, start, end, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async hset(key: string, ...args: any): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.hset(key, args, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async hget(key: string, field: string): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.hget(key, field, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async hgetall(key: string): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.hgetall(key, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async hmset(key: string, args: any): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.hmset(key, args, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async hmget(key: string, args: string | string[]): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.hmget(key, args, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async hdel(key: string, args: string | string[]): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.hdel(key, args, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async hexists(key: string, field: string): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.hexists(key, field, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async hkeys(key: string): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.hkeys(key, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async hlen(key: string): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.hlen(key, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async hincrby(key: string, field: string, increment: number): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.hincrby(key, field, increment, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async hsetnx(key: string, field: string, value: string): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.hsetnx(key, field, value, (err, reply): void => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async hkeys(key: string): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.hkeys(key, (err, reply) => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async hstrlen(key: string, field: string): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.hstrlen(key, field, (err, reply) => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async hvals(key: string): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.hvals(key, (err, reply) => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async hscan(key: string, args: string | string[]): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.hscan(key, args, (err, reply) => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- async hincrbyfloat(key: string, field: string, increment: number): Promise<any> {
- return q.Promise((resolve, reject) => {
- this.clientRedis.hincrbyfloat(key, field, increment, (err, reply) => {
- if (err) reject(err)
- resolve(reply)
- })
- })
- }
- }
Add Comment
Please, Sign In to add comment