<commit_before># redis function - redis scripts in javascript

_Notice: this module is under heavy development and not yet ready for production. Also, a great part of the js syntax it not yet supported._

This is an interface for transpiling Javascript functions to [Lua](http://www.lua.org/) code and running them on the [Redis scripting engine](http://redis.io/commands/eval).

It is designed to work as a companion to the [excellent `node_redis` module](https://github.com/mranney/node_redis), although it is of course possible to use it with any other redis client library.

Install with:

    npm install redis-function
    
## Usage

Simple example, included as example.js:

```
    var redis = require('redis'),
        RedisFunction = require('redis-function');

    RedisFunction.mixin(redis.RedisClient);

    function compareAndDelete (key, cmp) {
      'use redis';

      var val = this.call('get', key);
      if (val == cmp) {
        this.call('del', key);
      }
      return val;

    }

    var client = redis.createClient();
    client.set('foo', 'bar', redis.print);
    client.eval(compareAndDelete, 1, 'foo', 'baz', redis.print);
    client.eval(compareAndDelete, 1, 'foo', 'bar', redis.print);
    client.quit();
```

This will display:

```<commit_msg>fix typo and highlighting in README<commit_after># redis function - redis scripts in javascript

_Notice: this module is under heavy development and not yet ready for production. Also, a great part of the js syntax is not yet supported.n_

This is an interface for transpiling Javascript functions to [Lua](http://www.lua.org/) code and running them on the [Redis scripting engine](http://redis.io/commands/eval).

It is designed to work as a companion to the [excellent `node_redis` module](https://github.com/mranney/node_redis), although it is of course possible to use it with any other redis client library.

Install with:

    npm install redis-function
    
## Usage

Simple example, included as example.js:

```js
    var redis = require('redis'),
        RedisFunction = require('redis-function');

    RedisFunction.mixin(redis.RedisClient);

    function compareAndDelete (key, cmp) {
      'use redis';

      var val = this.call('get', key);
      if (val == cmp) {
        this.call('del', key);
      }
      return val;

    }

    var client = redis.createClient();
    client.set('foo', 'bar', redis.print);
    client.eval(compareAndDelete, 1, 'foo', 'baz', redis.print);
    client.eval(compareAndDelete, 1, 'foo', 'bar', redis.print);
    client.quit();
```

This will display:

```
{'fraction_non_alphanumeric': 0.12010848508330105, 'fraction_numerical': 0.0015497869043006587, 'mean_word_length': 3.4671280276816607, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5030723', 'n_tokens_mistral': 814, 'n_tokens_neox': 770, 'n_words': 272}