select
is rarely use these days, kqueue
and epoll
tend to be preferred.Good? Let’s get to it now.
select
syscallThe select
syscall is really useful to write systems using an event loop. A good example…
When &:object_id
is used as an argument to a method call, it will convert the symbol :object_id
into a Proc
instance with the Symbol#to_proc
method.
This syntax is really useful when mixed with Enumerable
methods such as map
and select
:
irb(main):001:0> [ 1, 2, 3, 4, 5 ].select(&:even?)
=> [2, 4]
irb(main):002:0> [ 1, 2, 3, 4, 5 ].map(&:even?)
=> [false, true, false, true, false]
The result of :even?.to_proc
is a Proc
instance, very similar to proc { |x| x.even? }
with one major difference. They handle arguments differently. …
This article is part of a series, Redis in Ruby, originally published at https://redis.pjam.me/. All chapters are available on Medium as well: https://medium.com/@pierre_jambet
So far we’ve been using the Ruby Hash
class as the main storage mechanism for the key/value pairs received through the SET
command. We also use it for the secondary dictionary necessary to implement the TTL related options of the SET
command. We store the expiration timestamp of keys with TTLs, which allows us to know whether a key is expired or not.
Redis is written in C, which does not provide a collection similar to Ruby’s…
This article is part of a series, Redis in Ruby, originally published at https://redis.pjam.me/. All chapters are available on Medium as well: https://medium.com/@pierre_jambet
By the end of this chapter RedisServer
will speak the Redis Protocol, RESP v2
. Doing this will allow any clients that was written to communicate with the real Redis to also communicate with our own server, granted that the commands it uses are within the small subset of the ones we implemented.
One such client is the redis-cli
utility that ships with Redis, it'll look like this:
RESP v2 has been the protocol used by Redis since…
As I’m writing this, I’m finishing my fifth week of running after taking a five-week break, so things are starting to feel like they’re back to normal on that front. On the other hand, all the problems that were there before, racial injustice, and COVID being top of mind, are still here, and it’s really hard to gauge if progress is being made. But at least there is momentum to make things better, a lot of people are speaking up, on both ends, and that might be the silver lining.
On the protesting front, there are things we can do…
This article is part of a series, Redis in Ruby, originally published at https://redis.pjam.me/. All chapters are available on Medium as well: https://medium.com/@pierre_jambet
We implemented a simplified version of the SET
command in Chapter 2, in this chapter we will complete the command by implementing all its options. Note that we're still not following the Redis Protocol, we will address that in the next chapter.
The commands accepts the following options:
In the previous post we attempted to translate the main F# constructs from the original Railway Oriented Programming (ROP) documents — the blog posts & the slide deck — to Scala. We also showed what an alternative approach looks like using Scala’s built-in class. The code is on GitHub. That was a long article, I want to keep this one short & sweet.
In this article, we will focus on the “Combining functions in parallel” piece.
The word “parallel” in this context can be confusing because it is conceptually different from “parallelism” used to describe tasks happening at the same…
Good morning runners!
My last race was on March 1st, a little bit over four months ago now, and I’m starting to seriously miss it. There’s something special about the atmosphere in the corral, as you wait for the start of the race, shoulder to shoulder with a bunch of sweaty, smelly runners. The way NYRR staff greets you over the mic with their “Goooood morning runners!” — I haven’t really ventured much outside of NYRR races in the last few years — the national anthem, the whole thing! And then sure, the racing part is fun too, but the…
A few years ago, a coworker introduced me to Railway Oriented Programming (ROP). At the time we were using Ruby, and while the ideas in ROP made a ton of sense, I didn’t really find a way to apply them to what I was working on. The lack of types made it pretty hard to go beyond “I just read a blog post and I’m gonna pollute our codebase with it, because I can” and actually improve things. We all pretty much moved on.
Later on, I switched to a different project, using Scala, and ended up using the Either
…
This article is part of a series, Redis in Ruby, originally published at https://redis.pjam.me/. All chapters are available on Medium as well: https://medium.com/@pierre_jambet
In this chapter we will add support for efficient handling of multiple clients connected simultaneously. We will first isolate the problematic elements of the current implementation and explore different solutions before getting to the final one using the syscall.
Let’s start with the new client problem. Our goal is the following:
Regardless of the state of the server, or what it might be doing, or whether other clients are already connected, new clients should be able to…
Software Engineer by day, Runner by day as well.