Secret
D:\msys64\home\unix2linux\lua2\redis>echo %DATE%T%TIME%
2024-12-31T 8:55:47.94
D:\msys64\home\unix2linux\lua2\redis>printf "%DATE%%TIME%" | openssl dgst -md5
MD5(stdin)= b40c65cc4796709fea4fb6e370ab355bD:\msys64\home\unix2linux\lua2\redis>uuidgen
e9ce2966-8cf6-4e80-862e-1914261ee784
D:\msys64\home\unix2linux\lua2\redis>uuidgen | openssl dgst -md5
MD5(stdin)= 64763802aba6d3b6e67505659a36b4fdD:\msys64\home\unix2linux\lua2\redis>linux_date +"%s%N"
1735606709895182500
D:\msys64\home\unix2linux\lua2\redis>linux_date +"%s%N" | openssl dgst -md5
MD5(stdin)= e88ac702f6da42dd731179501d5e7aec
Auth
D:\msys64\home\unix2linux\lua2\redis>redis-cli -a e88ac702f6da42dd731179501d5e7aec
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> config get requirepass
1) "requirepass"
2) "e88ac702f6da42dd731179501d5e7aec"
127.0.0.1:6379>
Configure
###############################################################################
requirepass 'e88ac702f6da42dd731179501d5e7aec'
###############################################################################
dbfilename "dump.rdb"save 900 1
save 300 10
save 60 10000
###############################################################################
Keys
D:\msys64\home\unix2linux\lua2\redis>red
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> config get dir
1) "dir"
2) "D:\\msys64\\home\\unix2linux\\lua2\\redis"
127.0.0.1:6379> keys *
(empty array)
127.0.0.1:6379> save
OK
127.0.0.1:6379> flushall
OK
127.0.0.1:6379> ping
PONG
Flush
127.0.0.1:6379> flushdb
OK
127.0.0.1:6379> flushall
OK
127.0.0.1:6379>
Data Dictionary : Run Mode
[{"ID": 0, "Key": "ON", "Value": "running", "Data": "", "Description": ""}, {"ID": 1, "Key": "OFF", "Value": "freezing", "Data": "", "Description": ""}
]
Data Dictionary : Predict Mode
[{"ID": 0, "Key": "YOLO V5", "Value": "yolov5s.pt", "Data": "", "Description": ""}, {"ID": 1, "Key": "Fireworks V1", "Value": "fireworksv1.pt", "Data": "", "Description": ""}
]
127.0.0.1:6379> set data-dictionary:run-mode "[{'ID':0,'Key':'ON','Value':'running','Data':'','Description':''},{'ID':1,'Key':'OFF','Value':'freezing','Data':'','Description':''}]"
OK
127.0.0.1:6379> set data-dictionary:predict-mode "[{'ID':0,'Key':'YOLO V5','Value':'yolov5s.pt','Data':'','Description':''},{'ID':1,'Key':'Fireworks V1','Value':'fireworksv1.pt','Data':'','Description':''}]"
OK
127.0.0.1:6379> save
OK
127.0.0.1:6379> keys *
1) "data-dictionary:predict-mode"
2) "data-dictionary:run-mode"
127.0.0.1:6379> get data-dictionary:run-mode
"[{'ID':0,'Key':'ON','Value':'running','Data':'','Description':''},{'ID':1,'Key':'OFF','Value':'freezing','Data':'','Description':''}]"
127.0.0.1:6379> get data-dictionary:predict-mode
"[{'ID':0,'Key':'YOLO V5','Value':'yolov5s.pt','Data':'','Description':''},{'ID':1,'Key':'Fireworks V1','Value':'fireworksv1.pt','Data':'','Description':''}]"
Data Dictionary List
D:\msys64\home\unix2linux\lua2\redis>curl "http://localhost:9999/api/redis/dictionary/list?master=run-mode&slave=0"
{"code": 0,"msg": "success","data": {"master": "run-mode","slave": "0","token": [{"ID": 0,"Key": "ON","Value": "running","Data": "","Description": ""}]}
}
D:\msys64\home\unix2linux\lua2\redis>curl "http://localhost:9999/api/redis/dictionary/list?master=predict-mode"
{"code": 0,"msg": "success","data": {"master": "predict-mode","slave": "","token": [[{"Data": "","Description": "","ID": 0,"Key": "YOLO V5","Value": "yolov5s.pt"},{"Data": "","Description": "","ID": 1,"Key": "Fireworks V1","Value": "fireworksv1.pt"}]]}
}
Data Dictionary Save
D:\msys64\home\unix2linux\lua2\redis>curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d "{\"ID\":0,\"Name\":\"redis\"}" "http://localhost:9999/api/redis/dictionary/save?master=view-mode"
{"code": 0,"msg": "success","data": {"master": "view-mode","slave": "","body": {"ID": 0,"Name": "redis"}}
}
/api/redis/dictionary/all
location /api/redis/dictionary/all {content_by_lua_block {ngx.header.content_type = 'text/html; charset=utf-8'local args = ngx.req.get_uri_args()local result, ok, err, respond;local cjson = require "cjson.safe"local redis = require "resty.redis";local red = redis:new();ok, err = red:connect("127.0.0.1", 6379);ok, err = red:auth(ngx.var.client_redis_secret)if not ok thenresult = string.format('{"code":1,"msg":"error","data":{"token":"%s","body":[]}}', args['token'])return ngx.say(result)endlocal dictionary = 'data-dictionary'local token = string.format('%s*', dictionary)local keys, err = red:keys(token)local line = '['for i, key in ipairs(keys) doline = line .. '"' .. string.sub(key, (string.len(dictionary) + 2)) .. '",'endline = line .. ']'line = string.gsub(line, ',]', ']')red:close()result = string.format('{"code":0,"msg":"success","data":{"token":"%s","body":%s}}', dictionary, line)return ngx.say(result)}
}