Skip to content

Instantly share code, notes, and snippets.

View antirez's full-sized avatar

Salvatore Sanfilippo antirez

View GitHub Profile
Compile the Redis "notifications" branch on Github.
Start Redis with ./redis-server --notify-keyspace-events yes
Subscribe to all the events with:
redis-cli psubscribe '*'
In another terminal window, play with redis-cli: set, del, expire, ... Only a few already work.

Meltdown fix impact on Redis performances in virtualized environments

UPDATE: apparently kernel difference may have a serious impact, so I'll redo the test from scratch.

Test performed with AOF enabled, fsync policy 1 second, allowing the rewrites to be triggered.

Command lines used:

Random weighted element with Redis sorted sets

Imagine you have elements A, B and C with weights 1, 2 and 3. You compute the sum of the weights, which is 1+2+3 = 6

At this point you add all the elements into a sorted set using this algorithm:

SUM = ELEMENTS.TOTAL_WEIGHT // 6 in this case.
SCORE = 0
@antirez
antirez / wh.md
Last active November 26, 2020 07:18
For white hat hackers setting passwords to open Redis instances

Dear white hat attackers,

recently we observed a number of Redis instances that were targeted by a simple attack, consisting in setting a password using the CONFIG SET requirepass <password> command to instances which are left open on the internet.

This is, in my opinion, a good idea, since those Redis instances are going to be cracked anyway. I believe you are doing this in order to make Redis users aware they forgot to setup firewalling rules in order to make their instances not reachable from the outside.

" antirez's .vimrc
" Copyright(C) 2001 Salvatore Sanfilippo
" Enable the syntax highlight mode if available
syntax sync fromstart
if has("syntax")
syntax sync fromstart
syntax on
set background=dark
let php_sync_method="0"
@antirez
antirez / resp3.md
Last active June 2, 2020 08:41
RESP3 protocol draft

RESP3 specification

Versions history:

  • 1.0, 2 May 2018, Initial draft to get community feedbacks.

Background

The Redis protocol has served us well in the past years, showing that, if carefully designed, a simple human readable protocol is not the bottleneck in the client server communication, and that the simplicity of the design is a major advantage in creating a healthy client libraries ecosystem.

Yet the Redis experience has shown that after about six years from its introduction (when it replaced the initial Redis protocol), the current RESP protocol could be improved, especially in order to make client implementations simpler and to support new features.

<!DOCTYPE html>
<html>
<head><title>Fizzlefade</title></head>
<body>
<canvas id="framebuffer" width="320" height="200"></canvas>
<script type="text/javascript">
/* Fizzlefade using a Feistel network.
@antirez
antirez / api.md
Last active November 20, 2018 02:52
Consumer groups final API
  • XGROUP CREATE <key> <groupname> <id or $>
  • XGROUP SETID <key> <id or $>
  • XGROUP DELGROUP <key> <groupname>
  • XGROUP DELCONSUMER <key> <consumername>
  • XPENDING <key> [<start> <stop>]
  • XCLAIM <key> <group-name> <consumer-name> <min-idle-time> <ID-1> <ID-2> ...
  • XACK <key> <ID-1> <ID-2> ...
  • XREAD-GROUP (wrapper for XREAD that accepts GROUP and CONSUMER options)
  • XINFO [CONSUMERS|GROUPS|STREAM|...]. STREAM is the default
@antirez
antirez / sinatra_redis_cache.rb
Created March 22, 2011 21:06
the simplest Redis caching for Sinatra -- not even tested... consider this code just an hint
# This is just an hint for a simple Redis caching "framework" using Sinatra
# A friend of mine asked for something like that, after checking the first two gems realized there was
# a lot of useless complexity (IMHO). That's the result.
#
# The use_cache parameter is useful if you want to cache only if the user is authenticated or
# something like that, so you can do cache_url(ttl,User.logged_in?, ...)
require 'rubygems'
require 'sinatra'
require 'redis'
@antirez
antirez / vmlatency.c
Last active September 5, 2018 11:12
VM latency
/* vmlatency.c
*
* Measure max latency of a running process that does not result from
* syscalls. Basically this software should provide an hint about how much
* time the kernel leaves the process without a chance to run.
*
* Copyright (C) 2014 Salvatore Sanfilippo.
* This software is released under the BSD two-clause license.
*
* compile with: cc vmlatency.c -o vmlatency