mirror of
https://github.com/amark/gun.git
synced 2026-03-04 16:25:25 +00:00
38 lines
10 KiB
JSON
38 lines
10 KiB
JSON
{
|
|
"name": "fakeredis",
|
|
"version": "0.1.3",
|
|
"description": "Fake redis for testing, works as a drop-in replacement for node_redis",
|
|
"keywords": [
|
|
"test",
|
|
"spec",
|
|
"fake",
|
|
"redis",
|
|
"simulated",
|
|
"implementation",
|
|
"client"
|
|
],
|
|
"author": {
|
|
"name": "Hristo Dachev",
|
|
"email": "tutini@gmail.com"
|
|
},
|
|
"main": "./main.js",
|
|
"dependencies": {
|
|
"redis": ">= 0.7"
|
|
},
|
|
"bugs": {
|
|
"url": "http://github.com/hdachev/fakeredis/issues"
|
|
},
|
|
"repository": {
|
|
"type": "git",
|
|
"url": "git://github.com/hdachev/fakeredis.git"
|
|
},
|
|
"scripts": {
|
|
"test": "node test"
|
|
},
|
|
"readme": "\n\n# fakeredis - a fake redis for node.js\n\n\nThis module provides easy-to-use simulated instances of Redis\nto which you appear to be connected via the\n[redis](https://github.com/mranney/node_redis) client by [Matt Ranney](https://github.com/mranney).\n**It helps with writing tests** in two ways:\nyour tests won't require an actual redis instance\nand you'll be able to safely run as many tests in parallel as you want.\n\n[](https://npmjs.org/package/fakeredis)\n[](http://travis-ci.org/hdachev/fakeredis)\n\n\n## Usage\n\nInstall:\n\n npm install fakeredis\n\nYou can use fakeredis as you would use node_redis,\njust changing the module name from `redis` to `fakeredis`:\n\n```javascript\nvar client = require(\"fakeredis\").createClient(port, host);\n```\n\nBoth parameters are optional,\nand only serve to determine if you want to reuse a an existing fakeredis instance or not.\nYou can also just name your backends arbitrarily:\n\n```javascript\n\n// Create a connection to a fresh fakeredis instance:\nvar client = fakeredis.createClient(\"social stuff\");\n\n// Connect to the same backend via another simulated connection:\nvar concurrentClient = fakeredis.createClient(\"social stuff\");\n```\n\nBy omitting both parameters,\nyou simply create a new blank slate fakeredis instance:\n\n```javascript\nvar client = require(\"fakeredis\").createClient();\n```\n\n\nIn other words,\nevery time you create a client specifying the same port and/or name\nyou reuse the same simulated backend.\nThis makes most sense when you need a concurrent client setup for some test,\nsay because you need to publish / subscribe,\nor because you want to test something that's based on `MULTI`/`EXEC`\nand uses optimistic locking with `WATCH`/`UNWATCH`.\n\nIn any case, fakeredis is great for testing\nbecause you can run as many tests in parallel as you wish,\nand that's also why you'll generally be naming your clients\nin a way that ensures tests don't collide.\n\n\n\n## Intended differences from a true Redis\n\nOne key difference is that the output of some commands,\nsuch as `SMEMBERS`, `HKEYS`, `HVALS`,\ncomes out sorted lexicographically to provide for simpler testing.\nThis means that some tests that make use of undocumented Redis behaviours\nsuch as the chronological order of retrieval for members in a set\nmay fail when attempted with fakeredis.\nTo solve this,\nwhenever there is no documented sort order for a given Redis command's multi-bulk reply,\nsort the output before asserting equality to ensure your tests run everywhere.\n\nAnother major difference is that commands that accept modifier parameters, such as\n`SORT key [BY pattern] [LIMIT offset count] [GET pattern [GET pattern ...]] [ASC|DESC] [ALPHA] [STORE destination]`\ncurrently only accept these parameters in the order that is stated in the documentation.\nFor example,\nin Redis it appears to be perfectly legitimate to have `SORT myset ALPHA LIMIT 0 5`,\nbut in fakeredis this will currently return a syntax error.\n\nI'm totally open to discussion on both points.\n\n\n### Implemented subset:\n\nAll string, list, hash, set and sorted set commands,\nmost keyspace commands, and some connection and server commands.\nPubsub, transactions with optimistic locking are also fully implemented.\n\nList of **available** commands:\n\nKeyspace:\n\n DBSIZE\n EXISTS\n EXPIRE\n EXPIREAT\n FLUSHDB\n KEYS\n PERSIST\n DEL\n RANDOMKEY\n RENAME\n RENAMENX\n SORT\n TTL\n TYPE\n\nStrings:\n\n APPEND\n DECR\n DECRBY\n GET\n GETBIT\n GETRANGE\n GETSET\n INCR\n INCRBY\n MGET\n MSET\n MSETNX\n SET\n SETBIT\n SETEX\n SETNX\n SETRANGE\n\nHashes:\n\n HDEL\n HEXISTS\n HGET\n HGETALL\n HINCRBY\n HKEYS\n HLEN\n HMGET\n HMSET\n HSET\n HSETNX\n HVALS\n\nLists:\n\n BLPOP\n BRPOP\n BRPOPLPUSH\n LINDEX\n LINSERT\n LLEN\n LPOP\n LPUSH\n LPUSHX\n LRANGE\n LREM\n LSET\n LTRIM\n RPOP\n RPOPLPUSH\n RPUSH\n RPUSHX\n\nSets:\n\n SADD\n SCARD\n SDIFF\n SDIFFSTORE\n SINTER\n SINTERSTORE\n SISMEMBER\n SMEMBERS\n SMOVE\n SPOP\n SRANDMEMBER\n SREM\n STRLEN\n SUNION\n SUNIONSTORE\n\nSorted Sets:\n\n ZADD\n ZCARD\n ZCOUNT\n ZINCRBY\n ZINTERSTORE\n ZRANGE\n ZRANGEBYSCORE\n ZRANK\n ZREM\n ZREMRANGEBYRANK\n ZREMRANGEBYSCORE\n ZREVRANGE\n ZREVRANGEBYSCORE\n ZREVRANK\n ZSCORE\n ZUNIONSTORE\n\nPub/Sub:\n\n PSUBSCRIBE\n PUBLISH\n PUNSUBSCRIBE\n SUBSCRIBE\n UNSUBSCRIBE\n\nTransactions:\n\n DISCARD\n EXEC\n MULTI\n UNWATCH\n WATCH\n\nConnection and Server:\n\n ECHO\n PING\n QUIT\n SELECT\n\nThese do nothing but return `OK`:\n\n AUTH\n BGREWRITEAOF\n BGSAVE\n SAVE\n\n\n### What's missing:\n\nMost notably, `MONITOR` is still missing.\n\nAlso note that **none of the node_redis client constructor options are available**,\nwhich means no `detect_buffers` and `return_buffers`.\nCommand arguments are always stringified at the fake connection level,\nand replies are always returned as `null`, `String`, `Number` or `Array`.\n\nFinally,\nnone of the `ready`, `connect`, `error`, `end`, `drain` and `idle`\nclient events are currently implemented.\n\nList of **missing** commands (will throw upon attempt to use):\n\nConnection and Server:\n\n CONFIG GET\n CONFIG SET\n CONFIG RESETSTAT\n DEBUG OBJECT\n DEBUG SEGFAULT\n FLUSHALL\n INFO\n LASTSAVE\n MONITOR\n MOVE\n OBJECT\n SHUTDOWN\n SLAVEOF\n SYNC\n\n\n\n## Helpers\n\nTo facilitate development and testing,\nfakeredis provides some additional methods on the client object.\n\n\n### Prettyprinting:\n\n```javascript\nfakeredisClient.pretty();\nfakeredisClient.pretty(\"p*tte?n\");\nfakeredisClient.pretty(options);\n```\n\n`.pretty()` will prettyprint to stdout the entire keyspace\nor a subset of keys specificed with a redis pattern\nof the same kind that's used for `KEYS` and `PSUBSCRIBE`.\nKeep in mind .pretty() is async,\nbecause it works as a normal client command\nand hence needs to respect the command order,\nfake pipelining and latency and all,\nso that you can do stuff like:\n\n```javascript\nvar client = require(\"fakeredis\").createClient();\n\nclient.SADD('hello', 'world', 'Jenny', 'Sam');\nclient.LPUSH('mylist', 'hey', 'ho', 'letsgo');\nclient.pretty({label: \"my stuff\", pattern: \"*\"});\n```\n\nWhich would print *(in color!)*\n\n my stuff:\n\n set hello\n -1 Jenny, Sam, world\n\n list mylist\n -1 letsgo, ho, hey\n\n\n### Keyspace dumps:\n\n```javascript\nfakeredisClient.getKeypsace(callback);\nfakeredisClient.getKeypsace(\"p*tte?n\", callback);\nfakeredisClient.getKeyspace(options, callback);\n```\n\nWill `callback(err, data)` with an array\nthat enumerates the whole keyspace,\nor the requested subset, in the following manner:\n\n```javascript\n[ key1, ttl1, type1, value1\n, key2, ttl2, type2, value2\n, ... ]\n```\n\nThe keyspace is sorted lexicographically by key,\nstring values are strings,\nlist values are the output of `LRANGE 0 -1`,\nhashes come out as the output of `HGETALL` for hashes\n(no syntactic sugar though, so an Array of `[field, value, field, value, ...]`),\n`SMEMBERS` output is used for sets,\nand `ZRANGE 0 -1 WITHSCORES` for sorted sets,\neach of which is sorted lexicographically in a way that makes sense,\nso that the final result is simple enough to assert deep equality against.\n\nIn any case, you'll probably need to reformat these keyspace dumps\nto a format that makes more sense for your testing needs.\nThere are a couple of transforms that are included out of the box:\n\n```javascript\nfakeredisClient.getKeypsace({pattern: \"myz*\", map: true}, callback);\n```\n\nIf you only care about the key and value of each entry,\nyou can set the **map** option to a truthy value,\nyou will instead receive the keyspace dump as a key-value map of the kind:\n\n```javascript\n{ key1: value1, key2: value2, ... }\n```\n\nThis means you're skipping ttl and key type info though. You can also do:\n\n```javascript\nfakeredisClient.getKeypsace({pattern: \"myz*\", group: true}, callback);\n```\n\nWhich will return an `Array` of `Array`s,\none for each keyspace entry, so that you end up with:\n\n```javascript\n[ [ key1, ttl1, type1, value1 ]\n, [ key2, ttl2, type2, value2 ]\n, ... ]\n```\n\nThe benefit of this option is that you can sort the outer array as you like more easily.\n\n\n\n## Similar projects\n\nYou might also want to check out these similar implementations in\n[python](https://github.com/jamesls/fakeredis) and\n[ruby](https://github.com/guilleiguaran/fakeredis).\n\n\n\n## MIT License\n\nCopyright (c) 2012 Hristo Dachev\n\nPermission is hereby granted, free of charge, to any person\nobtaining a copy of this software and associated documentation\nfiles (the \"Software\"), to deal in the Software without\nrestriction, including without limitation the rights to use,\ncopy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\nHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n\n",
|
|
"readmeFilename": "README.md",
|
|
"homepage": "https://github.com/hdachev/fakeredis",
|
|
"_id": "fakeredis@0.1.3",
|
|
"_from": "fakeredis@~>0.1.3"
|
|
}
|