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
>>> counts = df.groupby("countryCode", "occupation").agg({"en_curid": "count"}) | |
>>> counts.show(2) | |
+-----------+-------------+---------------+ | |
|countryCode| occupation|count(en_curid)| | |
+-----------+-------------+---------------+ | |
| FR|MATHEMATICIAN| 34| | |
| IT|SOCCER PLAYER| 81| | |
+-----------+-------------+---------------+ | |
only showing top 2 rows |
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
>>> from pyspark.sql.window import Window | |
>>> from pyspark.sql.functions import count, col, row_number | |
>>> w = Window().partitionBy("countryCode").orderBy(col("count(en_curid)").desc()) | |
>>> result = counts.withColumn("rn", row_number().over(w)).where(col("rn") == 1).select("countryCode", "occupation") | |
>>> result.show(5) | |
+-----------+-------------+ | |
|countryCode| occupation| | |
+-----------+-------------+ | |
| DZ| POLITICIAN| | |
| LT| POLITICIAN| |
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 | |
> SCAN 0 MATCH people:* COUNT 3 | |
1) "2048" | |
2) 1) "people:2113653" | |
2) "people:44849" | |
3) "people:399280" | |
4) "people:101393" |
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
>>> result.where(col("occupation") == "POLITICIAN").count() | |
150 |
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
>>> no_pol = result.where(col("occupation") != "POLITICIAN") | |
>>> no_pol.write.format("org.apache.spark.sql.redis").option("table", "occupation").option("key.column", "countryCode").save() |
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 | |
> HGETALL occupation:IT | |
1) "occupation" | |
2) "RELIGIOUS FIGURE" | |
> HGETALL occupation:US | |
1) "occupation" | |
2) "ACTOR" |
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
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 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 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 = @import("./redismodule.zig"); | |
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 { | |
if (redis.RedisModule_Init(ctx, c"testmodule", 1, redis.REDISMODULE_APIVER_1) |
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"); | |
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).*; |