This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
pub fn main() !void { | |
const oh = error { | |
no, | |
}; | |
var x: oh!u8 = oh.no; | |
if (x) |_| { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
"github.com/go-redis/redis" | |
"github.com/kristoff-it/redis-memolock/go/memolock" | |
) | |
func main () { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> HSET vec:1 x 10 y 5 z 23 | |
(integer) 3 | |
> HSET vec:2 x 2 y 5 z 5 | |
(integer) 3 | |
> RG.PYEXECUTE 'import numpy; GearsBuilder().map(lambda x: [float(x["value"]["x"]), float(x["value"]["y"]), float(x["value"]["z"])]).accumulate(lambda a, x: x if a is None else numpy.mean([a, x], axis=0)).flatmap(lambda x: x.tolist()).run("vec:*")' | |
1) 1) "14.0" | |
2) "5.0" | |
3) "6.0" | |
2) (empty list or set) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# script.py | |
import numpy as np | |
def hash2list(redis_key): | |
h = redis_key['value'] # redis_key contains 'key' and 'value' | |
return [float(h['x']), float(h['y']), float(h['z'])] | |
def do_mean(acc, x): | |
if acc is None: | |
return x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ redis-cli hset vec:1 x 10 y 5 z 23 | |
$ redis-cli hset vec:2 x 2 y 5 z 5 | |
$ cat script.py | redis-cli -x RG.PYEXECUTE | |
1) 1) "14.0" | |
2) "5.0" | |
3) "6.0" | |
2) (empty list or set) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ redis-cli hset vec:1 x 10 y 5 z 23 | |
$ redis-cli hset vec:2 x 2 y 5 z 5 | |
$ python3 | |
>>> import redis | |
>>> r = redis.Redis(decode_responses=True) # decode_responses is useful in py3 | |
>>> script = open("path/to/script.py", 'r').read() | |
>>> r.execute_command("RG.PYEXECUTE", script) | |
[['14.0', '5.0', '6.0'], []] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GearsBuilder().filter(lambda x: x['key'].startswith('audited-')).foreach(lambda x: execute('xadd', 'audit-logs', '*', 'key', x['key'])).register() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GearsBuilder('StreamReader').foreach(lambda x: execute('zadd', 'audit-counts', '1', x['key'])).register('audit-logs') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> RG.PYEXECUTE "GearsBuilder().filter(lambda x: int(x['value']['age']) > 35).foreach(lambda x: execute('del', x['key'])).run('user:*')" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Connect to the container. Use `docker container list` to know the container name. | |
$ docker exec -it CONTAINER_NAME bash | |
# Attach to the virtual environment. This is probably going to be streamlined in future versions. | |
$ apt-get update | |
$ apt-get install python-pip | |
$ pip install pipenv | |
$ cd /opt/redislabs/lib/modules/python3/ | |
$ pipenv shell |