Skip to content

Instantly share code, notes, and snippets.

@itamarhaber
itamarhaber / part1.md
Last active Mar 1, 2021
Redis 6.0 & 6.2
View part1.md
View mass.txt
*3
$3
SET
$3
key
$5
value
View docs.Dockerfile
FROM alpine
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.local/bin
COPY requirements.txt /mkdocs/
WORKDIR /mkdocs
RUN apk --update upgrade \
&& apk --no-cache --no-progress add py-pip \
&& rm -rf /var/cache/apk/* \
View acl-app-profile.md

ACL v6RC1 default app profile

The purpose of this exercise is to define a "default" application ACL profile that can access the all the data without being able to cause too much harm.

Additive ("future-proof") profile

Required extra permissions:

  • All functional categories
  • CLIENT ID|GETNAME|REPLY|SETNAME|TRACKING|GETREDIR: must for modern clients
  • CLUSTER COUNTKEYSINSLOT|GETKEYSINSLOT|INFO|KEYSLOT|MYID|NODES|SLOTS: must for cluster-aware clients
@itamarhaber
itamarhaber / README.md
Created Oct 2, 2018
Naively call RedisTF from Python with redis-py
View README.md
  1. Clone, sh get_deps.sh, and make run https://github.com/lantiga/RedisTF
  2. pip install redis tensorflow
  3. cd models
  4. Run python tf-minimal.py to prepare a minimal graph
  5. The attached redistf-py.py demonstrates how to run the test in the README from Python:
$ python redistf-py.py
Setting the graph: OK
Setting tensor t1: OK
@itamarhaber
itamarhaber / edgex-go-redisdb.md
Created Jul 20, 2018
Edgexfoundry and Redis for Core Data PoC
View edgex-go-redisdb.md

Edgexfoundry and Redis for Core Data PoC

Objectives

  • Implement the Redis client for edgex-go core data client tests/benchmarks
  • Compare between TCP, UDS and embedded Redis connections vs. Mongo's

Setting up

Server set up

@itamarhaber
itamarhaber / some_thoughts.md
Created Feb 23, 2018
Some thoughts about "Building a sliding window rate limiter with Redis"
View some_thoughts.md

Reading Building a sliding window rate limiter with Redis, and w/o addressing the actual logic (which may or may not work).

Optimize by:

  1. Lua seems a much better choice: idiompotent, portable, server-side, less bandwidth, atomic...
  2. The call to ZRANGEBYSCORE seems to be unused, should be commented out if so
  3. Looking at the use of ZRANGE, it appears that ZCARD it what's actually needed

The (untested) Lua snippet:

View xmas.lua
local
h,d,r=9,
0,{} while
h>0 do local
l='' h=h-1 for
x=0, 38 do local
a=x-6 if a<0 then a
= -a end if a <= d then
l = l .. '*' elseif (0.3/
(h+1)) > math.random() then
@itamarhaber
itamarhaber / setbitrange.lua
Last active Dec 25, 2020
A somewhat optimized scripted approach to complementing Redis with a `SETBITRANGE` command
View setbitrange.lua
--[[
Sets a bitmap range
Bitmaps are stored as Strings in Redis. A range spans one or more bytes,
so we can call `SETRANGE` when entire bytes need to be set instead of flipping
individual bits. Also, to avoid multiple internal memory allocations in
Redis, we traverse in reverse.
Expected input:
KEYS[1] - bitfield key
@itamarhaber
itamarhaber / pubsub.py
Created Dec 5, 2017
Threaded Redis PubSub demonstration in Python w/ redis-py
View pubsub.py
# Demonstrates PubSub
import threading
import redis
class Listener(threading.Thread):
def __init__(self, r, p):
threading.Thread.__init__(self)
self.redis = r
self.pubsub = self.redis.pubsub()