Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from ong-bitcoin-argentina/vus-123/crear-servi…
…cio-redis [VUS-123] Crear servicio para Redis
- Loading branch information
Showing
3 changed files
with
64 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const redis = require('redis'); | ||
const { REDIS_URI } = require('../constants/Constants'); | ||
const { missingKey, missingValue } = require('../constants/serviceErrors'); | ||
|
||
const client = redis.createClient(REDIS_URI); | ||
|
||
(async () => { | ||
await client.connect(); | ||
})(); | ||
|
||
const get = async (key) => { | ||
if (!key) throw missingKey; | ||
try { | ||
const value = await client.get(key); | ||
return value; | ||
} catch (err) { | ||
return err; | ||
} | ||
}; | ||
|
||
const set = async (key, value) => { | ||
if (!key) throw missingKey; | ||
if (!value) throw missingValue; | ||
try { | ||
const response = await client.setEx(key, 864000, value); | ||
return response; | ||
} catch (err) { | ||
return err; | ||
} | ||
}; | ||
|
||
const del = async (key) => { | ||
if (!key) throw missingKey; | ||
try { | ||
const response = await client.del(key); | ||
return response; | ||
} catch (err) { | ||
return err; | ||
} | ||
}; | ||
|
||
const disconnect = () => { | ||
return client.disconnect(); | ||
}; | ||
|
||
module.exports = { | ||
get, | ||
set, | ||
del, | ||
disconnect, | ||
}; |