Skip to content

Instantly share code, notes, and snippets.

@itamarhaber
itamarhaber / hashslot.lua
Created November 26, 2022 16:47
Redis key to hashslot in Lua
--/*
-- Examples:
-- $ redis-cli --eval hashslot.lua , key
-- (integer) 12539
-- $ redis-cli --eval hashslot.lua , key2
-- (integer) 4998
-- $ redis-cli --eval hashslot.lua , key3
-- (integer) 935
-- $ redis-cli --eval hashslot.lua , "id:{key}"
-- (integer) 12539
@itamarhaber
itamarhaber / tcl-dump.lua
Created June 27, 2021 14:45
Dump a Redis key in TCL binary string encoding
-- DUMPs a Redis key in TCL-compatible binary string encoding
local b = redis.call("DUMP",KEYS[1])
local s = ""
for i = 1, string.len(b), 1 do
s = s .. string.format("\\x%02X",string.byte(b,i))
end
return s
@itamarhaber
itamarhaber / part1.md
Last active March 1, 2021 15:01
Redis 6.0 & 6.2
*3
$3
SET
$3
key
$5
value
@itamarhaber
itamarhaber / docs.Dockerfile
Last active February 2, 2020 16:49
structor mkdocs
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/* \

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 October 2, 2018 22:01
Naively call RedisTF from Python with redis-py
  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 July 20, 2018 16:41
Edgexfoundry and Redis for Core Data PoC

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 February 23, 2018 19:18
Some thoughts about "Building a sliding window rate limiter with Redis"

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:

@itamarhaber
itamarhaber / xmas.lua
Last active December 21, 2017 14:38
Happy Xmas!
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