Skip to content

chore: enabled syntax highlighting #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ All commands must be defined at the time the module is loaded in a startup scrip
Below we create an example script named startup.js which defines a new command named "concat". This command fetches two keys and returns the string concatenation of the two values.
We then register this function with the server so that it will be directly callable from Redis or KeyDB clients.

function concat(key1, key2) {
var str1 = redis.call('get', key1);
var str2 = redis.call('get', key2);
return str1 + str2;
}

keydb.register(concat);
```js
function concat(key1, key2) {
var str1 = redis.call('get', key1);
var str2 = redis.call('get', key2);
return str1 + str2;
}

keydb.register(concat);
```

*Note: The redis and keydb objects may be used interchangebly.*

Expand All @@ -49,15 +51,17 @@ The above examples were simple enough not to require external libraries, however

In this example we will use the popular lodash library, installed with: ``npm install loadash``. Below we've updated our example script to use the camelCase() function in lodash:

var _ = require("lodash")
```js
var _ = require("lodash")

function concat(key1, key2) {
var str1 = redis.call('get', key1);
var str2 = redis.call('get', key2);
return _.camelCase(str1 + " " + str2)
}

keydb.register(concat);
function concat(key1, key2) {
var str1 = redis.call('get', key1);
var str2 = redis.call('get', key2);
return _.camelCase(str1 + " " + str2)
}

keydb.register(concat);
```

The lodash module is imported with require() as it would be in a node.js script. Note that require() will search for modules starting from the working directory of Redis or KeyDB. Once loaded this new script will concatenate the two strings using camel case.

Expand Down