Skip to content

Commit

Permalink
docs(README): add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Feb 11, 2016
1 parent ca9ffbd commit 9cd89bf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ redis.sadd('set', [1, 3, 5, 7]);
redis.set('key', 100, 'EX', 10);
```

See the `examples/` folder for more examples.

## Connect to Redis
When a new `Redis` instance is created,
a connection to Redis will be created at the same time.
Expand Down
26 changes: 26 additions & 0 deletions examples/basic_operations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

var Redis = require('ioredis');
var redis = new Redis();

// ioredis supports all Redis commands:
redis.set('foo', 'bar');
redis.get('foo', function (err, result) {
if (err) {
console.error(err);
} else {
console.log(result);
}
});

// Or using a promise if the last argument isn't a function
redis.get('foo').then(function (result) {
console.log(result);
});

// Arguments to commands are flattened, so the following are the same:
redis.sadd('set', 1, 3, 5, 7);
redis.sadd('set', [1, 3, 5, 7]);

// All arguments are passed directly to the redis server:
redis.set('key', 100, 'EX', 10);

0 comments on commit 9cd89bf

Please sign in to comment.