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 const io_mode = .evented; | |
// Loris: This is an unfortunate combination of traps that you stumbled upon. | |
// Reader / Writer interfaces are generic (ie the type changes based on the underlying stream). | |
// In Zig we use the term "interface" very broadly to refer to anything that fulfills a predetermined API. | |
// This is very different than say, Go, where "interface" is a concrete feature of the language that | |
// only offers one specific way of doing runtime polymorphism. Going back to Zig, the problem here is | |
// that stdin and stdout are `std.fs.File` structs, while the socket is a `std.net.Stream`, which means |
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 time = std.time; | |
const Timer = time.Timer; | |
const net = std.net; | |
const fs = std.fs; | |
pub const io_mode = .evented; | |
const NUM_CLIENTS = 5; | |
const MSG_SIZE = 4096 * 512; |
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 time = std.time; | |
const builtin = @import("builtin"); | |
const heyredis = @import("./src/okredis.zig"); | |
pub const io_mode = .evented; | |
const addr = if (builtin.os.tag == .linux) "192.168.65.2" else "127.0.0.1"; | |
pub fn main() !void { |
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 time = std.time; | |
const builtin = @import("builtin"); | |
const heyredis = @import("./src/okredis.zig"); | |
pub const io_mode = .evented; | |
const addr = "127.0.0.1"; | |
pub fn main() !void { |
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 time = std.time; | |
const builtin = @import("builtin"); | |
const heyredis = @import("./src/heyredis.zig"); | |
const addr = if (builtin.os == .linux) "192.168.65.2" else "127.0.0.1"; | |
pub const io_mode = .evented; | |
pub fn main() !void { | |
if (std.io.is_async) { |
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
// Connection info, a URI with this shape: | |
// [redis[s]:]//[[user][:password@]][host][:port][/db-number][?db=db-number[&password=bar[&option=value]]] | |
const REDIS_URI = process.env.REDIS_URI; | |
// Redis client library | |
const redis = require('redis'); | |
// Client instance | |
const r = redis.createClient(REDIS_URI); |
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 asyncio, aioredis | |
async def main(): | |
pool = await aioredis.create_redis_pool('localhost', | |
db=0, password=None, ssl=False, minsize=4, maxsize=10, encoding='utf8') | |
# No need to pluck a single connection | |
# aioredis will schedule your command to | |
# a random connection inside the pool. | |
await pool.set("key", "hello world") |
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 asyncio, aioredis | |
async def main(): | |
pool = await aioredis.create_redis_pool('localhost', | |
db=0, password=None, ssl=False, minsize=4, maxsize=10, encoding='utf8') | |
# Assuming we're not the only ones using the pool | |
start_other_coroutines_that_use_redis(pool) | |
# We reserve a connection for a blocking operation |
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 asyncio, aioredis | |
async def main(): | |
pool = await aioredis.create_redis_pool('localhost', | |
db=0, password=None, ssl=False, minsize=4, maxsize=10, encoding='utf8') | |
# Assuming we're not the only ones using the pool | |
start_other_coroutines_that_use_redis(pool) | |
# This time we do a transaction |
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 asyncio | |
import aioredis | |
async def add_new_win(pool, winner): | |
# Creating tasks doesn't schedule them | |
# so you can create multiple and then | |
# schedule them all in one go using `gather` | |
task1 = pool.zincrby('wins_counter', 1, winner) | |
task2 = pool.incr('total_games_played') |
NewerOlder