redis-dev

2.4.0 • Public • Published

install

npm i redis-dev

start

const port = 6379
const host = '127.0.0.1'
const requirepass = 'foo'
const redis = new RedisDev(port, host, requirepass)

APIs

common

_set

/**
 * Set key and value.
 * 
 * @param {string} pattern - 'string' or 'hash'
 * @param {string} key
 * @param {(string|Object)} fieldOrEntriesOrValue
 * @param {string} [value=undefined]
 * @returns {Promise}
 */
await redis._set('string', 'foo', 'foo') 

await redis._set('hash', 'foo', 'bar', 'bar') // foo: { bar: 'bar' }
await redis._set('hash', 'foo', { // foo: { bar: 'bar', baz: 'baz' }
  bar: 'bar',
  baz: 'baz'
})

_get

/**
 * Get value by key.
 * 
 * @param {string} pattern - 'string' or 'hash'
 * @param {string} key
 * @param {(string|number)} startOrField
 * @param {number} [end=-1]
 * @returns {Promise}
 */
await redis._get('string', 'foo') // output: 'foo'
await redis._get('string', 'foo', 0) // output: 'foo'
await redis._get('string', 'foo', 1) // output: 'oo'
await redis._get('string', 'foo', 0, 1) // output: 'fo'

await redis._get('hash', 'foo') // output: { foo: 'foo', bar: 'bar' }
await redis._get('hash', 'foo', 'foo') // output: 'foo'
await redis._get('hash', 'foo', ['foo', 'bar']) // output: ['foo', 'bar']

_del

/**
 * Remove data by key.
 * 
 * @param {string} pattern - 'string' or 'hash'
 * @param {string} key
 * @param {string} field
 * @returns {Promise}
 */
await redis._del('string', 'foo')

await redis._del('hash', 'foo', 'foo')

flushall

/**
 * Clear all data.
 * 
 * @returns {Promise}
 */
await redis.flushall()

ttl

/**
 * Get the remaining survival time of a data with an expiration time.
 * 
 * @param {string} key - key
 * @returns {Promise}
 */
await redis.ttl(key)

type

/**
 * Get the type of data.
 * 
 * @param {string} key - key
 * @returns {Promise}
 */
await redis.type(key)

keys

/**
 * Get data by pattern.
 * 
 * @param {string} [pattern=*] - pattern
 * @returns {Promise}
 */
await redis.keys('*')

expire

/**
 * Set expiration time.
 * 
 * @param {string} key - key
 * @param {number} expiration - duration time
 * @returns {Promise}
 */
await redis.expire('foo', 60)

subscribe

/**
 * Subscribe channel.
 * 
 * @param {string} channel - channel
 * @param {Function} cb - callback
 * @returns {Promise}
 */
await redis.subscribe('foo', message => console.log(message))

publish

/**
 * Puslish message.
 * 
 * @param {string} channel - channel
 * @param {string} message - message
 * @returns {Promise}
 */
await redis.publisj('foo', 'Published message')

for string

set

/**
 * Set key and value.
 * 
 * @param {string} key - key
 * @param {string} value - value
 * @returns {Promise}
 */
await redis.set('foo', 'foo')

get

/**
 * Get value by key.
 * 
 * @param {string} key - key
 * @returns {Promise}
 */
await redis.get('foo')

getrange

/**
 * Get range value by key.
 * 
 * @param {string} key - key
 * @param {number} start - start index
 * @param {number} [end=-1] - end index
 * @returns {Promise}
 */
await redis.getrange('foo')

del

/**
 * Remove data by key.
 * 
 * @param {string} key - key
 * @returns {Promise}
 */
await redis.del('foo')

for hash

hset

/**
 * Set key and field and value.
 * 
 * @param {string} key - key
 * @param {string} field - field
 * @param {string} value - value
 * @returns {Promise}
 */
await redis.hset('foo', 'foo', 'foo')

hget

/**
 * Get value by field.
 * 
 * @param {string} key - key
 * @param {string} field - field
 * @returns {Promise}
 */
await redis.hget('foo', 'foo')

hmget

/**
 * Get multiple values by fields.
 * 
 * @param {string} key - key
 * @param {...string} fields - fields
 * @returns {Promise}
 */
await redis.hmget('foo', 'foo', 'bar', 'baz')

hgetall

/**
 * Get all fields and values by key.
 * 
 * @param {string} key - key
 * @returns {Promise}
 */
await redis.hgetall('foo')

hdel

/**
 * Remove data by key.
 * 
 * @param {string} key - key
 * @param {string} field - field
 * @returns {Promise}
 */
await redis.hdel('foo', 'foo')

Readme

Keywords

Package Sidebar

Install

npm i redis-dev

Weekly Downloads

10

Version

2.4.0

License

MIT

Unpacked Size

13.4 kB

Total Files

9

Last publish

Collaborators

  • xnorain001