This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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"); | |
| const hasher = std.hash.Fnv1a_64; | |
| const cuckoo = @import("./cuckoofilter.zig"); | |
| fn fingerprint8(x: []const u8) u8 { | |
| return x[0]; | |
| } | |
| fn fingerprint16(x: []const u8) u16 { | |
| return @ptrCast(*u16, x[0..1].ptr).*; |
This file contains hidden or 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 redis = @cImport({ | |
| @cInclude("./redismodule.h"); | |
| }); | |
| export fn HelloWorld_Command(ctx: *redis.RedisModuleCtx, argv: [*c]*redis.RedisModuleString, argc: c_int) c_int { | |
| _ = redis.RedisModule_ReplyWithSimpleString(ctx, c"Hello World!"); | |
| return redis.REDISMODULE_OK; | |
| } | |
| export fn RedisModule_OnLoad(ctx: *redis.RedisModuleCtx, argv: [*c]*redis.RedisModuleString, argc: c_int) c_int { |
This file contains hidden or 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
| import redis | |
| r = redis.Redis(decode_responses=True) | |
| data = {"hello": "world", "ans": 42} | |
| p1 = r.pubsub(ignore_subscribe_messages=True) | |
| p1.subscribe("channel") | |
| # Assuming we have an exposed RESP3 parser from the library |
This file contains hidden or 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 | |
| > HGETALL occupation:IT | |
| 1) "occupation" | |
| 2) "RELIGIOUS FIGURE" | |
| > HGETALL occupation:US | |
| 1) "occupation" | |
| 2) "ACTOR" |