0.1.0 • Published 4 years ago
ascredis v0.1.0
Ascredis
Redis client wrapper with easy-to-use endpoint and async-await support
npm install ascredis
Docker Guide
docker pull redis:latest
docker run -d --name redis -p 6379:6379 redis:latest
How to add test cases and test
Create new file with naming convention *.test.ts in tests directory
# Run this command to test with Jest
npm run test
How to use the library
To create a redis client
import Redis from 'predis';
const client = new Redis('127.0.0.1', 6379);
Key-Value Pair Operations
# Will throw error or return 'Operation SET done with key: <your-key>'
await client.set('testing', 1);
# Will throw error or return the found value
await client.get('testing');
Hashmap Operations
# Will throw error or return 'Operation SET done with key: <your-key>'
await client.hset('testing2', 'count', 100);
# Will throw error or return the found value
await client.hget('testing2', 'count');
Set Operations
await client.sadd('testing', 1);
await client.sadd('testing2', 2);
const scard = await client.scard('testing');
// --> 1
const sdiff = await client.sdiff('testing', ['testing2']);
// --> ['1']
const sinter = await client.sinter('testing', ['testing2']);
// --> []
const sismember = await client.sismember('testing', '1');
// --> true
await client.smove('testing', 'testing2', '1');
const smembers = await client.smembers('testing2');
// --> ['1', '2']
const spop = await client.spop('testing2');
// --> '2'
await client.srem('testing2', '1');
const sunion = await client.sunion(['testing1', 'testing2']);
// --> []
List Operations
await client.lpush('testing', 1);
await client.rpush('testing', 2);
const lrange = await client.lrange('testing', 0, 1000);
// --> ['1', '2']
await client.lpush('testing', 3);
await client.rpush('testing', 4);
const lpop = await client.lpop('testing');
// --> '3'
const rpop = await client.rpop('testing');
// --> '4'
const llen = await client.llen('testing');
// --> 2
await client.rpush('testing', 3);
await client.ltrim('testing', 0, -2);
const lrem = await client.lrem('testing', 0, '2');
// --> 1
const lindex = await client.lindex('testing', 0);
// --> '1'
Pub/Sub Operations
await client.subscribe('testing');
const clientsReceived = await client2.publish('testing', 'hellooooo');
// --> 1
client.getClient().on('message', (_channel, message) => {
console.log(message);
// --> 'hellooooo'
});