UNPKG

4.17 kBMarkdownView Raw
1redis-mock
2============
3
4[![NPM](https://nodei.co/npm/redis-mock.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/redis-mock/)
5
6[![Build Status](https://travis-ci.org/yeahoffline/redis-mock.svg?branch=master)](https://travis-ci.org/yeahoffline/redis-mock)
7[![Coverage Status](https://coveralls.io/repos/yeahoffline/redis-mock/badge.svg)](https://coveralls.io/r/yeahoffline/redis-mock)
8
9The goal of the `redis-mock` project is to create a feature-complete mock of [node_redis](https://github.com/NodeRedis/node_redis), which may be used interchangeably when writing unit tests for code that depends on `redis`.
10
11All operations are performed in-memory, so no Redis installation is required.
12
13100% Redis-compatible (see [Cross Verification](#cross-verification))
14
15# Installation
16
17````bash
18$ npm install redis-mock --save-dev
19````
20
21
22## Usage
23
24### node.js/io.js
25
26The below code demonstrates a example of using the redis-mock client in node.js/io.js
27
28
29```js
30var redis = require("redis-mock"),
31 client = redis.createClient();
32```
33
34
35# API
36
37Currently implemented are the following redis commands:
38
39### General
40* createClient
41* duplicate
42* auth
43* end
44* multi
45 * exec
46 * discard
47 * exec_atomic
48* batch
49
50### Events
51* ready
52* connect
53* end
54* quit
55* subscribe
56* unsubscribe
57* message
58* psubscribe
59* punsubscribe
60* pmessage
61
62### Publish/subscribe
63* publish
64* subscribe
65* unsubscribe
66* psubscribe
67* punsubscribe
68
69### Keys
70* del
71* keys
72* scan
73* exists
74* type
75* expire
76* ttl
77* incr
78* incrby
79* incrbyfloat
80* decr
81* decrby
82* rename
83* dbsize
84* renamenx
85
86### Strings
87* get
88* set
89* getset
90* mget
91* mset
92* msetnx
93* setex
94* setnx
95* ping
96
97### Hashing
98* hset
99* hsetnx
100* hget
101* hexists
102* hdel
103* hlen
104* hgetall
105* hscan
106* hmset
107* hmget
108* hkeys
109* hvals
110* hincrby
111* hincrbyfloat
112
113### Lists
114* llen
115* lpush
116* rpush
117* lpushx
118* rpushx
119* lpop
120* rpop
121* blpop
122* brpop
123* lindex
124* lrange
125* lrem
126* lset
127
128### Sets
129* sadd
130* srem
131* smembers
132* scard
133* sismember
134
135### Sorted Sets
136* zadd
137* zcard
138* zcount
139* zincrby
140* zrange
141* zrangebyscore
142* zrank
143* zrem
144* zremrangebyrank
145* zremrangebyscore
146* zrevrange
147* zrevrank
148* zunionstore (Partial: no support for `WEIGHTS` or `AGGREGATE` yet)
149* zinterstore (Partial: no support for `WEIGHTS` or `AGGREGATE` yet)
150* zscore
151
152### Server
153* flushdb
154* flushall
155
156
157# Cross verification
158
159If you want to add new tests to the test base it is important that they work too on node_redis (we are creating a mock...).
160You can therefore run the tests using `redis` instead of `redis-mock`. To do so:
161
162````bash
163$ make check-tests
164````
165
166
167You will need to have a running instance of `redis` on you machine and our tests use flushdb a lot so make sure you don't have anything important on it.
168
169
170# Roadmap
171redis-mock is work in progress, feel free to report an issue
172
173
174# Versions
175* 0.5.1 setex bug + readme update (thanks to gswalden)
176* 0.5.0 "Add an AUTH method" + other pr (thanks to aredridel)
177* 0.4.9 merge getset + expire fix (thanks to sobotklp)
178* 0.4.8 merge issue #1 (thanks to williamkapke)
179* 0.4.7 update devDependencies (should, mocha)
180
181
182
183
184## LICENSE - "MIT License"
185
186Copyright (c) 2012 Kristian Faeldt <kristian.faeldt@gmail.com>
187
188Permission is hereby granted, free of charge, to any person
189obtaining a copy of this software and associated documentation
190files (the "Software"), to deal in the Software without
191restriction, including without limitation the rights to use,
192copy, modify, merge, publish, distribute, sublicense, and/or sell
193copies of the Software, and to permit persons to whom the
194Software is furnished to do so, subject to the following
195conditions:
196
197The above copyright notice and this permission notice shall be
198included in all copies or substantial portions of the Software.
199
200THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
201EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
202OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
203NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
204HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
205WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
206FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
207OTHER DEALINGS IN THE SOFTWARE.
208
\No newline at end of file