{"id":18470366,"url":"https://github.com/aliencreations/alien-node-redis-utils","last_synced_at":"2026-01-30T14:19:50.380Z","repository":{"id":35275097,"uuid":"39535890","full_name":"AlienCreations/alien-node-redis-utils","owner":"AlienCreations","description":"Helper functions for Redis on NodeJS","archived":false,"fork":false,"pushed_at":"2023-09-13T21:21:34.000Z","size":37,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-10T17:15:13.692Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlienCreations.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2015-07-22T23:52:57.000Z","updated_at":"2023-09-13T15:09:07.000Z","dependencies_parsed_at":"2025-05-17T14:34:44.120Z","dependency_job_id":"d1ad7b65-f948-4c08-9a26-40947e26d2c7","html_url":"https://github.com/AlienCreations/alien-node-redis-utils","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AlienCreations/alien-node-redis-utils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlienCreations%2Falien-node-redis-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlienCreations%2Falien-node-redis-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlienCreations%2Falien-node-redis-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlienCreations%2Falien-node-redis-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlienCreations","download_url":"https://codeload.github.com/AlienCreations/alien-node-redis-utils/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlienCreations%2Falien-node-redis-utils/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28914045,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-30T12:13:43.263Z","status":"ssl_error","status_checked_at":"2026-01-30T12:13:22.389Z","response_time":66,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T10:13:44.215Z","updated_at":"2026-01-30T14:19:50.363Z","avatar_url":"https://github.com/AlienCreations.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# alien-node-redis-utils\nHelper functions for Redis cache on NodeJS. The functions are pure and curried with Ramda.\n\n[![Build Status](https://travis-ci.org/AlienCreations/alien-node-redis-utils.svg?branch=master)](https://travis-ci.org/AlienCreations/alien-node-redis-utils) [![Coverage Status](https://coveralls.io/repos/AlienCreations/alien-node-redis-utils/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/AlienCreations/alien-node-redis-utils?branch=master) [![npm version](http://img.shields.io/npm/v/alien-node-redis-utils.svg)](https://npmjs.org/package/alien-node-redis-utils) [![Dependency Status](https://david-dm.org/AlienCreations/alien-node-redis-utils.svg)](https://david-dm.org/AlienCreations/alien-node-redis-utils)\n\n## Install\n\n```\n$ npm install alien-node-redis-utils --save\n```\n\nRun the specs\n\n```\n$ npm test\n```\n\n## Methods\n\n#### getItem\nGet an item from the Redis store, provided a recognized `cacheKey`\n\n```js\n\nvar redis       = require('redis'),\n    redisClient = redis.createClient(),\n    cacheUtils  = require('alien-node-redis-utils')(redisClient);\n    \ncacheUtils.getItem('someKey')\n  .then(function(item) {\n    // cool\n  })\n  .catch(function(err) {\n    // no item found matching cacheKey\n  });\n\n```\n\n#### setItem\nSet an item in the Redis store. Adds if key does not exist, otherwise updates the cache.\n\n```js\n\nvar redis       = require('redis'),\n    redisClient = redis.createClient(),\n    cacheUtils  = require('alien-node-redis-utils')(redisClient);\n    \nvar TWO_HOURS_IN_SECONDS_CACHE_EXPIRE = 1000 * 60 * 60 * 2;\n\nvar cacheKey = 'someKey', \n    data     = { foo : 'bar' };\n    \ncacheUtils.setItem(cacheKey, TWO_HOURS_IN_SECONDS_CACHE_EXPIRE, data);\n  .then(function(data) {\n    // cool\n  });\n\n```\n\n#### deleteItem\nDelete an item from the Redis store, provided a recognized `cacheKey`\n\n```js\n\nvar redis       = require('redis'),\n    redisClient = redis.createClient(),\n    cacheUtils  = require('alien-node-redis-utils')(redisClient);\n\ncacheUtils.deleteItem('someKey')\n  .then(function() {\n    // cool\n  })\n  .catch(function(err) {\n    // some err from redisClient\n  });\n\n```\n\n## Helpers\n\n#### maybeAddToQueryCache\nChecks for an existing record matching `cacheKey` and appends/prepends `item`\n\n```js\n\nvar User = require('/path/to/user/model'),\n    data = {name : 'joe'};\n\nvar redis       = require('redis'),\n    redisClient = redis.createClient(),\n    cacheUtils  = require('alien-node-redis-utils')(redisClient);\n\nvar CACHE_KEY    = 'api.users',\n    CACHE_EXPIRE = 1000 * 60 * 60 * 24;\n\nreturn User.create(data).then(function(user) {\n  return cacheUtils.maybeAddToQueryCache(CACHE_KEY, CACHE_EXPIRE, user);\n});\n\n```\n\n#### pluckFromQueryCache\nChecks for an existing record matching `cacheKey`, looks for an item matching a\n provided `identifierProperty`, removes the item and resets the cache.\n\n```js\n\nvar User = require('/path/to/user/model'),\n    data = {id : 123};\n\nvar redis       = require('redis'),\n    redisClient = redis.createClient(),\n    cacheUtils  = require('alien-node-redis-utils')(redisClient);\n\nvar CACHE_KEY   = 'api.users';\n\nreturn User.delete(data)\n  .thenResolve(data)\n  .then(cacheUtils.pluckFromQueryCache(CACHE_KEY, 'id');\n\n```\n\n\n#### setOrDeleteCacheBucket\nChecks for an existing record matching `cacheKey`, and sets it to `items` if `items` \nis a populated list. If `items` is falsy or an empty array, `cacheKey` will be deleted.\n\n```js\n\n// See internal usage from pluckFromQueryCache method: \n\nvar pluckFromQueryCache = R.curry(function(redisClient, cacheKey, identifierProperty, item) {\n  return getItem(redisClient, cacheKey)\n    .then(JSON.parse)\n    .then(R.defaultTo([]))\n    .then(listUtils.filterOutObject(identifierProperty, R.prop(identifierProperty, item)))\n    .then(setOrDeleteCacheBucket(redisClient, cacheKey))\n    .thenResolve(item)\n    .catch(R.always(item));\n});\n\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faliencreations%2Falien-node-redis-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faliencreations%2Falien-node-redis-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faliencreations%2Falien-node-redis-utils/lists"}