{"id":16223714,"url":"https://github.com/lykmapipo/redis-hashes","last_synced_at":"2025-04-03T04:30:38.472Z","repository":{"id":57349731,"uuid":"102279629","full_name":"lykmapipo/redis-hashes","owner":"lykmapipo","description":"redis hash utilities for nodejs","archived":false,"fork":false,"pushed_at":"2018-01-01T16:07:00.000Z","size":100,"stargazers_count":2,"open_issues_count":2,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-26T17:53:18.876Z","etag":null,"topics":["create","delete","hash","lykmapipo","nodejs","object","ohm","redis","reds","remove","search","update","upsert"],"latest_commit_sha":null,"homepage":"https://github.com/lykmapipo/redis-hashes","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/lykmapipo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-03T16:52:38.000Z","updated_at":"2025-01-20T20:53:51.000Z","dependencies_parsed_at":"2022-09-15T15:23:13.215Z","dependency_job_id":null,"html_url":"https://github.com/lykmapipo/redis-hashes","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lykmapipo%2Fredis-hashes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lykmapipo%2Fredis-hashes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lykmapipo%2Fredis-hashes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lykmapipo%2Fredis-hashes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lykmapipo","download_url":"https://codeload.github.com/lykmapipo/redis-hashes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246938937,"owners_count":20857916,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["create","delete","hash","lykmapipo","nodejs","object","ohm","redis","reds","remove","search","update","upsert"],"created_at":"2024-10-10T12:19:50.446Z","updated_at":"2025-04-03T04:30:38.213Z","avatar_url":"https://github.com/lykmapipo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"redis-hashes\n===============\n\n[![Build Status](https://travis-ci.org/lykmapipo/redis-hashes.svg?branch=master)](https://travis-ci.org/lykmapipo/redis-hashes)\n[![Dependency Status](https://img.shields.io/david/lykmapipo/redis-hashes.svg?style=flat)](https://david-dm.org/lykmapipo/redis-hashes)\n[![npm version](https://badge.fury.io/js/redis-hashes.svg)](https://badge.fury.io/js/redis-hashes)\n\nredis hash utilities for nodejs\n\n*Note!: From v0.5+ all indexes keys will be using format \u003cprefix\u003e:indexes:\u003ccollection\u003e:...*\n\n## Requirements\n- [Redis 2.8.0+](http://redis.io/)\n- [NodeJS 8.1.4+](https://nodejs.org/en/)\n\n## Installation\n```sh\n$ npm install --save redis-hashes\n```\n\n## Usage\n\n```javascript\n//initialize redis-hashes with default options\nconst redis = require('redis-hashes')([options]);\n\n//save single user\nconst user = ...;\nhash.save(user, {collection: 'users' }, done);\n\n//save multiple users\nconst users = ...;\nhash.save(users, {collection: 'users' }, done);\n\n\n//get single user\nhash.get(\u003cid\u003e, function(error, user){\n   ...\n});\n\n//get single user and select specified fields\nhash.get(\u003cid\u003e, { fields: 'name, email'}, function(error, user){\n   ...\n});\n\n\n//get multiple users\nhash.get(\u003cid\u003e, \u003cid\u003e, function(error, users){\n   ...\n});\n\n//search users collection\nhash.search(\u003csearch_query\u003e, function (error, users) {\n    ...\n});\n\n\n//count number of users\nhash.count('users', function(error, counters){\n  ...\n});\n\n\n//count number of users and orders\nhash.count('users', 'orders', function(error, counters){\n  ...\n});\n\n\n//remove single users\nhash.remove(\u003cid\u003e, function(error, results){\n   ...\n});\n\n\n//remove multiple users\nhash.remove(\u003cid\u003e, \u003cid\u003e, function(error, results){\n   ...\n});\n\n...\n\n```\n\n## Options\n- `prefix:String` - redis key prefix. default to `r`\n- `separator:String` - redis key separator. default to `:`\n- `redis:Object|String` - [redis](https://github.com/NodeRedis/node_redis#rediscreateclient) connections options or string.\n\nTo initialize `redis` with custom options use\n\n```js\nconst redis = require('redis-hashes')({\n    prefix:'q',\n    separator:'-',\n    redis: {\n    port: 6379,\n    host: '127.0.0.1'\n  }\n});\n\n...\n\nor\n\nconst redis = require('redis-clients')({\n    prefix:'q',\n    separator:'-',\n    redis: 'redis://localhost:6379'\n});\n\n\n```\n\n## API\n\n### `save(objects:Object|Object[],[options:Object],done:Fuction)`\nStore`(create or update)` object(s) into redis [hash datatype](http://redis.io/commands/HSET). Before saving the whole of object is [flatten'ed](https://github.com/hughsk/flat) and serialized. i.e all `dates` will be converted to `timestamps` etc.\n\n\nOptions:\n- `index:Boolean` - whether to [index](https://github.com/tj/reds) the object or not for search. default to `true`.\n- `collection:String` - name of collection or namespace used in prefix hash keys. default to `hash`\n- `ignore: Array[String]` - Collection of `object fields` to ignore when indexing \n\n```js\nconst object = ...;\nhash.save(object, function (error, saved) {\n    ...\n});\n\nconst user = ...;\nhash.save(user, {collection: 'users' }, function (error, saved) {\n    ...\n});\n\n//or bulk save\nconst objects = ...;\nhash.save(objects, function (error, objects) {\n    ...\n});\n\nconst users = ...;\nhash.save(users, {collection: 'users' }, function (error, users) {\n    ...\n});\n```\n\n### `get(...keys,[{ fields: String|String[] }],done:Function)`\nGet single or multiple saved object using their keys\n\n```js\n//get single\nhash.get(\u003cid\u003e, function(error, object){\n   ...\n});\n\n//get single\nhash.get(\u003cid\u003e, { fields: 'name, email'}, function(error, object){\n   ...\n});\n\n//get multiple object\nhash.get([\u003cid\u003e, \u003cid\u003e], function(error, objects){\n   ...\n});\n\n//get multiple object\nhash.get([\u003cid\u003e, \u003cid\u003e], { fields: 'name, email'},  function(error, objects){\n   ...\n});\n\n//get multiple object\nhash.get(\u003cid\u003e, \u003cid\u003e, function(error, objects){\n   ...\n});\n\n//get multiple object\nhash.get(\u003cid\u003e, \u003cid\u003e, { fields: 'name, email'}, function(error, objects){\n   ...\n});\n```\n\n### `search(options:String|Object,[{ fields: String|String[]}],done:Function)`\nSearch existing objects.\n\nOptions:\n- `type:String` - type of [reds](https://github.com/tj/reds) search. default to `or`\n- `collection:String` - name of collection used in searching. default to `hash`\n- `q: String` - query string. default to ''\n\n```js\n//search default collection\nhash.search(\u003csearch_query\u003e, function (error, objects) {\n    ...\n});\n\n//search default collection and select specified fields\nhash\n  .search({q:\u003csearch_query\u003e, fields: 'name, email'}, function (error, objects) {\n    ...\n});\n\n//search specific collection\nhash.search({\n    q: \u003csearch_query\u003e,\n    collection: 'users',\n    type:'or'\n  }, function (error, objects) {\n    ...\n});\n\n//search specific collection and select specified fields\nhash.search({\n    q: \u003csearch_query\u003e,\n    collection: 'users',\n    type:'or',\n    fields: 'name, email'\n  }, function (error, objects) {\n    ...\n});\n```\n\n### `remove(...keys,done:Function)`\nRemove single or multiple saved object using their keys\n\n```js\n//remove single\nhash.remove(\u003cid\u003e, function(error, object){\n   ...\n});\n\n//remove multiple object\nhash.remove([\u003cid\u003e, \u003cid\u003e], function(error, objects){\n   ...\n});\n\n\n//remove multiple object\nhash.remove(\u003cid\u003e, \u003cid\u003e, function(error, objects){\n   ...\n});\n```\n\n### `count(...collections, done:Function)`\nCount number of saved object(s) on specified collection(s)\n\n```js\n//count in single collection\nhash.count('users', function(error, counters){\n   ...\n});\n\n//count in multiple collections\nhash.count('users', 'orders', 'contacts', function(error, counters){\n   ...\n});\n\n```\n\n## References\n- [store-javascript-objects-in-redis-with-node-js-the-right-way](https://medium.com/@stockholmux/store-javascript-objects-in-redis-with-node-js-the-right-way-1e2e89dbbf64#.eb1040111)\n- [reds-internals-searching-and-better-searching-with-node-js-and-redis](https://medium.com/@stockholmux/reds-internals-searching-and-better-searching-with-node-js-and-redis-57da99077e83#.5nhdaxnl4)\n\n\n## Testing\n* Clone this repository\n\n* Install all development dependencies\n```sh\n$ npm install\n```\n\n* Then run test\n```sh\n$ npm test\n```\n\n## Contribute\nIt will be nice, if you open an issue first so that we can know what is going on, then, fork this repo and push in your ideas. Do not forget to add a bit of test(s) of what value you adding.\n\n## Licence\n\nThe MIT License (MIT)\n\nCopyright (c) 2017 lykmapipo \u0026 Contributors\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flykmapipo%2Fredis-hashes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flykmapipo%2Fredis-hashes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flykmapipo%2Fredis-hashes/lists"}