mad1690 5 months ago
parent
commit
6de6cee665
100 changed files with 9075 additions and 0 deletions
  1. 90 0
      .gitignore
  2. 24 0
      .gitmodules
  3. 15 0
      .readthedocs.yaml
  4. 119 0
      3rdparty/3rdparty.pri
  5. 89 0
      3rdparty/pyotherside.pri
  6. 102 0
      BACKERS.md
  7. 44 0
      CONTRIBUTING.md
  8. 10 0
      COPYRIGHT
  9. 674 0
      LICENSE
  10. 10 0
      README.md
  11. BIN
      build/windows/installer/images/main.bmp
  12. 53 0
      build/windows/installer/include/install_vcredist_x64.nsh
  13. 28 0
      build/windows/installer/include/nsProcess.nsh
  14. 54 0
      build/windows/installer/include/x64.nsh
  15. 167 0
      build/windows/installer/installer.nsi
  16. BIN
      build/windows/installer/plugin/INetC.dll
  17. BIN
      build/windows/installer/plugin/nsProcess.dll
  18. BIN
      build/windows/installer/resources/libeay32.dll
  19. 3 0
      build/windows/installer/resources/qt.conf
  20. BIN
      build/windows/installer/resources/ssleay32.dll
  21. 5 0
      docs/app-store.md
  22. 55 0
      docs/bulk-operations.md
  23. 7 0
      docs/css/extra.css
  24. 40 0
      docs/development.md
  25. 60 0
      docs/extension-server.md
  26. 11 0
      docs/faq.md
  27. BIN
      docs/favicon.ico
  28. 11 0
      docs/index.md
  29. 96 0
      docs/install.md
  30. 2 0
      docs/known-issues.md
  31. 45 0
      docs/lg-keyspaces.md
  32. 9 0
      docs/native-formatters.md
  33. 154 0
      docs/quick-start.md
  34. 2 0
      docs/requirements.txt
  35. 129 0
      docs/server_spec.yaml
  36. 25 0
      mkdocs.yml
  37. 8 0
      sonar-project.properties
  38. 430 0
      src/app/app.cpp
  39. 80 0
      src/app/app.h
  40. 7 0
      src/app/apputils.h
  41. 65 0
      src/app/darkmode.h
  42. 16 0
      src/app/events.cpp
  43. 63 0
      src/app/events.h
  44. 278 0
      src/app/jsonutils.cpp
  45. 12 0
      src/app/jsonutils.h
  46. 91 0
      src/app/models/configmanager.cpp
  47. 22 0
      src/app/models/configmanager.h
  48. 99 0
      src/app/models/connectionconf.cpp
  49. 92 0
      src/app/models/connectionconf.h
  50. 22 0
      src/app/models/connectiongroup.cpp
  51. 29 0
      src/app/models/connectiongroup.h
  52. 459 0
      src/app/models/connectionsmanager.cpp
  53. 103 0
      src/app/models/connectionsmanager.h
  54. 374 0
      src/app/models/key-models/abstractkey.h
  55. 73 0
      src/app/models/key-models/bfkey.cpp
  56. 34 0
      src/app/models/key-models/bfkey.h
  57. 149 0
      src/app/models/key-models/hashkey.cpp
  58. 28 0
      src/app/models/key-models/hashkey.h
  59. 167 0
      src/app/models/key-models/keyfactory.cpp
  60. 37 0
      src/app/models/key-models/keyfactory.h
  61. 158 0
      src/app/models/key-models/listkey.cpp
  62. 32 0
      src/app/models/key-models/listkey.h
  63. 42 0
      src/app/models/key-models/listlikekey.cpp
  64. 20 0
      src/app/models/key-models/listlikekey.h
  65. 43 0
      src/app/models/key-models/newkeyrequest.cpp
  66. 68 0
      src/app/models/key-models/newkeyrequest.h
  67. 77 0
      src/app/models/key-models/rejsonkey.cpp
  68. 25 0
      src/app/models/key-models/rejsonkey.h
  69. 112 0
      src/app/models/key-models/rowcache.h
  70. 67 0
      src/app/models/key-models/setkey.cpp
  71. 19 0
      src/app/models/key-models/setkey.h
  72. 149 0
      src/app/models/key-models/sortedsetkey.cpp
  73. 28 0
      src/app/models/key-models/sortedsetkey.h
  74. 198 0
      src/app/models/key-models/stream.cpp
  75. 31 0
      src/app/models/key-models/stream.h
  76. 98 0
      src/app/models/key-models/stringkey.cpp
  77. 31 0
      src/app/models/key-models/stringkey.h
  78. 7 0
      src/app/models/key-models/unknownkey.cpp
  79. 44 0
      src/app/models/key-models/unknownkey.h
  80. 559 0
      src/app/models/treeoperations.cpp
  81. 147 0
      src/app/models/treeoperations.h
  82. 635 0
      src/app/qcompress.cpp
  83. 46 0
      src/app/qcompress.h
  84. 361 0
      src/app/qmlutils.cpp
  85. 50 0
      src/app/qmlutils.h
  86. 98 0
      src/main.cpp
  87. 175 0
      src/modules/bulk-operations/bulkoperationsmanager.cpp
  88. 87 0
      src/modules/bulk-operations/bulkoperationsmanager.h
  89. 17 0
      src/modules/bulk-operations/connections.h
  90. 116 0
      src/modules/bulk-operations/operations/abstractoperation.cpp
  91. 82 0
      src/modules/bulk-operations/operations/abstractoperation.h
  92. 125 0
      src/modules/bulk-operations/operations/copyoperation.cpp
  93. 36 0
      src/modules/bulk-operations/operations/copyoperation.h
  94. 82 0
      src/modules/bulk-operations/operations/deleteoperation.cpp
  95. 31 0
      src/modules/bulk-operations/operations/deleteoperation.h
  96. 139 0
      src/modules/bulk-operations/operations/rdbimport.cpp
  97. 38 0
      src/modules/bulk-operations/operations/rdbimport.h
  98. 73 0
      src/modules/bulk-operations/operations/ttloperation.cpp
  99. 32 0
      src/modules/bulk-operations/operations/ttloperation.h
  100. 26 0
      src/modules/common/baselistmodel.cpp

+ 90 - 0
.gitignore

@@ -0,0 +1,90 @@
+*.user
+*.aps
+*.pch
+*.vspscc
+*_i.c
+*_p.c
+*.ncb
+*.suo
+*.bak
+*.cache
+*.ilk
+*.log
+[Bb]in
+[Dd]ebug*/
+*.sbr
+obj/
+[Rr]elease*/
+_ReSharper*/
+*.sdf
+*.opensdf
+*/GeneratedFiles/*
+build-redis*
+
+.vagrant/*
+redis-desktop-manager/Makefile*
+build/redis*
+build/gbreakpad*
+redis-desktop-manager/connections.xml
+*.deb
+deps/libssh/example/.deps/*
+deps/libssh/example/.*
+deps/libssh/example/*
+deps/libssh/config.status
+deps/libssh/docs/Makefile
+deps/libssh/libssh2.pc
+deps/libssh/libtool
+deps/libssh/Makefile
+deps/libssh/src/.*
+deps/libssh/*.lo
+deps/libssh/src/**.o
+deps/libssh/*.lo
+deps/libssh/*/*.*o
+deps/libssh/*/*.la
+deps/libssh/tests/*
+deps/libssh/src/libssh2_config.h
+deps/libssh/src/Makefile
+deps/libssh/src/stamp-h1
+build-tests-*/*
+tests/Makefile
+tests/qml_tests/target_wrapper.sh
+deps/jsoncpp/buildscons/*
+deps/jsoncpp/dist/*
+deps/jsoncpp/libs/*
+redis-desktop-manager*.gz
+build/cpp-coveralls/*
+build/requests/*
+.svn/
+deps/gyp*
+*.vsp
+*.psess
+build/windows/installer/redis-desktop-manager*.exe
+vagrant-provision/automake*
+RDM.sln.metaproj*
+crashreports/*
+redis-desktop-manager/ui_*.h
+src/ui_*.h
+src/Makefile*
+build-rdm-*
+src/rdm.pro.*
+tests/tests.pro.*
+.idea*
+*~
+*Makefile
+*.DS_Store
+tests/unit_tests/coverage*
+*.qmlc
+*.jsc
+.qmake.stash
+parts
+prime
+stage
+3rdparty/python*
+__pycache__/
+qml_*.cpp
+src/modules/extension-server/server*
+.openapi-generator*
+build-*
+*.xcodeproj
+.xcode
+*qmlcache*

+ 24 - 0
.gitmodules

@@ -0,0 +1,24 @@
+[submodule "3rdparty/qredisclient"]
+	path = 3rdparty/qredisclient
+	url = https://github.com/uglide/qredisclient.git
+[submodule "3rdparty/pyotherside"]
+	path = 3rdparty/pyotherside
+	url = https://github.com/uglide/pyotherside.git
+[submodule "3rdparty/lz4"]
+	path = 3rdparty/lz4
+	url = https://github.com/lz4/lz4.git
+[submodule "3rdparty/simdjson"]
+	path = 3rdparty/simdjson
+	url = https://github.com/simdjson/simdjson.git
+[submodule "3rdparty/zstd"]
+	path = 3rdparty/zstd
+	url = https://github.com/facebook/zstd.git
+[submodule "3rdparty/snappy"]
+	path = 3rdparty/snappy
+	url = https://github.com/google/snappy.git
+[submodule "3rdparty/brotli"]
+	path = 3rdparty/brotli
+	url = https://github.com/google/brotli.git
+[submodule "3rdparty/fakeit"]
+	path = 3rdparty/fakeit
+	url = https://github.com/eranpeer/FakeIt.git

+ 15 - 0
.readthedocs.yaml

@@ -0,0 +1,15 @@
+version: 2
+
+# Set the version of Python and other tools you might need
+build:
+  os: ubuntu-20.04
+  tools:
+    python: "3.9"
+
+mkdocs:
+  configuration: mkdocs.yml
+
+# Optionally declare the Python requirements required to build your docs
+python:
+   install:
+   - requirements: docs/requirements.txt

+ 119 - 0
3rdparty/3rdparty.pri

@@ -0,0 +1,119 @@
+#-------------------------------------------------
+#
+# Redis Desktop Manager Dependencies
+#
+#-------------------------------------------------
+
+exists( $$_PRO_FILE_PWD_/modules/extension-server/client/client.pri) {
+    message("RESP.app Extension server integration was enabled")
+    DEFINES += ENABLE_EXTERNAL_FORMATTERS
+    HEADERS += $$_PRO_FILE_PWD_/modules/extension-server/dataformattermanager.h
+    SOURCES += $$_PRO_FILE_PWD_/modules/extension-server/dataformattermanager.cpp
+    include($$_PRO_FILE_PWD_/modules/extension-server/client/client.pri)
+}
+
+# qredisclient
+if(win32*):exists( $$PWD/qredisclient/qredisclient.lib ) {
+    message("Using prebuilt qredisclient")    
+    INCLUDEPATH += $$PWD/qredisclient/src/
+    OPENSSL_LIB_PATH = C:\OpenSSL-Win64\lib\VC
+    LIBS += -L$$OPENSSL_LIB_PATH -llibeay32MD -L$$PWD/qredisclient/ -lqredisclient -lbotan -llibssh2 -lgdi32 -lws2_32 -lkernel32 -luser32 -lshell32 -luuid -lole32 -ladvapi32
+    include($$PWD/qredisclient/3rdparty/asyncfuture/asyncfuture.pri)
+} else:unix*:exists( $$PWD/qredisclient/libqredisclient.a ) {
+    message("Using prebuilt qredisclient")
+    INCLUDEPATH += $$PWD/qredisclient/src/
+    LIBS += -L$$PWD/qredisclient/ -lqredisclient -lbotan-2 -lssh2 -lz -lssl -lcrypto
+    include($$PWD/qredisclient/3rdparty/asyncfuture/asyncfuture.pri)
+} else {
+    message("Using qredisclient source code")
+    include($$PWD/qredisclient/qredisclient.pri)
+}
+
+
+#PyOtherSide
+include($$PWD/pyotherside.pri)
+
+#LZ4
+LZ4DIR = $$PWD/lz4/
+INCLUDEPATH += $$LZ4DIR/lib
+
+#ZSTD
+ZSTDDIR = $$PWD/zstd/
+INCLUDEPATH += $$ZSTDDIR/lib
+
+#Snappy
+SNAPPYDIR = $$PWD/snappy
+INCLUDEPATH += $$SNAPPYDIR
+
+#Brotli
+BROTLIDIR = $$PWD/brotli
+INCLUDEPATH += $$BROTLIDIR/c/include
+
+#SIMDJSON
+SIMDJSONDIR = $$PWD/simdjson/singleheader
+INCLUDEPATH += $$SIMDJSONDIR/
+HEADERS += $$SIMDJSONDIR/simdjson.h
+SOURCES += $$SIMDJSONDIR/simdjson.cpp
+
+
+win32* {
+    ZLIBDIR = $$PWD/zlib-msvc14-x64.1.2.11.7795/build/native    
+    INCLUDEPATH += $$ZLIBDIR/include
+    LIBS += $$ZLIBDIR/lib_release/zlibstatic.lib $$LZ4DIR/build/cmake/Release/lz4.lib
+    LIBS += $$ZSTDDIR/build/cmake/lib/Release/zstd_static.lib
+    LIBS += $$SNAPPYDIR/Release/snappy.lib
+    LIBS += -L$$BROTLIDIR/Release/ -lbrotlicommon-static -lbrotlidec-static -lbrotlienc-static
+}
+
+unix:macx { # OSX
+    LIBS += -lz $$LZ4DIR/build/cmake/liblz4.a $$ZSTDDIR/build/cmake/lib/libzstd.a
+    LIBS += $$SNAPPYDIR/libsnappy.a
+    LIBS += -L$$BROTLIDIR/ -lbrotlicommon-static -lbrotlidec-static -lbrotlienc-static
+}
+
+unix:!macx { # ubuntu & debian   
+    defined(CLEAN_RPATH, var) { # clean default flags
+        message("DEB package build")
+        QMAKE_LFLAGS_RPATH=
+        QMAKE_LFLAGS = -Wl,-rpath=\\\$$ORIGIN/../lib
+        QMAKE_LFLAGS += -static-libgcc -static-libstdc++
+    } else {
+        # Note: uncomment if qtcreator fails to find QtCore dependencies
+        #QMAKE_LFLAGS = -Wl,-rpath=/home/user/Qt5.9.3/5.9.3/gcc_64/lib
+    }
+
+    LIBS += -lz
+    defined(SYSTEM_LZ4, var) {
+        LIBS += -llz4
+    } else {
+        LIBS += $$LZ4DIR/build/cmake/liblz4.a
+    }
+
+    defined(SYSTEM_ZSTD, var) {
+        LIBS += -lzstd
+    } else {
+        LIBS += $$ZSTDDIR/build/cmake/lib/libzstd.a
+    }
+
+    defined(SYSTEM_SNAPPY, var) {
+        LIBS += -lsnappy
+    } else {
+        LIBS += $$SNAPPYDIR/libsnappy.a
+    }
+
+    defined(SYSTEM_BROTLI, var) {
+        LIBS += -lbrotlicommon -lbrotlidec -lbrotlienc
+    } else {
+        LIBS += -L$$BROTLIDIR/ -lbrotlienc-static -lbrotlicommon-static -lbrotlidec-static
+    }
+
+    # Unix signal watcher
+    defined(LINUX_SIGNALS, var) {
+        message("Build with qt-unix-signals")
+
+        DEFINES += LINUX_SIGNALS
+        HEADERS += $$PWD/qt-unix-signals/sigwatch.h
+        SOURCES += $$PWD/qt-unix-signals/sigwatch.cpp
+        INCLUDEPATH += $$PWD/qt-unix-signals/
+    }
+}

+ 89 - 0
3rdparty/pyotherside.pri

@@ -0,0 +1,89 @@
+
+# Python
+PY_VERSION="39"
+PY_WIN_VERSION="38"
+PY_LIB_SUFFIX="3.9"
+
+win32* {
+    QMAKE_LIBS += -LC:\Python$${PY_WIN_VERSION}-x64\libs -lpython$${PY_WIN_VERSION}
+    INCLUDEPATH += C:\Python$${PY_WIN_VERSION}-x64\include\
+} else {
+    unix:macx {
+      exists($$PWD/python-3) {
+        message("Using Python from 3rdparty dir")
+        LIBS += $$PWD/python-3/lib/libpython$${PY_LIB_SUFFIX}.dylib
+        INCLUDEPATH += $$PWD/python-3/include/python$${PY_LIB_SUFFIX}
+
+        #deployment
+        PY_DATA_FILES.files = $$PWD/python-3/lib/libpython$${PY_LIB_SUFFIX}.dylib
+        PY_DATA_FILES.path = Contents/Frameworks
+        QMAKE_BUNDLE_DATA += PY_DATA_FILES
+
+      } else {
+       PYTHON_CONFIG = /usr/local/bin/python3-config
+       QMAKE_LIBS += $$system($$PYTHON_CONFIG --ldflags --libs --embed)
+       QMAKE_CXXFLAGS += $$system($$PYTHON_CONFIG --includes)
+      }
+    } else {
+      PYTHON_CONFIG = python3-config
+
+      PYTHON_VERSION = $$str_member($$system(python3 --version), 7, 11)
+      message("Python version $$PYTHON_VERSION")
+
+      versionAtLeast(PYTHON_VERSION, "3.8.0") {        
+        QMAKE_LIBS += $$system($$PYTHON_CONFIG --ldflags --libs --embed)
+      } else {
+        QMAKE_LIBS += $$system($$PYTHON_CONFIG --ldflags --libs)
+      }
+
+      QMAKE_CXXFLAGS += $$system($$PYTHON_CONFIG --includes)
+      DEFINES *= HAVE_DLADDR
+    }
+}
+
+include(pyotherside/pyotherside.pri)
+
+DEFINES += PYOTHERSIDE_VERSION=\\\"$${VERSION}\\\"
+
+DEPENDPATH += $$PWD/pyotherside/src
+INCLUDEPATH += $$PWD/pyotherside/src
+
+PYOTHERSIDE_DIR = $$PWD/pyotherside/src/
+
+# Importer from Qt Resources
+RESOURCES += $$PYOTHERSIDE_DIR/qrc_importer.qrc
+
+HEADERS += $$PYOTHERSIDE_DIR/pythonlib_loader.h\
+    $$PWD/pyotherside/src/callback.h
+SOURCES += $$PYOTHERSIDE_DIR/pythonlib_loader.cpp
+
+# Python QML Object
+SOURCES += $$PYOTHERSIDE_DIR/qpython.cpp
+HEADERS += $$PYOTHERSIDE_DIR/qpython.h
+SOURCES += $$PYOTHERSIDE_DIR/qpython_worker.cpp
+HEADERS += $$PYOTHERSIDE_DIR/qpython_worker.h
+SOURCES += $$PYOTHERSIDE_DIR/qpython_priv.cpp
+HEADERS += $$PYOTHERSIDE_DIR/qpython_priv.h
+HEADERS += $$PYOTHERSIDE_DIR/python_wrap.h
+
+# Globally Load Python hack
+SOURCES += $$PYOTHERSIDE_DIR/global_libpython_loader.cpp
+HEADERS += $$PYOTHERSIDE_DIR/global_libpython_loader.h
+
+# Reference-counting PyObject wrapper class
+SOURCES += $$PYOTHERSIDE_DIR/pyobject_ref.cpp
+HEADERS += $$PYOTHERSIDE_DIR/pyobject_ref.h
+
+# QObject wrapper class exposed to Python
+SOURCES += $$PYOTHERSIDE_DIR/qobject_ref.cpp
+HEADERS += $$PYOTHERSIDE_DIR/qobject_ref.h
+HEADERS += $$PYOTHERSIDE_DIR/pyqobject.h
+
+# GIL helper
+HEADERS += $$PYOTHERSIDE_DIR/ensure_gil_state.h
+
+# Type System Conversion Logic
+HEADERS += $$PYOTHERSIDE_DIR/converter.h
+HEADERS += $$PYOTHERSIDE_DIR/qvariant_converter.h
+HEADERS += $$PYOTHERSIDE_DIR/pyobject_converter.h
+HEADERS += $$PYOTHERSIDE_DIR/qml_python_bridge.h

+ 102 - 0
BACKERS.md

@@ -0,0 +1,102 @@
+## RDM Backers
+
+1.  peters
+2.  WillPerone
+3.  cblage
+4.  richard.hoogenboom
+5.  rodogu
+6.  markoan
+7.  tomlobato
+8.  sun.ming.77
+9.  Wrhector
+10.  trelsco
+11.  Sai P.S.
+12.  mostly-harmless
+13.  chasm
+14.  Clayton Sayer
+15.  henkvos
+16.  syrusm
+17.  stgogm
+18.  pmercier
+19.  elliots
+20.  Itamar Haber
+21.  Kelson
+22.  linux_china
+23.  mjirby
+24.  cristianobaptista
+25.  Scott Steele
+26.  caywood
+27.  GuRui
+28.  ryanski44
+29.  alex.mirrr
+30.  andrewjknox
+31.  chrisgo
+32.  Rob T.
+33.  chrismckee
+34.  ritxi
+35.  Recumbented
+36.  imesner
+37.  ragboy
+38.  tinou.bao
+39.  dbrugne
+40.  brianberlin
+41.  noocyte
+42.  yu, Wu
+43.  Alejandra
+44.  ne0zen
+45.  Macarun
+46.  Mitch
+47.  STRML
+48.  somebody
+49.  sachinwalia
+50.  Wayne Robinson
+51.  PyYoshi
+52.  JHoffmanME
+53.  sebastian.stanisor
+54.  xurumelous
+55.  nilskp
+56.  science
+57.  cicorias
+58.  BrianLocke
+59.  anoordende
+60.  pablovilas
+61.  runes83
+62.  chentex
+63.  forcer
+64.  ikary
+65.  eduardomcrodrigues
+66.  Christophe Cholot
+67.  mickdelaney
+68.  SwaroopH
+69.  David Jonasson
+70.  dean.mehmet
+71.  lyhdj001
+72.  gary.weng.10
+73.  okachan_0417
+74.  xbtequila
+75.  ducu
+76.  timeblimp
+77.  rduplain
+78.  Salada
+79.  djolaq
+80.  Alric
+81.  patrick
+82.  descipar
+83.  marcin.glenszczyk
+84.  Benni
+85.  ksatirli
+86.  devcrust
+87.  Soheil
+88.  rsafier
+89.  leftis
+90.  Brayyy
+91.  artsard
+92.  irvingswiftj
+93.  KeyManPL
+94.  atierant
+95.  tomascayuelas
+96.  kiyoaki
+97.  Jesper Niedermann
+98.  Jingjie Zheng
+99.  humiaozuzu
+100.  rolfvreijdenberger

+ 44 - 0
CONTRIBUTING.md

@@ -0,0 +1,44 @@
+
+## IMPORTANT: HOW TO ADD ISSUES
+
+* GitHub issues **SHOULD ONLY BE USED to report bugs**, and for DETAILED feature
+  requests. Everything else belongs to the [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/uglide/RedisDesktopManager)
+
+  **PLEASE DO NOT POST GENERAL QUESTIONS** that are not about bugs or suspected
+  bugs in the GitHub issues system. We'll be very happy to help you and provide
+  all the support in the [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/uglide/RedisDesktopManager) 
+
+### Bug report template:
+
+	Version:
+	Environment:
+	Redis Server Version:
+
+	Steps to reproduce:
+	1.
+	2.
+	3.
+
+	Expected result:
+
+	Actual Result:
+
+
+### Example of bug report:
+
+	Version: 0.6.2
+	Environment: Windows 7 SP1 x64
+	Redis Server Version: 2.8.1
+
+	Steps to reproduce:
+	1.Click on RedisDesktopManager.ink
+	2.Click on Add Connection button	
+
+	Expected result: Active dialog window
+
+	Actual Result: Crash
+
+
+
+
+

+ 10 - 0
COPYRIGHT

@@ -0,0 +1,10 @@
+RESP.app (formerly RedisDesktopManager), Cross-platform GUI management tool for Redis®
+
+Copyright 2013-2022, Ihor Malinovskyi.
+
+The RESP.app is released under the terms of the GNU General Public
+License, version 3.
+
+The RESP.app Project includes files written by third
+parties and used with permission or subject to their respective 
+license agreements.

+ 674 - 0
LICENSE

@@ -0,0 +1,674 @@
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+  The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works.  By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.  We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors.  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+  To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights.  Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received.  You must make sure that they, too, receive
+or can get the source code.  And you must show them these terms so they
+know their rights.
+
+  Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+  For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software.  For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+  Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so.  This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software.  The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable.  Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products.  If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+  Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary.  To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                       TERMS AND CONDITIONS
+
+  0. Definitions.
+
+  "This License" refers to version 3 of the GNU General Public License.
+
+  "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+  "The Program" refers to any copyrightable work licensed under this
+License.  Each licensee is addressed as "you".  "Licensees" and
+"recipients" may be individuals or organizations.
+
+  To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy.  The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+  A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+  To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy.  Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+  To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies.  Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+  An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License.  If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+  1. Source Code.
+
+  The "source code" for a work means the preferred form of the work
+for making modifications to it.  "Object code" means any non-source
+form of a work.
+
+  A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+  The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form.  A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+  The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities.  However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work.  For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+  The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+  The Corresponding Source for a work in source code form is that
+same work.
+
+  2. Basic Permissions.
+
+  All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met.  This License explicitly affirms your unlimited
+permission to run the unmodified Program.  The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work.  This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+  You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force.  You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright.  Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+  Conveying under any other circumstances is permitted solely under
+the conditions stated below.  Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+  No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+  When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+  4. Conveying Verbatim Copies.
+
+  You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+  You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+  5. Conveying Modified Source Versions.
+
+  You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+    a) The work must carry prominent notices stating that you modified
+    it, and giving a relevant date.
+
+    b) The work must carry prominent notices stating that it is
+    released under this License and any conditions added under section
+    7.  This requirement modifies the requirement in section 4 to
+    "keep intact all notices".
+
+    c) You must license the entire work, as a whole, under this
+    License to anyone who comes into possession of a copy.  This
+    License will therefore apply, along with any applicable section 7
+    additional terms, to the whole of the work, and all its parts,
+    regardless of how they are packaged.  This License gives no
+    permission to license the work in any other way, but it does not
+    invalidate such permission if you have separately received it.
+
+    d) If the work has interactive user interfaces, each must display
+    Appropriate Legal Notices; however, if the Program has interactive
+    interfaces that do not display Appropriate Legal Notices, your
+    work need not make them do so.
+
+  A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit.  Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+  6. Conveying Non-Source Forms.
+
+  You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+    a) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by the
+    Corresponding Source fixed on a durable physical medium
+    customarily used for software interchange.
+
+    b) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by a
+    written offer, valid for at least three years and valid for as
+    long as you offer spare parts or customer support for that product
+    model, to give anyone who possesses the object code either (1) a
+    copy of the Corresponding Source for all the software in the
+    product that is covered by this License, on a durable physical
+    medium customarily used for software interchange, for a price no
+    more than your reasonable cost of physically performing this
+    conveying of source, or (2) access to copy the
+    Corresponding Source from a network server at no charge.
+
+    c) Convey individual copies of the object code with a copy of the
+    written offer to provide the Corresponding Source.  This
+    alternative is allowed only occasionally and noncommercially, and
+    only if you received the object code with such an offer, in accord
+    with subsection 6b.
+
+    d) Convey the object code by offering access from a designated
+    place (gratis or for a charge), and offer equivalent access to the
+    Corresponding Source in the same way through the same place at no
+    further charge.  You need not require recipients to copy the
+    Corresponding Source along with the object code.  If the place to
+    copy the object code is a network server, the Corresponding Source
+    may be on a different server (operated by you or a third party)
+    that supports equivalent copying facilities, provided you maintain
+    clear directions next to the object code saying where to find the
+    Corresponding Source.  Regardless of what server hosts the
+    Corresponding Source, you remain obligated to ensure that it is
+    available for as long as needed to satisfy these requirements.
+
+    e) Convey the object code using peer-to-peer transmission, provided
+    you inform other peers where the object code and Corresponding
+    Source of the work are being offered to the general public at no
+    charge under subsection 6d.
+
+  A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+  A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling.  In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage.  For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product.  A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+  "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source.  The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+  If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information.  But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+  The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed.  Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+  Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+  7. Additional Terms.
+
+  "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law.  If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+  When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it.  (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.)  You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+  Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+    a) Disclaiming warranty or limiting liability differently from the
+    terms of sections 15 and 16 of this License; or
+
+    b) Requiring preservation of specified reasonable legal notices or
+    author attributions in that material or in the Appropriate Legal
+    Notices displayed by works containing it; or
+
+    c) Prohibiting misrepresentation of the origin of that material, or
+    requiring that modified versions of such material be marked in
+    reasonable ways as different from the original version; or
+
+    d) Limiting the use for publicity purposes of names of licensors or
+    authors of the material; or
+
+    e) Declining to grant rights under trademark law for use of some
+    trade names, trademarks, or service marks; or
+
+    f) Requiring indemnification of licensors and authors of that
+    material by anyone who conveys the material (or modified versions of
+    it) with contractual assumptions of liability to the recipient, for
+    any liability that these contractual assumptions directly impose on
+    those licensors and authors.
+
+  All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10.  If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term.  If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+  If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+  Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+  8. Termination.
+
+  You may not propagate or modify a covered work except as expressly
+provided under this License.  Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+  However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+  Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+  Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License.  If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+  9. Acceptance Not Required for Having Copies.
+
+  You are not required to accept this License in order to receive or
+run a copy of the Program.  Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance.  However,
+nothing other than this License grants you permission to propagate or
+modify any covered work.  These actions infringe copyright if you do
+not accept this License.  Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+  10. Automatic Licensing of Downstream Recipients.
+
+  Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License.  You are not responsible
+for enforcing compliance by third parties with this License.
+
+  An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations.  If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+  You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License.  For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+  11. Patents.
+
+  A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based.  The
+work thus licensed is called the contributor's "contributor version".
+
+  A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version.  For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+  In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement).  To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+  If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients.  "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+  If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+  A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License.  You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+  Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+  12. No Surrender of Others' Freedom.
+
+  If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all.  For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+  13. Use with the GNU Affero General Public License.
+
+  Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work.  The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+  14. Revised Versions of this License.
+
+  The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+  Each version is given a distinguishing version number.  If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation.  If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+  If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+  Later license versions may give you additional or different
+permissions.  However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+  15. Disclaimer of Warranty.
+
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. Limitation of Liability.
+
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+  17. Interpretation of Sections 15 and 16.
+
+  If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+  If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+    <program>  Copyright (C) <year>  <name of author>
+    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+  You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+  The GNU General Public License does not permit incorporating your program
+into proprietary programs.  If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.  But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.

+ 10 - 0
README.md

@@ -0,0 +1,10 @@
+## RESP.app - GUI for Redis &reg; (Formerly RedisDesktopManager)
+
+### RESP.app is joining forces with Redis to offer the Redis community the best possible developer experience and to increase productivity when developing with Redis.
+Please read [this blog post](https://redis.com/blog/respapp-joining-redis/) where we share more details, and you can also visit the [FAQ](https://resp.app/faq).
+
+<hr>
+
+![RESP.app screenshot](http://resp.app/static/img/features/all.png?v2021)
+
+

BIN
build/windows/installer/images/main.bmp


+ 53 - 0
build/windows/installer/include/install_vcredist_x64.nsh

@@ -0,0 +1,53 @@
+!include LogicLib.nsh
+
+!macro InstallVCredist
+  !define VCplus_URL "https://aka.ms/vs/16/release/VC_redist.x64.exe"
+
+  ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x64" Bld
+  ${If} $0 >= 27033
+    goto VCInstalled
+  ${Else}
+    goto VCDownload
+  ${EndIf}
+
+  VCDownload:
+  DetailPrint "Beginning download of VC++ 2015-2019 Redistributable."
+  inetc::get /TIMEOUT=30000 ${VCplus_URL} "$TEMP\vc_redist.x64.exe" /END
+  Pop $0
+  DetailPrint "Result: $0"
+  StrCmp $0 "OK" InstallVCplusplus
+  StrCmp $0 "cancelled" VCCanceled
+  inetc::get /TIMEOUT=30000 /NOPROXY ${VCplus_URL} "$TEMP\vc_redist.x64.exe" /END
+  Pop $0
+  DetailPrint "Result: $0"
+  StrCmp $0 "OK" InstallVCplusplus
+
+  MessageBox MB_ICONEXCLAMATION "Cannot download VC++ 2015-2019 Redistributable. Please install it manually if you experience any issues: ${VCplus_URL}"
+  ExecShell open "${VCplus_URL}"
+  goto VCInstalled
+
+  InstallVCplusplus:
+  DetailPrint "Completed download."
+  Pop $0
+  ${If} $0 == "cancel"
+    MessageBox MB_YESNO|MB_ICONEXCLAMATION \
+    "Download cancelled.  Continue Installation?" \
+    IDYES VCInstalled IDNO VCCanceled
+  ${EndIf}
+
+  DetailPrint "Pausing installation while downloaded VC++ installer runs."
+  DetailPrint "Installation could take several minutes to complete."
+  ExecWait '$TEMP\vc_redist.x64.exe /passive /norestart'
+
+  DetailPrint "Removing VC++ installer."
+  Delete "$TEMP\vc_redist.x64.exe"
+
+  DetailPrint "VC++ installer removed."
+  goto VCInstalled
+
+VCCanceled:
+  Abort "Installation cancelled by user."
+
+VCInstalled:
+  Pop $0
+!macroend

+ 28 - 0
build/windows/installer/include/nsProcess.nsh

@@ -0,0 +1,28 @@
+!define nsProcess::FindProcess `!insertmacro nsProcess::FindProcess`
+
+!macro nsProcess::FindProcess _FILE _ERR
+	nsProcess::_FindProcess /NOUNLOAD `${_FILE}`
+	Pop ${_ERR}
+!macroend
+
+
+!define nsProcess::KillProcess `!insertmacro nsProcess::KillProcess`
+
+!macro nsProcess::KillProcess _FILE _ERR
+	nsProcess::_KillProcess /NOUNLOAD `${_FILE}`
+	Pop ${_ERR}
+!macroend
+
+!define nsProcess::CloseProcess `!insertmacro nsProcess::CloseProcess`
+
+!macro nsProcess::CloseProcess _FILE _ERR
+	nsProcess::_CloseProcess /NOUNLOAD `${_FILE}`
+	Pop ${_ERR}
+!macroend
+
+
+!define nsProcess::Unload `!insertmacro nsProcess::Unload`
+
+!macro nsProcess::Unload
+	nsProcess::_Unload
+!macroend

+ 54 - 0
build/windows/installer/include/x64.nsh

@@ -0,0 +1,54 @@
+; ---------------------
+;       x64.nsh
+; ---------------------
+;
+; A few simple macros to handle installations on x64 machines.
+;
+; RunningX64 checks if the installer is running on x64.
+;
+;   ${If} ${RunningX64}
+;     MessageBox MB_OK "running on x64"
+;   ${EndIf}
+;
+; DisableX64FSRedirection disables file system redirection.
+; EnableX64FSRedirection enables file system redirection.
+;
+;   SetOutPath $SYSDIR
+;   ${DisableX64FSRedirection}
+;   File some.dll # extracts to C:\Windows\System32
+;   ${EnableX64FSRedirection}
+;   File some.dll # extracts to C:\Windows\SysWOW64
+;
+
+!ifndef ___X64__NSH___
+!define ___X64__NSH___
+
+!include LogicLib.nsh
+
+!macro _RunningX64 _a _b _t _f
+  !insertmacro _LOGICLIB_TEMP
+  System::Call kernel32::GetCurrentProcess()i.s
+  System::Call kernel32::IsWow64Process(is,*i.s)
+  Pop $_LOGICLIB_TEMP
+  !insertmacro _!= $_LOGICLIB_TEMP 0 `${_t}` `${_f}`
+!macroend
+
+!define RunningX64 `"" RunningX64 ""`
+
+!macro DisableX64FSRedirection
+
+  System::Call kernel32::Wow64EnableWow64FsRedirection(i0)
+
+!macroend
+
+!define DisableX64FSRedirection "!insertmacro DisableX64FSRedirection"
+
+!macro EnableX64FSRedirection
+
+  System::Call kernel32::Wow64EnableWow64FsRedirection(i1)
+
+!macroend
+
+!define EnableX64FSRedirection "!insertmacro EnableX64FSRedirection"
+
+!endif # !___X64__NSH___

+ 167 - 0
build/windows/installer/installer.nsi

@@ -0,0 +1,167 @@
+!addincludedir .\include
+!addplugindir .\plugin
+
+Name "RESP.app (formerly RedisDesktopManager)"
+
+BrandingText "Open source Developer GUI for Redis"
+
+RequestExecutionLevel admin
+
+SetCompress auto
+SetCompressor /SOLID /FINAL lzma
+ManifestDPIAware true
+
+# General Symbol Definitions
+!define REGKEY "SOFTWARE\$(Name)"
+!define COMPANY "Igor Malinovskiy"
+!define URL resp.app
+!define APP_EXE "resp.exe"
+
+# MUI Symbol Definitions
+!define MUI_ICON "..\..\..\src\resources\images\logo.ico"
+!define MUI_FINISHPAGE_NOAUTOCLOSE
+!define MUI_FINISHPAGE_RUN $INSTDIR\${APP_EXE}
+!define MUI_UNICON "..\..\..\src\resources\images\logo.ico"
+!define MUI_WELCOMEFINISHPAGE_BITMAP ".\images\main.bmp"
+
+# Included files
+!include "nsProcess.nsh"
+!include "x64.nsh"
+!include "install_vcredist_x64.nsh"
+!include Sections.nsh
+!include MUI2.nsh
+
+# Variables
+Var StartMenuGroup
+
+# Installer pages
+!insertmacro MUI_PAGE_WELCOME
+!insertmacro MUI_PAGE_LICENSE ..\..\..\LICENSE
+!insertmacro MUI_PAGE_DIRECTORY
+!insertmacro MUI_PAGE_INSTFILES
+!insertmacro MUI_PAGE_FINISH
+!insertmacro MUI_UNPAGE_CONFIRM
+!insertmacro MUI_UNPAGE_INSTFILES
+
+
+# Installer languages
+!insertmacro MUI_LANGUAGE English
+
+# Installer attributes
+OutFile resp-${VERSION}.exe
+InstallDir $PROGRAMFILES64\RESP_app
+CRCCheck on
+XPStyle on
+ShowInstDetails show
+VIProductVersion ${VERSION}.0
+VIAddVersionKey /LANG=${LANG_ENGLISH} ProductName "RESP.app (formerly RedisDesktopManager)"
+VIAddVersionKey /LANG=${LANG_ENGLISH} ProductVersion "${VERSION}"
+VIAddVersionKey /LANG=${LANG_ENGLISH} CompanyName "${COMPANY}"
+VIAddVersionKey /LANG=${LANG_ENGLISH} CompanyWebsite "${URL}"
+VIAddVersionKey /LANG=${LANG_ENGLISH} FileVersion "${VERSION}"
+VIAddVersionKey /LANG=${LANG_ENGLISH} FileDescription ""
+VIAddVersionKey /LANG=${LANG_ENGLISH} LegalCopyright ""
+InstallDirRegKey HKLM "${REGKEY}" Path
+ShowUninstDetails show
+
+
+# Installer sections
+Section -Main SEC0000
+    ${nsProcess::KillProcess} "rdm.exe" $R4
+    ${nsProcess::KillProcess} "${APP_EXE}" $R4
+
+    ${IfNot} ${RunningX64}
+        MessageBox MB_OK "Starting from version 2019.0.0, RESP.app doesn't support 32-bit Windows"
+        Quit
+    ${EndIf}
+
+    IfFileExists $INSTDIR\uninstall.exe already_installed not_installed
+    already_installed:
+    CopyFiles /SILENT /FILESONLY "$INSTDIR\uninstall.exe" "$INSTDIR\uninstall_.exe"
+    ExecWait '"$INSTDIR\uninstall_.exe" /S _?=$INSTDIR'
+    Sleep 100
+    Delete /REBOOTOK $INSTDIR\uninstall_.exe
+
+    not_installed:
+    SetOutPath $INSTDIR    
+    File /r resources\*
+    WriteRegStr HKLM "${REGKEY}\Components" Main 1
+    !insertmacro InstallVCredist
+    BringToFront
+SectionEnd
+
+Section -post SEC0001
+    WriteRegStr HKLM "${REGKEY}" Path $INSTDIR
+    SetOutPath $INSTDIR
+    WriteUninstaller $INSTDIR\uninstall.exe
+    SetOutPath $SMPROGRAMS\$StartMenuGroup
+    
+    CreateShortCut "$DESKTOP\RESP.lnk" "$INSTDIR\${APP_EXE}" ""
+    
+    IfSilent 0 +2
+        Exec "$INSTDIR\${APP_EXE}"
+
+    CreateShortcut "$SMPROGRAMS\$StartMenuGroup\RESP.lnk" "$INSTDIR\${APP_EXE}"
+    CreateShortcut "$SMPROGRAMS\$StartMenuGroup\$(^UninstallLink).lnk" $INSTDIR\uninstall.exe
+
+    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayName "$(^Name)"
+    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayVersion "${VERSION}"
+    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" Publisher "${COMPANY}"
+    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" URLInfoAbout "${URL}"
+    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayIcon $INSTDIR\uninstall.exe
+    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" UninstallString $INSTDIR\uninstall.exe
+    WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" NoModify 1
+    WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" NoRepair 1
+SectionEnd
+
+# Macro for selecting uninstaller sections
+!macro SELECT_UNSECTION SECTION_NAME UNSECTION_ID
+    Push $R0
+    ReadRegStr $R0 HKLM "${REGKEY}\Components" "${SECTION_NAME}"
+    StrCmp $R0 1 0 next${UNSECTION_ID}
+    !insertmacro SelectSection "${UNSECTION_ID}"
+    GoTo done${UNSECTION_ID}
+next${UNSECTION_ID}:
+    !insertmacro UnselectSection "${UNSECTION_ID}"
+done${UNSECTION_ID}:
+    Pop $R0
+!macroend
+
+# Uninstaller sections
+Section /o -un.Main UNSEC0000
+    ${nsProcess::KillProcess} "${APP_EXE}" $R4
+    Sleep 1000
+    Delete /REBOOTOK $INSTDIR\*
+    RmDir /REBOOTOK /r $INSTDIR\*
+    DeleteRegValue HKLM "${REGKEY}\Components" Main
+SectionEnd
+
+Section -un.post UNSEC0001
+    DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)"
+    Delete /REBOOTOK "$DESKTOP\RESP.lnk"
+    Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\RESP.lnk"
+    Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\$(^UninstallLink).lnk"
+    Delete /REBOOTOK $INSTDIR\uninstall.exe
+    DeleteRegValue HKLM "${REGKEY}" Path
+    DeleteRegKey /IfEmpty HKLM "${REGKEY}\Components"
+    DeleteRegKey /IfEmpty HKLM "${REGKEY}"
+    RmDir /REBOOTOK $SMPROGRAMS\$StartMenuGroup
+    RmDir /REBOOTOK $INSTDIR
+SectionEnd
+
+# Installer functions
+Function .onInit
+    InitPluginsDir
+    StrCpy $StartMenuGroup RESP
+FunctionEnd
+
+# Uninstaller functions
+Function un.onInit
+    SetAutoClose true
+    ReadRegStr $INSTDIR HKLM "${REGKEY}" Path
+    StrCpy $StartMenuGroup RESP
+    !insertmacro SELECT_UNSECTION Main ${UNSEC0000}
+FunctionEnd
+
+# Installer Language Strings
+LangString ^UninstallLink ${LANG_ENGLISH} "Uninstall $(^Name)"

BIN
build/windows/installer/plugin/INetC.dll


BIN
build/windows/installer/plugin/nsProcess.dll


BIN
build/windows/installer/resources/libeay32.dll


+ 3 - 0
build/windows/installer/resources/qt.conf

@@ -0,0 +1,3 @@
+[Paths]
+Prefix=..
+

BIN
build/windows/installer/resources/ssleay32.dll


+ 5 - 0
docs/app-store.md

@@ -0,0 +1,5 @@
+## Limitations of App Store version
+
+* AppStore version of RESP.app doesn't support [Native Formatters](native-formatters.md)
+  
+  

+ 55 - 0
docs/bulk-operations.md

@@ -0,0 +1,55 @@
+# Bulk operations
+***
+
+RESP.app simplifies your Redis daily routines with bulk operations. To access bulk operations connect to Redis
+server and click on a target database like db0:
+
+<img src="http://resp.app/static/docs/bulk_operations.png?v=1" width="350" />
+
+## Supported bulk operations
+
+<img src="http://resp.app/static/docs/bulk_operations_list.png?v=1" width="350" />
+
+### Flush database
+
+It's a useful operation if you need to invalidate cache in a couple clicks instead of firing `FLUSHDB` command.
+> !!! warning "Be careful"
+    Do not use it on Production servers. You can safeguard your Production Redis server by using [a restricted user with limited permissions](https://redis.io/docs/manual/security/acl/).
+
+### Delete keys with filter
+
+If you need to remove some specific keys or a ["namespace"](lg-keyspaces.md#use-namespaced-keys) from your Redis server this bulk operation can come in handy.
+It allows you to specify a glob style pattern to define which keys should be removed.
+
+![](http://resp.app/static/docs/bulk_delete_keys.png?v=1)
+
+### Set TTL for multiple keys
+
+As you know, Redis is an in-memory database. You should be careful and set appropriate TTL for all keys otherwise Redis can 
+crash or stop responding after consuming all available memory. If you realized that some keys have wrong TTL values or don't have TTL at all you can fix it using RESP.app:
+
+![](http://resp.app/static/docs/bulk_ttl.png?v=1)
+
+
+### Copy keys from one Redis server to another
+
+Sometimes you need to copy some keys from a Production Redis server to local one for debugging or vice-versa.
+You can achieve that by writing custom script, however it's much easier to just make a couple of clicks in RESP.app to copy keys:
+
+> !!! warning "Limitations"
+    Currently RESP.app supports only copying data between redis-servers with the same RDB version. 
+    Usually it means that major versions of both Redis servers should be the same.  
+
+![](http://resp.app/static/docs/bulk_copy_keys.png?v=1)
+
+
+### Import keys directly from RDB files
+
+Usually, production Redis servers have [AOF or RDB back-ups or persistent files](https://redis.io/docs/manual/persistence/).
+While AOF is basically a file with all commands that should be played again to reconstruct original dataset, RDB files don't have such flexibility.
+Therefore, RESP.app provides a convenient way to easily import subset of data for debugging and testing directly from RDB file instead of creating additional load to your Production system.
+
+![](http://resp.app/static/docs/bulk_import_rdb.png?v=1)
+
+
+#### Is your use case not covered in RESP.app? [Contact us](mailto:support@resp.app), and we will do our best to solve it!  

+ 7 - 0
docs/css/extra.css

@@ -0,0 +1,7 @@
+img {
+   max-height: 500px;
+}
+
+code {
+ font-size: 11pt;
+}

+ 40 - 0
docs/development.md

@@ -0,0 +1,40 @@
+### Build RESP.app from source
+See [instruction](install.md#build-from-source)
+
+### Generate test data
+Open RESP.app console or redis-cli and execute:
+
+```lua
+eval "for index = 0,100000 do redis.call('SET', 'test_key' .. index, index) end" 0
+eval "for index = 0,100000 do redis.call('SET', 'test_key:' .. math.random(1, 100) .. ':' .. math.random(1,100), index) end" 0
+eval "for index = 0,100000 do redis.call('HSET', 'test_large_hash', index, index) end" 0
+eval "for index = 0,100000 do redis.call('ZADD', 'test_large_zset', index, index) end" 0
+eval "for index = 0,100000 do redis.call('SADD', 'test_large_set', index) end" 0
+eval "for index = 0,100000 do redis.call('LPUSH', 'test_large_list', index) end" 0
+```
+
+### App profiling
+
+```bash
+sudo apt-get install valgrind
+sudo add-apt-repository ppa:kubuntu-ppa/backports 
+sudo apt-get update
+sudo apt-get install massif-visualizer
+
+export LD_LIBRARY_PATH="/usr/share/redis-desktop-manager/lib":$LD_LIBRARY_PATH
+valgrind --tool=massif --massif-out-file=rdm.massif /usr/share/redis-desktop-manager/bin/rdm
+
+```
+
+### Debug SSL
+```bash
+openssl s_client -connect HOST:PORT -cert test_user.crt -key test.key -CAfile test_ca.pem
+```
+
+### Remove app settings on OSX
+```bash
+rm $HOME/Library/Preferences/com.redisdesktop.RedisDesktopManager.plist
+killall -u `whoami` cfprefsd
+```
+
+### Fix bugs or implement whatever you want :)

+ 60 - 0
docs/extension-server.md

@@ -0,0 +1,60 @@
+## RESP.app Extension Server
+
+Developers love Redis because it gives freedom to store anything they want in it.
+RESP.app shares this ideology by supporting automatic decompression (GZIP, LZ4, ZSTD, BROTLI, Snappy) and deserialization of common formats like MsgPack, PHP Sessions, CBOR and Pickle.
+
+Is your serialization format not mentioned above? Continue reading to find out how to easily view your data in RESP.app.
+
+### What is it?
+
+Starting from version `2022.4` RESP.app comes with a built-in client for Extension Server. Extension Server is a simple REST API defined by
+the following [OpenAPI Specification](extension-server.md#openapi-v3-specification). This server allows you to support 
+any custom compression or serialization format.
+
+### Build your own Extension Server in minutes
+
+Thanks to [OpenAPI Generator](https://openapi-generator.tech/docs/installation) you can generate boilerplate for your Extension Server in a couple of minutes.
+
+1. [Install OpenAPI Generator](https://openapi-generator.tech/docs/installation)
+2. Select [appropriate server generator](https://openapi-generator.tech/docs/generators#server-generators).
+3. Download spec file from `https://raw.githubusercontent.com/uglide/RedisDesktopManager/2022/docs/server_spec.yaml`
+4. Generate server: <br />
+`
+openapi-generator generate -i server_spec.yaml -g YOUR_GENERATOR -o my_extension_server
+`
+5. Open `my_extension_server` in your favorite IDE and start adding your custom formatters to generated server.
+
+
+**If you are faced with any issues you can [contact support](mailto:support@resp.app) or ask for help in [telegram chat](https://t.me/RedisDesktopManager)**
+
+
+### Connect to Extension Server in RESP.app
+
+1. Ensure that you are using RESP.app version `2022.4` or above
+2. Click on the "Extension Server" button in top right corner of the main window
+3. In the Extension Server dialog specify your server URL and basic auth details if any:
+<img src="http://resp.app/static/docs/extension-server.png" width="550" />
+4. Hit Reload button
+
+### Visualizing data with Extension Server
+
+RESP.app supports following `Content-Type` responses from Extension Server:
+
+- `application/json`
+- `image/*` for example `image/svg+xml`
+
+This allows you to perform any required preprocessing and visualize your data:
+<img src="http://resp.app/static/docs/extension-server-chart.png" width="550" />
+
+
+
+### OpenAPI v3 Specification
+
+**Please submit your proposals to the following spec on [GitHub](https://github.com/uglide/RedisDesktopManager/issues)**
+
+!!swagger server_spec.yaml!!
+
+
+### Third-party extension servers
+
+You can find some examples on [GitHub](https://github.com/search?q=resp.app+extension+server).

+ 11 - 0
docs/faq.md

@@ -0,0 +1,11 @@
+## Where is the connections config stored?
+
+**Windows** `%USERPROFILE%\.rdm\connections.json`
+
+**macOS dmg** `$HOME/Library/Preferences/rdm/connections.json`
+
+**macOS App Store** `$HOME/Library/Containers/com.redisdesktop.rdm/Data/Library/Preferences/rdm/`
+
+**Linux flatpak** `$HOME/.rdm/connections.json`
+
+**Linux snap** `$HOME/snap/redis-desktop-manager/common/.rdm/connections.json`

BIN
docs/favicon.ico


+ 11 - 0
docs/index.md

@@ -0,0 +1,11 @@
+# RESP.app Documentation
+
+RESP.app (formerly RedisDesktopManager) — is a cross-platform open source GUI for Redis &reg; available on Windows, Linux and macOS. This tool offers you an easy-to-use GUI to access your Redis &reg; DB and perform some basic operations: view keys as a tree, CRUD keys, execute commands via shell. RESP.app supports SSL/TLS encryption, SSH tunnels and cloud Redis instances, such as: Amazon ElastiCache, Microsoft Azure Redis Cache and other Redis &reg; clouds.    
+
+
+Please submit any issues and proposals on [GitHub](https://github.com/uglide/RedisDesktopManager/issues)
+
+
+
+
+#### Ask for help in [telegram chat](https://t.me/RedisDesktopManager)

+ 96 - 0
docs/install.md

@@ -0,0 +1,96 @@
+# Quick Install
+
+## Windows
+
+1. Install [Microsoft Visual C++ 2015-2019 x64](https://aka.ms/vs/16/release/vc_redist.x64.exe)  (If you have not already).
+2. Download Windows Installer from [http://resp.app/subscriptions](http://resp.app/subscriptions). **(Requires subscription)**
+3. Run the downloaded installer.
+
+## Mac OS X
+
+1. Download dmg image from [http://resp.app/subscriptions](http://resp.app/subscriptions). **(Requires subscription)**
+2. Mount the DMG image.
+3. Run rdm.app.
+
+## Ubuntu / ArchLinux / Debian / Fedora / CentOS / OpenSUSE / etc
+
+### Install flatpak
+
+1. Install RESP.app using [Flathub](https://flathub.org/apps/details/app.resp.RESP).
+
+> !!! info "How to install in command line"
+    Make sure to follow the [setup guide](https://flatpak.org/setup/) before installing
+    <br />`flatpak install flathub app.resp.RESP`
+
+> !!! tip "How to run"
+    If RESP.app icon hasn't appeared in your application launcher, you can run RESP.app from terminal with:
+    <br /> `flatpak run app.resp.RESP`
+
+### Install snap
+
+1. Install RESP.app using [Snapcraft](https://snapcraft.io/redis-desktop-manager).
+
+> !!! warning "SSH Keys"
+    To be able to access your ssh keys from RESP.app please connect `ssh-key` interface:
+    `sudo snap connect redis-desktop-manager:ssh-keys`
+    
+> !!! tip "How to Run"
+    If RESP.app icon hasn't appeared in your application launcher you can run RESP.app from terminal `/snap/bin/redis-desktop-manager.rdm`
+
+## Build from source
+
+### Get source
+
+1. Install git using the instructions here: https://git-scm.com/download
+    
+2. Get the source code:
+    ```
+    git clone --recursive https://github.com/uglide/RedisDesktopManager.git -b 2022 rdm && cd ./rdm
+    ```
+
+> !!! warning "SSH Tunneling support"
+    Since 0.9.9 RESP.app by default does not include SSH Tunneling support. You can create a SSH tunnel to your Redis server manually and connect to `localhost`:
+    `ssh -L 6379:REDIS_HOST:6379 SSH_USER@SSH_HOST -P SSH_PORT -i SSH_KEY -T -N` or [use pre-built binary for your OS](#quick-install)
+
+
+### Build on OS X
+
+1. Install [Xcode](https://developer.apple.com/xcode/) with Xcode build tools.
+2. Install [Homebrew](http://brew.sh/).
+3. Copy `cd ./src && cp ./resources/Info.plist.sample ./resources/Info.plist`.
+4. Building RESP.app dependencies require i.a. `openssl`, `cmake` and `python3`. Install them: `brew install openssl cmake python3`
+5. Build lz4 lib
+```
+cd 3rdparty/lz4/build/cmake
+cmake -DLZ4_BUNDLED_MODE=ON  .
+make
+cd 3rdparty/brotli
+cmake -DBUILD_SHARED_LIBS=OFF
+make
+cd 3rdparty/snappy
+cmake -DHAVE_LIBLZO2=0 -DHAVE_LIBLZ4=0 && make
+cd 3rdparty/zstd/build/cmake
+cmake ./ && make
+```
+6. Install Python requirements `pip3 install -t ../bin/osx/release -r py/requirements.txt`
+7. Install [Qt 5.15](http://www.qt.io/download-open-source/#section-2). Add Qt Creator and under Qt 5.15.x add Qt Charts module.
+8. Open `./src/rdm.pro` in **Qt Creator**.
+9. Run build. 
+
+### Build on Windows
+
+1. Install [Visual Studio 2019 Community Edition](https://visualstudio.microsoft.com/vs/).
+2. Install [Qt 5.15](https://www.qt.io/download).
+3. Go to `3rdparty/qredisclient/3rdparty/hiredis` and apply the patch to fix compilation on Windows:
+`git apply ../hiredis-win.patch`
+4. Go to the `3rdparty/` folder and install zlib with `nuget`: `nuget install zlib-msvc14-x64 -Version 1.2.11.7795`
+5. Build lz4 lib
+```
+cd 3rdparty/lz4/build/cmake
+cmake -DLZ4_BUNDLED_MODE=ON  .
+make
+```
+6. Install Python 3.9 amd64 to `C:\Python39-x64`.
+7. Install Python requirements `pip3 install -r src/py/requirements.txt`.
+8. Open `./src/rdm.pro` in **Qt Creator**.  Choose the `Desktop Qt 5.15.x MSVC2019 64bit > Release` build profile.
+9. Run build. (Just hit `Ctrl-B`)

+ 2 - 0
docs/known-issues.md

@@ -0,0 +1,2 @@
+### Application looks corrupted on my 1080p screen on Linux (too small font and/or broken dialogs)
+Run RESP.app from terminal without Qt Autoscaling: `Exec=env QT_AUTO_SCREEN_SCALE_FACTOR=0 redis-desktop-manager.rdm`

+ 45 - 0
docs/lg-keyspaces.md

@@ -0,0 +1,45 @@
+# Working with large keyspaces
+
+By default, RESP.app uses `*` (wildcard glob-style pattern) in  `SCAN` command to load all keys from the selected database. It’s simple and user-friendly for cases when you have only a couple of thousands keys. But for production redis-servers with millions of keys it leads to a huge amount of time needed to load keys in RESP.app.
+On this page you will find different approaches how to work with large Redis keyspaces efficiently. 
+
+## Increase limit for `SCAN` command
+RESP.app limits amount of keys that should be scanned by Redis to `10000`. If you have more than 100K keys in Redis it's recommended to increase this limit to
+`50000` or `100000`. 
+
+> !!! warning "Be careful!"
+    High scanning limit may affect your Redis performance!
+
+To increase this limit click on the Settings button in top right corner for the main window and change value for `Limit for SCAN command` setting.
+
+## Use specific `SCAN` filter to reduce loaded amount of keys
+
+Consider using more specific  filters for `SCAN` in order to speed up keys loading and reduce memory footprint 
+
+1. Right click on database and click on Filter button <br> <img width="250" src="https://user-images.githubusercontent.com/1655867/91542521-aa18c300-e926-11ea-8f09-4a0322d0f9ee.png">
+2. Enter glob-style pattern and press apply button <br> <img width="250" src="https://user-images.githubusercontent.com/1655867/91542549-b4d35800-e926-11ea-9920-ca0ad8701c56.png">
+
+> !!! note
+    More details about `SCAN` filter syntax you can find in Redis documentation [https://redis.io/commands/scan#the-match-option]()
+
+
+Default `SCAN` filter can be changed in connection settings on “Advanced Settings” tab:
+<br /><img width="500" src="https://user-images.githubusercontent.com/1655867/91543353-1eebfd00-e927-11ea-81ed-90bcc25c41f0.png">
+
+
+## Use namespaced keys
+
+Colon sign `:` is a commonly used convention when naming Redis keys. For example you can use following schema to store information about users:
+
+`user:1000`
+
+Following this schema allows you to simplify removal of obsolete keys and performing other operations with keys in Redis.
+
+Using namespaced keys is also important for loading huge keyspaces in RESP.app. It renders namespaces on demand (since 2020.2+) and this approach allows to visualise millions of keys with small memory footprint.
+
+<img width="250" src="https://user-images.githubusercontent.com/1655867/91547979-5c538900-e92d-11ea-8afa-10cc1634343f.png">
+
+Default namespace separator can be changed in connection settings on “Advanced Settings” tab.
+
+More tips about Redis keys naming you can find in this tutorial [https://redis.io/topics/data-types-intro#redis-keys]()
+

+ 9 - 0
docs/native-formatters.md

@@ -0,0 +1,9 @@
+## Native value formatters
+
+> !!! warning "End of life"
+    This feature was deprecated and removed from RESP.app. Please use [Extension Server](extension-server.md) instead  
+
+
+
+
+

+ 154 - 0
docs/quick-start.md

@@ -0,0 +1,154 @@
+# **How to start using RESP.app**
+***
+
+
+After you've [installed](install.md) RESP.app, the first thing you need to do in order to get going is to create a connection to your Redis server. On the main window, press the button labelled **Connect to Redis Server**. 
+
+![](http://resp.app/static/docs/rdm_main.png?v=2)
+
+## Connect to a local or public redis-server
+On the first tab (Connection Settings), put in general information regarding the connection that you are creating.
+
+* **Name** - the name of new connection (example: my_local_redis)
+* **Host** - redis-server host (example: localhost)
+* **Port** - redis-server port (example: 6379)
+* **Password** - redis-server authentication password (if any) ([http://redis.io/commands/AUTH](http://redis.io/commands/AUTH))
+* **Username** - only for redis-servers >= 6.0 with configured [ACL](https://redis.io/topics/acl), for older redis-server leave empty
+
+## Connect to a public redis-server with SSL
+If you want to connect to a redis-server instance with SSL you need to enable SSL on the second tab and provide a public key in PEM format. 
+Instructions for certain cloud services are below:
+
+<img src="http://resp.app/static/docs/rdm_ssl.png?v=2" />
+
+### AWS ElastiCache
+AWS ElastiCache is not accessible outside of your VPC. In order to connect to your ElastiCache remotely, you need to use one of the following options:
+
+*  Setup VPN connection **[Recommended]**
+[https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/accessing-elasticache.html#access-from-outside-aws](https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/accessing-elasticache.html#access-from-outside-aws)
+*  Setup SSH proxying host and connect through SSH tunnel. **[Slow network performance. Not recommended]**
+*  Setup NAT instance for exposing your AWS ElastiCache to the Internet **[Firewall rules should be configured very carefully. Not recommended.]**
+
+#### How to connect to AWS ElastiCache with In-Transit Encryption
+##### VPN / NAT
+Enable SSL/TLS checkbox and connect to your AWS ElastiCache with In-Transit Encryption.
+
+##### SSH tunnel
+Click on "Enable TLS-over-SSH" checkbox in the the SSH connection settings and connect to your AWS ElastiCache with In-Transit Encryption.
+
+### Microsoft Azure Redis Cache <br /> <img src="https://docs.microsoft.com/en-us/azure/azure-cache-for-redis/media/index/redis-cache.svg" width="100" />
+
+1. Create a connection with all requested information.
+ <br /> <img src="http://resp.app/static/docs/rdm_ssl_azure.png?v=2" />
+2. Make sure that the "Use SSL Protocol" checkbox is enabled.
+3. Your Azure Redis connection is ready to use.
+
+### Redis Labs <br /> <img src="https://upload.wikimedia.org/wikipedia/commons/7/75/Redis_Labs_Logo.png" height="75" />
+To connect to a Redis Labs instance with SSL/TLS encryption, follow the steps below:
+
+1. Make sure that SSL is enabled for your Redis instance in the Redis Labs dashboard.
+2. Download and unzip `garantia_credentials.zip` from the Redis Labs dashboard.
+3. Select `garantia_user.crt` in the "Public key" field.
+4. Select `garantia_user_private.key` in the "Private key" field.
+5. Select `garantia_ca.pem` in the "Authority" field.
+
+### Digital Ocean Managed Redis <br /> <img src="https://upload.wikimedia.org/wikipedia/commons/f/ff/DigitalOcean_logo.svg" width="100">
+Digital Ocean connection settings is a bit confusing. To connect to a Digital Ocean Managed Redis you need to follow steps bellow:
+
+1. Copy host, port and password information to RESP.app
+2. **Leave Username field in RESP.app empty** (Important!)
+3. Enable SSL/TLS checkbox
+
+Or using Quick Connect tab for new connections:
+1. Copy connection string (starts with "rediss://") from connection details to RESP.app
+2. Click "Import" and "Test Connection"
+
+### Heroku Redis <br /> <img src="https://brand.heroku.com/static/media/heroku-logo-stroke.aa0b53be.svg" width="80">
+
+1. Get Redis connection string from terminal with command 
+```
+heroku config -a YOUR-APP-NAME | grep REDIS
+```
+or get it from Heroku website.
+
+Example output:
+```
+rediss://user:password@host:port
+```
+2. Enter connection settings in RESP.app Connection dialog:
+- If URL starts with `rediss` enable SSL/TLS checkbox and **uncheck** "Enable strict mode" checkbox
+- Copy `user` to "Username" field
+- Copy `password` to "Password" field
+- Copy `host` and `port` to "Address" field in RESP.app
+
+## Connect to private redis-server via SSH tunnel
+### Basic SSH tunneling
+SSH tab is supposed to allow you to use a SSH tunnel. It's useful if your redis-server is not publicly accessible.
+To use a SSH tunnel select checkbox "SSH Tunnel". There are different security options; you can use a plain password or OpenSSH private key. 
+
+>!!! note "for Windows users:" 
+    Your private key must be in .pem format.
+
+<img height="350" src="http://resp.app/static/docs/resp_ssh.png?v=1" />
+
+### SSH Agent
+Starting from version 2022.3 RESP.app supports SSH Agents. This allows using password managers like [1Password](https://developer.1password.com/docs/ssh/agent)
+to securely store your SSH keys with 2FA.
+
+>!!! note "for Windows users:" 
+    On Windows RESP.app supports only [Microsoft OpenSSH](https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_overview) that's why "Custom SSH Agent Path" option is not available.  
+
+##### How to connect to 1Password SSH-Agent from DMG version of RESP.app
+It's possible to set default SSH Agent for all connections in RESP.app by overriding environment variable `SSH_AUTH_SOCK`.
+If you need to use custom ssh agent only for specific connections follow steps above:
+
+1. Create symlink to agent.sock
+```
+mkdir -p ~/.1password && ln -s ~/Library/Group\ Containers/2BUA8C4S2C.com.1password/t/agent.sock ~/.1password/agent.sock
+```
+2. In RESP.app check "Use SSH Agent" checkbox and click on the "Select File" button next to "Custom SSH Agent Path" field
+3. Press `⌘ + Shift + .` to show hidden files and folders in the dialog
+4. Select file `~/.1password/agent.sock`
+5. Save connection settings
+
+##### How to connect to SSH-Agent from AppStore version of RESP.app
+
+Due to AppStore sandboxing RESP.app cannot access default or custom SSH Agents defined by `SSH_AUTH_SOCK` variable.
+To overcome this limitation you need to create proxy unix socket inside RESP.app sandbox container:
+
+1. Install socat with homebrew
+```
+brew install socat
+```
+2. Create proxy unix-socket with socat:
+```
+socat UNIX-LISTEN:$HOME/Library/Containers/com.redisdesktop.rdm/Data/agent.sock UNIX-CONNECT:"$HOME/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock"
+```
+
+
+### Advanced SSH tunneling
+If you need advanced SSH tunneling you should setup a SSH tunnel manually and connect via localhost:
+```
+ssh SSH_HOST -L 7000:localhost:6379
+```
+
+## Connect to a UNIX socket
+
+RESP.app [doesn't support UNIX sockets](https://github.com/uglide/RedisDesktopManager/issues/1751) directly, but you can use redirecting of the local socket to the UNIX domain socket, for instance with [socat](https://sourceforge.net/projects/socat):
+
+```
+socat -v tcp-l:6379,reuseaddr,fork unix:/tmp/redis.sock
+```
+
+## Advanced connection settings
+The **Advanced settings** tab allows you to customise the namespace separator and other advanced settings.
+<img src="http://resp.app/static/docs/rdm_advanced_settings.png?v=3" />
+
+## Next steps
+Now you can test a connection or create a connection right away. 
+
+Congratulations, you've successfully connected to your Redis Server. You should see something similar to what we show below.
+![](http://resp.app/static/docs/rdm_main2.png?v=2)
+
+
+Click on the connection and expand keys. By clicking the right button, you can see console menu and manage your connection from there. 

+ 2 - 0
docs/requirements.txt

@@ -0,0 +1,2 @@
+mkdocs==1.3.0
+mkdocs-render-swagger-plugin==0.0.3

+ 129 - 0
docs/server_spec.yaml

@@ -0,0 +1,129 @@
+openapi: 3.0.0
+info:
+  version: 2022.0-preview1
+  title: RESP.app Extension server
+  description: RESP.app Extension Server API allows you to extend RESP.app with your custom data formatters
+paths:
+  /data-formatters:
+    get:
+      description: Returns a list of data formatters
+      responses:
+        '200':
+          description: Successful response
+          content:
+            application/json:    
+              schema:
+                $ref: "#/components/schemas/DataFormatters"
+  /data-formatters/{id}/decode:
+    post:
+      parameters:
+        - name: id
+          in: path
+          required: true
+          description: The id of data formatter
+          schema:
+            type: string
+      requestBody:
+        content: 
+          'application/json':
+            schema:
+              $ref: '#/components/schemas/DecodePayload'
+      responses:
+        '200':
+          description: Successful response with correct content type. RESP.app supports text/plain, application/json and application/octet-stream
+          content:
+            '*/*' :
+              schema:
+                type: string
+        '400':
+          description: Validation error response
+          content: 
+            'application/json':
+              schema:
+                type: object
+                properties:
+                  error:
+                    type: string
+          
+  /data-formatters/{id}/encode:
+    post:
+      parameters:
+        - name: id
+          in: path
+          required: true
+          description: The id of data formatter
+          schema:
+            type: string
+      requestBody:
+        content: 
+          'application/json':
+            schema:
+              $ref: '#/components/schemas/EncodePayload'
+      responses:
+        '200':
+          description: Successful response with content type application/octet-stream
+          content:
+            '*/*' :
+              schema:
+                type: string
+        '400':
+          description: Validation error response
+          content: 
+            'application/json':
+              schema:
+                type: object
+                properties:
+                  error:
+                    type: string        
+components:
+  securitySchemes:
+    basic:
+      type: http
+      scheme: basic
+  schemas:
+    DataFormatter:
+      type: object
+      required:
+        - id
+        - name
+      properties:
+        id:
+          type: string
+          description: Internal formatter ID used in requests to this API
+          example: "1"
+        name:
+          type: string
+          description: Name displayed inside RDM app
+          example: "My .net models decoder"
+        read-only:
+          type: boolean
+          description: Read-only formatters only receive decode requests
+          
+    DataFormatters:
+      type: array
+      items:
+        $ref: "#/components/schemas/DataFormatter"
+        
+    DecodePayload:
+      type: object
+      properties:
+        data: 
+          type: string
+          description: Base64 encoded string
+        redis-key-name:
+          type: string
+        redis-key-type:
+          type: string
+          
+    EncodePayload:
+      type: object
+      properties:
+        data:
+          type: string
+          description: Base64 encoded string
+        metadata:
+          type: object
+          description: Metadata from formatter custom ui forms
+
+security:
+  - basic: []

+ 25 - 0
mkdocs.yml

@@ -0,0 +1,25 @@
+site_name: "RESP.app"
+site_description: "RESP.app Documentation (formerly RedisDesktopManager)"
+site_author: "Igor Malinovskiy"
+site_favicon: "favicon.ico"
+repo_url: https://github.com/uglide/RedisDesktopManager
+edit_uri: edit/2022/docs/
+theme: readthedocs
+extra_css:
+- css/extra.css
+nav:
+- Home: 'index.md'
+- Install: 'install.md'
+- Quick Start: 'quick-start.md'
+- Bulk operations: 'bulk-operations.md'
+- Working with large keyspaces: 'lg-keyspaces.md'
+- Native Formatters: 'native-formatters.md'
+- Extension server: 'extension-server.md'
+- FAQ: 'faq.md'
+- Known Issues: 'known-issues.md'
+- AppStore Limitations: 'app-store.md'
+- Development Guide: 'development.md'
+markdown_extensions:
+  - markdown.extensions.admonition
+plugins:
+  - render_swagger

+ 8 - 0
sonar-project.properties

@@ -0,0 +1,8 @@
+sonar.projectName=RedisDesktopManager
+sonar.projectKey=uglide_RedisDesktopManager
+sonar.organization=uglide
+sonar.projectVersion=2021.10
+
+# SQ standard properties
+sonar.sources=src
+sonar.sourceEncoding=UTF-8

+ 430 - 0
src/app/app.cpp

@@ -0,0 +1,430 @@
+#include "app.h"
+
+#include <qpython.h>
+#include <pythonlib_loader.h>
+#include <qredisclient/redisclient.h>
+#include <QMessageBox>
+#include <QNetworkProxyFactory>
+#include <QQmlContext>
+#include <QQuickWindow>
+#include <QSettings>
+#include <QSysInfo>
+#include <QUrl>
+#include <QtQml>
+#include <QSslSocket>
+#include <QtConcurrent>
+
+#if defined(Q_OS_WINDOWS) || defined(Q_OS_LINUX)
+#include "darkmode.h"
+#include <QStyleFactory>
+#endif
+
+#include "common/tabviewmodel.h"
+#include "events.h"
+#include "models/configmanager.h"
+#include "models/connectionconf.h"
+#include "models/connectionsmanager.h"
+#include "models/key-models/keyfactory.h"
+#include "modules/bulk-operations/bulkoperationsmanager.h"
+#include "modules/common/sortfilterproxymodel.h"
+#include "modules/console/autocompletemodel.h"
+#include "modules/console/consolemodel.h"
+#include "modules/server-actions/serverstatsmodel.h"
+#include "modules/value-editor/embeddedformattersmanager.h"
+#ifdef ENABLE_EXTERNAL_FORMATTERS
+#include "modules/extension-server/dataformattermanager.h"
+#endif
+#include "modules/value-editor/syntaxhighlighter.h"
+#include "modules/value-editor/textcharformat.h"
+#include "modules/value-editor/tabsmodel.h"
+#include "modules/value-editor/valueviewmodel.h"
+#include "qmlutils.h"
+
+#ifdef Q_OS_WINDOWS
+#include <dwmapi.h>
+#endif
+
+Application::Application(int& argc, char** argv)
+    : QApplication(argc, argv),
+      m_engine(this),
+      m_qmlUtils(QSharedPointer<QmlUtils>(new QmlUtils())),
+      m_events(QSharedPointer<Events>(new Events()))
+{
+  // Init components required for models and qml
+  initAppInfo();
+  initProxySettings();
+  processCmdArgs();
+  initAppFonts();
+
+#if defined(Q_OS_WINDOWS) || defined(Q_OS_LINUX)
+  if (isDarkThemeEnabled()) {
+    setStyle(QStyleFactory::create("Fusion"));
+    setPalette(createDarkModePalette());
+  }
+#endif
+
+  initRedisClient();
+  installTranslator();  
+}
+
+void Application::initModels() {
+  ConfigManager confManager(m_settingsDir);
+
+  QString config = confManager.getApplicationConfigPath("connections.json");
+
+  if (config.isNull()) {
+    QMessageBox::critical(
+        nullptr,
+        QCoreApplication::translate("RESP",
+                                    "Settings directory is not writable"),
+        QCoreApplication::translate(
+            "RESP",
+            "RESP.app can't save connections file to settings directory. "
+            "Please change file permissions or restart RESP.app as "
+            "administrator."));
+
+    throw std::runtime_error("invalid connections config");
+  }
+
+  m_keyFactory = QSharedPointer<KeyFactory>(new KeyFactory());
+
+  m_keyValues =
+      QSharedPointer<ValueEditor::TabsModel>(new ValueEditor::TabsModel(
+          m_keyFactory.staticCast<ValueEditor::AbstractKeyFactory>(), m_events));
+
+  connect(m_events.data(), &Events::openValueTab, m_keyValues.data(),
+          &ValueEditor::TabsModel::openTab);
+  connect(m_events.data(), &Events::newKeyDialog, m_keyFactory.data(),
+          &KeyFactory::createNewKeyRequest);
+  connect(m_events.data(), &Events::closeDbKeys, m_keyValues.data(),
+          &ValueEditor::TabsModel::closeDbKeys);
+
+  m_connections = QSharedPointer<ConnectionsManager>(
+      new ConnectionsManager(config, m_events));
+
+  m_bulkOperations = QSharedPointer<BulkOperations::Manager>(
+      new BulkOperations::Manager(m_connections));
+
+  connect(m_events.data(), &Events::requestBulkOperation,
+          m_bulkOperations.data(),
+          &BulkOperations::Manager::requestBulkOperation);
+
+  m_consoleModel = QSharedPointer<TabViewModel>(
+      new TabViewModel(getTabModelFactory<Console::Model>()));
+
+  connect(m_events.data(), &Events::openConsole, m_consoleModel.data(),
+          &TabViewModel::openTab);
+
+  auto srvStatsFactory = [this](QSharedPointer<RedisClient::Connection> c,
+                                int dbIndex, QList<QByteArray> initCmd) {
+    auto model = QSharedPointer<TabModel>(
+        new ServerStats::Model(c, dbIndex, initCmd), &QObject::deleteLater);
+
+    QObject::connect(model.staticCast<ServerStats::Model>().data(),
+                     &ServerStats::Model::openConsoleTerminal, m_events.data(),
+                     &Events::openConsole);
+
+    return model;
+  };
+
+  m_serverStatsModel = QSharedPointer<TabViewModel>(
+      new TabViewModel(srvStatsFactory));
+
+  connect(m_events.data(), &Events::openServerStats, this,
+          [this](QSharedPointer<RedisClient::Connection> c) {
+            m_serverStatsModel->openTab(c, 0, false);
+          });
+
+#ifdef ENABLE_EXTERNAL_FORMATTERS
+  m_extServerManager =
+      QSharedPointer<RespExtServer::DataFormattersManager>(new RespExtServer::DataFormattersManager(m_engine));
+
+  connect(m_extServerManager.data(), &RespExtServer::DataFormattersManager::error, this,
+          [this](const QString& msg) {
+            qDebug() << "External formatters:" << msg;
+            m_events->log(QString("External: %1").arg(msg));
+          });
+
+  connect(m_extServerManager.data(), &RespExtServer::DataFormattersManager::loaded, this,
+          [this]() {
+            qDebug() << "External formatters loaded";
+            emit m_events->externalFormattersLoaded();
+          });
+
+  if (!m_extServerUrl.isEmpty()) {
+    m_extServerManager->setUrl(m_extServerUrl);
+  }
+
+  connect(m_events.data(), &Events::appRendered, this, [this]() {
+      if (m_extServerManager) m_extServerManager->loadFormatters();
+  });
+#endif
+
+  m_embeddedFormatters = QSharedPointer<ValueEditor::EmbeddedFormattersManager>(
+      new ValueEditor::EmbeddedFormattersManager());
+
+  connect(m_embeddedFormatters.data(),
+          &ValueEditor::EmbeddedFormattersManager::error, this,
+          [this](const QString& msg) {
+            m_events->log(QString("Formatters: %1").arg(msg));
+          });
+
+  m_consoleAutocompleteModel = QSharedPointer<Console::AutocompleteModel>(
+      new Console::AutocompleteModel());
+
+  connect(m_events.data(), &Events::appRendered, this, [this]() {
+    if (m_connections) m_connections->loadConnections();
+
+    initPython();
+
+    if (m_embeddedFormatters) m_embeddedFormatters->init(m_python);
+    if (m_bulkOperations) m_bulkOperations->setPython(m_python);
+
+    if (m_events) emit m_events->pythonLoaded();
+  });
+}
+
+void Application::initAppInfo() {
+  setApplicationName("RESP.app - Developer GUI for Redis");
+  setApplicationVersion(QString(APP_VERSION));
+  setOrganizationDomain("redisdesktop.com");
+  setOrganizationName("redisdesktop");
+
+#ifdef Q_OS_MAC
+  setWindowIcon(QIcon(":/images/logo.icns"));
+#else
+  setWindowIcon(QIcon(":/images/logo.png"));
+#endif
+
+  qDebug() << "TLS support:" << QSslSocket::sslLibraryVersionString();
+}
+
+void Application::initAppFonts() {
+  QSettings settings;
+
+  const int minFontSize = 4;
+#ifdef Q_OS_MAC
+  QString defaultFontName("Helvetica Neue");
+  QString defaultMonospacedFont("Monaco");
+  int defaultFontSize = 12;
+#elif defined(Q_OS_WINDOWS)
+  QString defaultFontName("Segoe UI");
+  QString defaultMonospacedFont("Consolas");
+  int defaultFontSize = 11;
+#else
+  QString defaultFontName("Open Sans");
+  QString defaultMonospacedFont("Ubuntu Mono");
+  int defaultFontSize = 11;  
+#endif
+
+  int defaultValueSizeLimit = 150000;
+
+  QString appFont = settings.value("app/appFont", defaultFontName).toString();
+
+  if (appFont.isEmpty())
+    appFont = defaultFontName;
+
+  int appFontSize = settings.value("app/appFontSize", defaultFontSize).toInt();
+
+  if (appFontSize < minFontSize)
+    appFontSize = defaultFontSize;
+
+  if (appFont == "Open Sans") {
+#if defined(Q_OS_LINUX)
+    int result = QFontDatabase::addApplicationFont("://fonts/OpenSans.ttc");
+
+    if (result == -1) {
+      appFont = "Ubuntu";
+    }
+#elif defined (Q_OS_WINDOWS)
+    appFont = defaultFontName;
+#endif
+  }
+
+  QString valuesFont = settings.value("app/valueEditorFont", defaultMonospacedFont).toString();
+
+  if (valuesFont.isEmpty())
+    valuesFont = defaultMonospacedFont;
+
+  int valuesFontSize = settings.value("app/valueEditorFontSize", defaultFontSize).toInt();
+
+  if (valuesFontSize < minFontSize)
+    valuesFontSize = defaultFontSize;
+
+  int valueSizeLimit = settings.value("app/valueSizeLimit", defaultValueSizeLimit).toInt();
+
+  if (valueSizeLimit < 1000)
+    valueSizeLimit = defaultValueSizeLimit;
+
+  settings.setValue("app/appFont", appFont);
+  settings.setValue("app/appFontSize", appFontSize);
+  settings.setValue("app/valueEditorFont", valuesFont);
+  settings.setValue("app/valueEditorFontSize", valuesFontSize);
+  settings.setValue("app/valueSizeLimit", valueSizeLimit);
+
+  qDebug() << "App font:" << appFont << appFontSize;
+  qDebug() << "Values font:" << valuesFont;
+  QFont defaultFont(appFont, appFontSize);
+  QApplication::setFont(defaultFont);
+}
+
+void Application::initProxySettings() {
+  QSettings settings;
+  QNetworkProxyFactory::setUseSystemConfiguration(
+      settings.value("app/useSystemProxy", false).toBool());
+}
+
+void Application::registerQmlTypes() {
+  qmlRegisterType<SortFilterProxyModel>("rdm.models", 1, 0,
+                                        "SortFilterProxyModel");
+  qmlRegisterType<SyntaxHighlighter>("rdm.models", 1, 0, "SyntaxHighlighter");
+  qmlRegisterType<TextCharFormat>("rdm.models", 1, 0, "TextCharFormat");
+  qRegisterMetaType<ServerConfig>();
+}
+
+void Application::registerQmlRootObjects() {
+  m_engine.rootContext()->setContextProperty("appEvents", m_events.data());
+  m_engine.rootContext()->setContextProperty("qmlUtils", m_qmlUtils.data());
+  m_engine.rootContext()->setContextProperty("connectionsManager",
+                                             m_connections.data());
+  m_engine.rootContext()->setContextProperty("keyFactory", m_keyFactory.data());
+  m_engine.rootContext()->setContextProperty("valuesModel", m_keyValues.data());
+#ifdef ENABLE_EXTERNAL_FORMATTERS
+  m_engine.rootContext()->setContextProperty("formattersManager",
+                                             m_extServerManager.data());
+#endif
+  m_engine.rootContext()->setContextProperty("embeddedFormattersManager",
+                                             m_embeddedFormatters.data());
+  m_engine.rootContext()->setContextProperty("consoleModel",
+                                             m_consoleModel.data());
+  m_engine.rootContext()->setContextProperty("serverStatsModel",
+                                             m_serverStatsModel.data());
+  m_engine.rootContext()->setContextProperty("bulkOperations",
+                                             m_bulkOperations.data());
+  m_engine.rootContext()->setContextProperty("consoleAutocompleteModel",
+                                             m_consoleAutocompleteModel.data());
+}
+
+void Application::initQml() {
+  if (m_renderingBackend == "auto") {
+    QQuickWindow::setSceneGraphBackend(QSGRendererInterface::Software);
+  } else {
+    QQuickWindow::setSceneGraphBackend(m_renderingBackend);
+  }
+
+  registerQmlTypes();
+  registerQmlRootObjects();
+
+  try {
+    m_engine.load(QUrl(QStringLiteral("qrc:///app.qml")));
+  } catch (...) {
+    qDebug() << "Failed to load app window. Retrying with software renderer...";
+    QQuickWindow::setSceneGraphBackend(QSGRendererInterface::Software);
+    m_engine.load(QUrl(QStringLiteral("qrc:///app.qml")));
+  }
+
+  updatePalette();
+  connect(this, &QGuiApplication::paletteChanged, this, &Application::updatePalette);
+
+  qDebug() << "Rendering backend:" << QQuickWindow::sceneGraphBackend();
+
+  emit m_events->appRendered();
+}
+
+void Application::initPython() {
+  m_python = QSharedPointer<QPython>(new QPython(this, 1, 5));
+  m_python->addImportPath("qrc:/python/");
+
+#ifdef Q_OS_MACOS
+  m_python->addImportPath(applicationDirPath() + "/../Resources/py");
+#else
+  m_python->addImportPath(applicationDirPath());
+#endif
+}
+
+void Application::installTranslator() {
+  QSettings settings;
+  QString preferredLocale = settings.value("app/locale", "system").toString();
+
+  QString locale;
+
+  if (preferredLocale == "system") {
+    settings.setValue("app/locale", "system");
+    locale = QLocale::system().uiLanguages().first().replace("-", "_");
+
+    qDebug() << QLocale::system().uiLanguages();
+
+    if (locale.isEmpty() || locale == "C") locale = "en_US";
+
+    qDebug() << "Detected locale:" << locale;
+  } else {
+    locale = preferredLocale;
+  }
+
+  m_translator = QSharedPointer<QTranslator>(new QTranslator((QObject*)this));
+  if (m_translator->load(QString(":/translations/rdm_") + locale)) {
+    qDebug() << "Load translations file for locale:" << locale;
+    QCoreApplication::installTranslator(m_translator.data());
+  } else {
+    m_translator.clear();
+  }
+}
+
+void Application::processCmdArgs() {
+  QCommandLineParser parser;
+  QCommandLineOption settingsDir("settings-dir",
+                                 "(Optional) Directory where RESP.app looks/saves "
+                                 ".rdm directory with connections.json file",
+                                 "settingsDir", QDir::homePath());
+  QCommandLineOption extensionServerUrl(
+      "extension-server-url",
+      "(Optional) Overrides extension server url",
+      "extensionServerUrl",
+      QString());
+
+  QCommandLineOption renderingBackend(
+      "rendering-backend",
+      "(Optional) QML rendering backend [software|opengl|d3d12|'']",
+      "renderingBackend", "auto");
+  parser.addHelpOption();
+  parser.addVersionOption();
+  parser.addOption(settingsDir);
+  parser.addOption(extensionServerUrl);
+  parser.addOption(renderingBackend);
+  parser.process(*this);
+
+  m_settingsDir = parser.value(settingsDir);
+  m_extServerUrl = parser.value(extensionServerUrl);
+  m_renderingBackend = parser.value(renderingBackend);
+}
+
+void Application::updatePalette()
+{
+    if (m_engine.rootObjects().size() == 0) {
+        qWarning() << "Cannot update palette. Root object is not loaded.";
+        return;
+    }
+
+    auto rootObject = m_engine.rootObjects().at(0);
+
+    rootObject->setProperty("palette", QGuiApplication::palette());
+
+#ifdef Q_OS_WINDOWS
+    if (!isDarkThemeEnabled()) return;
+
+    auto window = qobject_cast<QWindow*>(rootObject);
+
+    if (window) {
+      auto winHwnd = reinterpret_cast<HWND>(window->winId());
+      BOOL USE_DARK_MODE = true;
+      BOOL SET_IMMERSIVE_DARK_MODE_SUCCESS = SUCCEEDED(DwmSetWindowAttribute(
+          winHwnd, 20, &USE_DARK_MODE, sizeof(USE_DARK_MODE)));
+
+      if (SET_IMMERSIVE_DARK_MODE_SUCCESS) {
+        // Dirty hack to re-draw window and apply darkmode color
+        rootObject->setProperty("visible", false);
+        rootObject->setProperty("visible", true);
+      }
+    }
+#endif
+}

+ 80 - 0
src/app/app.h

@@ -0,0 +1,80 @@
+#pragma once
+#include <QApplication>
+#include <QFontDatabase>
+#include <QMenu>
+#include <QQmlApplicationEngine>
+#include <QSharedPointer>
+
+#ifndef APP_VERSION
+#include "../version.h"
+#endif
+
+class QmlUtils;
+class Events;
+class ConnectionsManager;
+class Updater;
+class KeyFactory;
+class TabViewModel;
+class QPython;
+namespace ValueEditor {
+class TabsModel;
+}
+#ifdef ENABLE_EXTERNAL_FORMATTERS
+namespace RespExtServer {
+class DataFormattersManager;
+}
+#endif
+namespace ValueEditor {
+class EmbeddedFormattersManager;
+}  // namespace ValueEditor
+namespace BulkOperations {
+class Manager;
+}
+namespace Console {
+class AutocompleteModel;
+}
+
+class Application : public QApplication {
+  Q_OBJECT
+
+ public:
+  Application(int &argc, char **argv);
+
+  void initModels();
+  void initQml();
+
+ private:
+  void initAppInfo();
+  void initAppFonts();
+  void initProxySettings();
+  void initPython();
+
+  void registerQmlTypes();
+  void registerQmlRootObjects();
+  void installTranslator();
+  void processCmdArgs();
+
+ private slots:
+  void updatePalette();
+
+ private:
+  QQmlApplicationEngine m_engine;
+  QSharedPointer<QmlUtils> m_qmlUtils;
+  QSharedPointer<Events> m_events;
+  QSharedPointer<ConnectionsManager> m_connections;
+  QSharedPointer<KeyFactory> m_keyFactory;
+  QSharedPointer<ValueEditor::TabsModel> m_keyValues;
+#ifdef ENABLE_EXTERNAL_FORMATTERS
+  QSharedPointer<RespExtServer::DataFormattersManager> m_extServerManager;
+#endif
+  QSharedPointer<ValueEditor::EmbeddedFormattersManager> m_embeddedFormatters;
+  QSharedPointer<BulkOperations::Manager> m_bulkOperations;
+  QSharedPointer<TabViewModel> m_consoleModel;
+  QSharedPointer<TabViewModel> m_serverStatsModel;
+  QSharedPointer<Console::AutocompleteModel> m_consoleAutocompleteModel;
+  QSharedPointer<QPython> m_python;
+  QString m_settingsDir;
+  QString m_extServerUrl;
+  QString m_renderingBackend;
+  QSharedPointer<QTranslator> m_translator = nullptr;
+};

+ 7 - 0
src/app/apputils.h

@@ -0,0 +1,7 @@
+#pragma once
+#include <QString>
+#include <QLocale>
+
+inline QString humanReadableSize(qint64 size) {
+  return QLocale().formattedDataSize(size, 2, QLocale::DataSizeSIFormat);
+}

+ 65 - 0
src/app/darkmode.h

@@ -0,0 +1,65 @@
+#pragma once
+#include <QPalette>
+#include <QSettings>
+
+bool isDarkThemeEnabled() {
+#if defined(Q_OS_WINDOWS)
+  QSettings settings;
+  QSettings systemSettings(
+      "HKEY_CURRENT_"
+      "USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
+      QSettings::NativeFormat);
+
+  QString darkMode = settings.value("app/darkMode", "Auto").toString();
+  if (darkMode == "Auto") {
+      return systemSettings.value("AppsUseLightTheme") == 0;
+  } else if (darkMode == "On") {
+      return true;
+  } else {
+      return false;
+  }
+#elif defined(Q_OS_LINUX)
+  QSettings settings;
+
+  return settings.value("app/darkModeOn", false).toBool();
+#else
+  return false;
+#endif
+}
+
+QPalette createDarkModePalette() {
+
+  QColor base = QColor(30, 30, 30);
+  QColor alt = QColor(50, 50, 50);
+  QColor text = QColor(223, 223, 223);
+  QColor buttonText = QColor(170, 170, 170);
+  QColor disabledColor = QColor(127, 127, 127);
+
+  QPalette p(alt, base);
+
+  p.setColor(QPalette::Light, QColor(76,76,76));
+  p.setColor(QPalette::Dark, QColor(235,235,235));
+  p.setColor(QPalette::Midlight, QColor(76,76,76));
+  p.setColor(QPalette::Mid, QColor(66,66,66));
+  p.setColor(QPalette::Window, base);
+  p.setColor(QPalette::WindowText, text);
+  p.setColor(QPalette::Base, base);
+  p.setColor(QPalette::AlternateBase, alt);
+  p.setColor(QPalette::ToolTipBase, alt);
+  p.setColor(QPalette::ToolTipText, Qt::white);
+  p.setColor(QPalette::Text, text);
+  p.setColor(QPalette::Disabled, QPalette::Text, disabledColor);
+  p.setColor(QPalette::Button, alt);
+  p.setColor(QPalette::ButtonText, buttonText);
+  p.setColor(QPalette::Disabled, QPalette::ButtonText, disabledColor);
+  p.setColor(QPalette::BrightText, text.lighter(80));
+  p.setColor(QPalette::Link, QColor(42, 130, 218));
+  p.setColor(QPalette::Highlight, QColor(42, 130, 218));
+  p.setColor(QPalette::HighlightedText, Qt::black);
+  p.setColor(QPalette::Disabled, QPalette::HighlightedText, disabledColor);
+
+  p.setBrush(QPalette::Active, QPalette::Highlight,  QColor(42, 130, 218));
+  p.setBrush(QPalette::Inactive, QPalette::Highlight, QColor(42, 130, 218));
+
+  return p;
+}

+ 16 - 0
src/app/events.cpp

@@ -0,0 +1,16 @@
+#include "events.h"
+
+void Events::registerLoggerForConnection(RedisClient::Connection& c) {
+  auto self = sharedFromThis().toWeakRef();
+  QObject::connect(
+      &c, &RedisClient::Connection::log, this, [self](const QString& info) {
+        if (!self) return;
+        emit self.toStrongRef()->log(QString("Connection: %1").arg(info));
+      }, Qt::QueuedConnection);
+
+  QObject::connect(
+      &c, &RedisClient::Connection::error, this, [self](const QString& error) {
+        if (!self) return;
+        emit self.toStrongRef()->log(QString("Connection: %1").arg(error));
+      }, Qt::QueuedConnection);
+}

+ 63 - 0
src/app/events.h

@@ -0,0 +1,63 @@
+#pragma once
+#include <qredisclient/connection.h>
+#include <QEnableSharedFromThis>
+#include <QObject>
+#include <QRegExp>
+#include <QSharedPointer>
+#include <QString>
+#include <functional>
+#include "modules/bulk-operations/bulkoperationsmanager.h"
+#include "common/callbackwithowner.h"
+
+namespace ConnectionsTree {
+class KeyItem;
+class TreeItem;
+}
+
+class Events : public QObject, public QEnableSharedFromThis<Events> {
+  Q_OBJECT
+
+ public:
+  void registerLoggerForConnection(RedisClient::Connection& c);
+
+ signals:
+
+  // Tabs
+  void openValueTab(QSharedPointer<RedisClient::Connection> connection,
+                    QSharedPointer<ConnectionsTree::KeyItem> key,
+                    bool inNewTab);
+
+  void openConsole(QSharedPointer<RedisClient::Connection> connection,
+                   int dbIndex, bool inNewTab,
+                   QList<QByteArray> initCmd = QList<QByteArray>());
+
+  void openServerStats(QSharedPointer<RedisClient::Connection> connection);
+
+  void closeDbKeys(QSharedPointer<RedisClient::Connection> connection,
+                   int dbIndex,
+                   const QRegExp& filter = QRegExp("*", Qt::CaseSensitive,
+                                                   QRegExp::Wildcard));
+
+  // Dialogs
+  void requestBulkOperation(
+      QSharedPointer<RedisClient::Connection> connection, int dbIndex,
+      BulkOperations::Manager::Operation op, QRegExp keyPattern,
+      BulkOperations::AbstractOperation::OperationCallback callback);
+
+  void newKeyDialog(
+      QSharedPointer<RedisClient::Connection> connection,
+      QSharedPointer<CallbackWithOwner<ConnectionsTree::TreeItem>> callback,
+      int dbIndex, QString keyPrefix);
+
+  // Notifications
+  void error(const QString& msg);
+
+  void log(const QString& msg);
+
+  void appRendered();
+
+  void pythonLoaded();
+
+  void externalFormattersLoaded();
+
+};

+ 278 - 0
src/app/jsonutils.cpp

@@ -0,0 +1,278 @@
+#include "jsonutils.h"
+
+#include <QDebug>
+#include <simdjson.h>
+
+// Based on https://github.com/nlohmann/json/blob/ec7a1d834773f9fee90d8ae908a0c9933c5646fc/src/json.hpp#L4604-L4697
+// Copyright &copy; 2013-2015 Niels Lohmann.
+// The code is licensed under the MIT License
+std::size_t extra_space(const std::string_view& s) noexcept
+{
+    std::size_t result = 0;
+
+    for (const auto& c : s)
+    {
+        switch (c)
+        {
+            case '"':
+            case '\\':
+            case '\b':
+            case '\f':
+            case '\n':
+            case '\r':
+            case '\t':
+            {
+                // from c (1 byte) to \x (2 bytes)
+                result += 1;
+                break;
+            }
+
+            default:
+            {
+                if (c >= 0x00 and c <= 0x1f)
+                {
+                    // from c (1 byte) to \uxxxx (6 bytes)
+                    result += 5;
+                }
+                break;
+            }
+        }
+    }
+
+    return result;
+}
+
+std::string escape_string(const std::string_view& s) noexcept
+{
+    const auto space = extra_space(s);
+    if (space == 0)
+    {
+        return std::string(s);
+    }
+
+    // create a result string of necessary size
+    std::string result(s.size() + space, '\\');
+    std::size_t pos = 0;
+
+    for (const auto& c : s)
+    {
+        switch (c)
+        {
+            // quotation mark (0x22)
+            case '"':
+            {
+                result[pos + 1] = '"';
+                pos += 2;
+                break;
+            }
+
+            // reverse solidus (0x5c)
+            case '\\':
+            {
+                // nothing to change
+                pos += 2;
+                break;
+            }
+
+            // backspace (0x08)
+            case '\b':
+            {
+                result[pos + 1] = 'b';
+                pos += 2;
+                break;
+            }
+
+            // formfeed (0x0c)
+            case '\f':
+            {
+                result[pos + 1] = 'f';
+                pos += 2;
+                break;
+            }
+
+            // newline (0x0a)
+            case '\n':
+            {
+                result[pos + 1] = 'n';
+                pos += 2;
+                break;
+            }
+
+            // carriage return (0x0d)
+            case '\r':
+            {
+                result[pos + 1] = 'r';
+                pos += 2;
+                break;
+            }
+
+            // horizontal tab (0x09)
+            case '\t':
+            {
+                result[pos + 1] = 't';
+                pos += 2;
+                break;
+            }
+
+            default:
+            {
+                if (c >= 0x00 and c <= 0x1f)
+                {
+                    // print character c as \uxxxx
+                    std::snprintf(&result[pos + 1], 7, "u%04x", int(c));
+                    pos += 6;
+                    // overwrite trailing null character
+                    result[pos] = '\\';
+                }
+                else
+                {
+                    // all other characters are added as-is
+                    result[pos++] = c;
+                }
+                break;
+            }
+        }
+    }
+
+    return result;
+}
+
+QByteArray escapeJsonKey(std::string_view key) {
+    return QByteArray::fromStdString(escape_string(key));
+}
+
+void print_json(QByteArray &result,
+                simdjson::ondemand::value element,
+                long level, bool objectValue = false) {
+  using namespace simdjson::ondemand;
+
+  QByteArray whitespace = QByteArray().fill(' ', level * 2);
+  bool add_comma;
+
+  if (!objectValue) result.append(whitespace);
+
+  switch (element.type()) {
+    case json_type::array:
+      result.append("[\n");
+      add_comma = false;
+      for (auto child : element.get_array()) {
+        if (add_comma) {
+          result.append(",\n");
+        }
+        print_json(result, child.value(), level + 1);
+        add_comma = true;
+      }
+
+      result.append('\n');
+      result.append(whitespace);
+      result.append("]");
+      break;
+    case json_type::object:
+      result.append("{\n");
+      add_comma = false;
+      for (auto field : element.get_object()) {
+        if (add_comma) {
+          result.append(",\n");
+        }
+
+        result.append(whitespace);
+        result.append("  ");
+        result.append(QString("\"%1\": ")
+                          .arg(QString::fromUtf8(escapeJsonKey(field.unescaped_key())))
+                          .toUtf8());
+        print_json(result, field.value(), level + 1, true);
+        add_comma = true;
+      }
+      result.append('\n');
+      result.append(whitespace);
+      result.append("}");
+      break;
+    case json_type::number:
+      result.append(QByteArray::fromStdString(
+                        std::string(std::string_view(element.raw_json_token())))
+                        .trimmed());
+      break;
+    case json_type::string:
+      result.append(QByteArray::fromStdString(
+                        std::string(std::string_view(element.raw_json_token())))
+                        .trimmed());
+      break;
+    case json_type::boolean:
+      result.append(bool(element) ? "true" : "false");
+      break;
+    case json_type::null:
+      result.append("null");
+      break;
+  }
+}
+
+QByteArray JSONUtils::prettyPrintJSON(QByteArray val)
+{
+    QByteArray result;
+    result.reserve(val.size() * 32);
+
+    val.resize(val.size() + simdjson::SIMDJSON_PADDING);
+
+    simdjson::ondemand::parser p;
+
+    try {
+      auto doc = p.iterate(val.data(), val.size());
+
+      if (doc.is_scalar()) {
+          return val;
+      }
+
+      print_json(result, simdjson::ondemand::value(doc), 0);
+    } catch (const std::exception& e) {
+      qDebug() << "Cannot parse JSON:" << e.what();
+      return QByteArray();
+    }
+
+    return result;
+}
+
+QByteArray JSONUtils::minifyJSON(const QByteArray &val)
+{
+    QByteArray minified;
+    minified.resize(val.size());
+
+    size_t new_length{};
+    auto error = simdjson::minify(val.data(), val.size(), minified.data(), new_length);
+
+    if (error != 0) {
+        qDebug() << "Failed to minify JSON with simdjson:" << error;
+        return QByteArray();
+    }
+
+    minified.resize(new_length);
+
+    return minified;
+}
+
+bool JSONUtils::isJSON(QByteArray val)
+{
+    int originalSize = val.size();
+    val.resize(val.size() + simdjson::SIMDJSON_PADDING);
+
+    simdjson::dom::parser parser;
+    simdjson::dom::element data;
+    auto error = parser.parse(val.data(), originalSize, false).get(data);
+
+    // NOTE(u_glide): Workaround to distinguish invalid JSON and valid JSON with Big Int
+    if (error == simdjson::NUMBER_ERROR) {
+        simdjson::ondemand::parser p;
+
+        try {
+          auto doc = p.iterate(val.data(), val.size());
+          return !doc.is_scalar();
+        } catch (const std::exception& e) {
+          qDebug() << "JSON is not valid:" << e.what();
+          return false;
+        }
+    } else if (error != simdjson::SUCCESS) {
+        qDebug() << "JSON is not valid:" << simdjson::error_message(error);
+        return false;
+    }
+
+    return true;
+}

+ 12 - 0
src/app/jsonutils.h

@@ -0,0 +1,12 @@
+#pragma once
+#include <QByteArray>
+
+namespace JSONUtils {
+
+QByteArray prettyPrintJSON(QByteArray val);
+
+bool isJSON(QByteArray val);
+
+QByteArray minifyJSON(const QByteArray& val);
+
+};  // namespace JSONUtils

+ 91 - 0
src/app/models/configmanager.cpp

@@ -0,0 +1,91 @@
+#include "configmanager.h"
+#include <qredisclient/utils/compat.h>
+#include <QDebug>
+#include <QDir>
+#include <QFile>
+#include <QFileInfo>
+#include <QJsonArray>
+#include <QJsonDocument>
+#include <QJsonObject>
+#include <QVariantHash>
+#include <QXmlStreamReader>
+#include "app/models/connectionconf.h"
+
+ConfigManager::ConfigManager(const QString &basePath) : m_basePath(basePath) {}
+
+QString ConfigManager::getApplicationConfigPath(const QString &configFile,
+                                                bool checkPath) {
+  QString configDir = getConfigPath(m_basePath);
+  QDir settingsPath(configDir);
+
+  if (!settingsPath.exists() && settingsPath.mkpath(configDir)) {
+    qDebug() << "Config Dir created";
+  }
+
+  QString configPath = QString("%1/%2").arg(configDir).arg(configFile);
+
+  if (checkPath && !chechPath(configPath)) return QString();
+
+  return configPath;
+}
+
+bool ConfigManager::chechPath(const QString &configPath) {
+  QFile testConfig(configPath);
+  QFileInfo checkPermissions(configPath);
+
+  if (!testConfig.exists() && testConfig.open(QIODevice::ReadWrite))
+    testConfig.close();
+
+  if (checkPermissions.isWritable()) {
+    setPermissions(testConfig);
+    return true;
+  }
+
+  return false;
+}
+
+void ConfigManager::setPermissions(QFile &file) {
+#ifdef Q_OS_WIN
+  extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;
+  qt_ntfs_permission_lookup++;
+#endif
+
+  if (!file.setPermissions(QFile::ReadUser | QFile::WriteUser))
+    qWarning() << "Cannot set permissions for config folder";
+
+#ifdef Q_OS_WIN
+  qt_ntfs_permission_lookup--;
+#endif
+}
+
+QString ConfigManager::getConfigPath(QString basePath) {
+  QString configDir;
+#ifdef Q_OS_MACX
+  if (basePath == QDir::homePath()) {
+    configDir = "/Library/Preferences/rdm/";
+  } else {
+    configDir = ".rdm";
+  }
+
+  configDir =
+      QDir::toNativeSeparators(QString("%1/%2").arg(basePath).arg(configDir));
+#else
+  configDir =
+      QDir::toNativeSeparators(QString("%1/%2").arg(basePath).arg(".rdm"));
+#endif
+  return configDir;
+}
+
+bool saveJsonArrayToFile(const QJsonArray &c, const QString &f) {
+  QJsonDocument config(c);
+  QFile confFile(f);
+
+  if (confFile.open(QIODevice::WriteOnly)) {
+    QTextStream outStream(&confFile);
+    outStream.setCodec("UTF-8");
+    outStream << config.toJson();
+    confFile.close();
+    return true;
+  }
+  return false;
+}

+ 22 - 0
src/app/models/configmanager.h

@@ -0,0 +1,22 @@
+#pragma once
+#include <QString>
+#include <QFile>
+#include <QDir>
+#include <QJsonArray>
+
+class ConfigManager
+{
+public:
+    explicit ConfigManager(const QString& basePath = QDir::homePath());
+    QString getApplicationConfigPath(const QString &, bool checkPath=true);    
+public:
+    static QString getConfigPath(QString basePath = QDir::homePath());    
+
+private:
+    static bool chechPath(const QString&);
+    static void setPermissions(QFile&);    
+private:
+    QString m_basePath;
+};
+
+bool saveJsonArrayToFile(const QJsonArray& c, const QString& f);

+ 99 - 0
src/app/models/connectionconf.cpp

@@ -0,0 +1,99 @@
+#include "connectionconf.h"
+
+ServerConfig::ServerConfig(const QString &host, const QString &auth, const uint port, const QString &name)
+    : RedisClient::ConnectionConfig(host, auth, port, name),
+      m_owner(QSharedPointer<TreeOperations>())
+{
+}
+
+ServerConfig::ServerConfig(const QVariantHash &options)
+    : RedisClient::ConnectionConfig(options),
+      m_owner(QSharedPointer<TreeOperations>())
+{
+
+}
+
+QString ServerConfig::keysPattern() const
+{
+    return param<QString>("keys_pattern", QString(DEFAULT_KEYS_GLOB_PATTERN));
+}
+
+void ServerConfig::setKeysPattern(QString keyGlobPattern)
+{
+    setParam<QString>("keys_pattern", keyGlobPattern);
+}
+
+QString ServerConfig::namespaceSeparator() const
+{
+    return param<QString>("namespace_separator", QString(DEFAULT_NAMESPACE_SEPARATOR));
+}
+
+void ServerConfig::setNamespaceSeparator(QString ns)
+{
+    return setParam<QString>("namespace_separator", ns);
+}
+
+uint ServerConfig::databaseScanLimit() const
+{
+    return param<uint>("db_scan_limit", DEFAULT_DB_SCAN_LIMIT);
+}
+
+void ServerConfig::setDatabaseScanLimit(uint limit)
+{
+    setParam<uint>("db_scan_limit", limit);
+}
+
+bool ServerConfig::useSshTunnel() const
+{
+    return RedisClient::ConnectionConfig::useSshTunnel();
+}
+
+QWeakPointer<TreeOperations> ServerConfig::owner() const
+{
+    return m_owner;
+}
+
+void ServerConfig::setOwner(QWeakPointer<TreeOperations> o)
+{
+    m_owner = o;
+}
+
+QVariantMap ServerConfig::filterHistory()
+{
+    return param<QVariantMap>("filter_history");
+}
+
+void ServerConfig::setFilterHistory(QVariantMap filterHistory)
+{
+    setParam<QVariantMap>("filter_history", filterHistory);
+}
+
+bool ServerConfig::askForSshPassword() const
+{
+    return param<bool>("ask_ssh_password", false);
+}
+
+void ServerConfig::setAskForSshPassword(bool v)
+{
+    setParam<bool>("ask_ssh_password", v);
+}
+
+QString ServerConfig::defaultFormatter() const
+{
+    return param<QString>("default_formatter", QString("auto"));
+}
+
+void ServerConfig::setDefaultFormatter(const QString &v)
+{
+    setParam<QString>("default_formatter", v);
+}
+
+QString ServerConfig::iconColor() const
+{
+    return param<QString>("icon_color", QString(""));
+}
+
+void ServerConfig::setIconColor(const QString &v)
+{
+    setParam<QString>("icon_color", v);
+}

+ 92 - 0
src/app/models/connectionconf.h

@@ -0,0 +1,92 @@
+#pragma once
+#include <QObject>
+#include <qredisclient/connectionconfig.h>
+
+
+class TreeOperations;
+
+class ServerConfig : public RedisClient::ConnectionConfig
+{
+    Q_GADGET
+
+    /* Basic settings */
+    Q_PROPERTY(QString name READ name WRITE setName)
+    Q_PROPERTY(QString host READ host WRITE setHost)
+    Q_PROPERTY(uint port READ port WRITE setPort)
+    Q_PROPERTY(QString auth READ auth WRITE setAuth)
+    Q_PROPERTY(QString username READ username WRITE setUsername)
+
+    /* SSL settings */
+    Q_PROPERTY(bool sslEnabled READ useSsl WRITE setSsl)
+    Q_PROPERTY(QString sslLocalCertPath READ sslLocalCertPath WRITE setSslLocalCertPath)
+    Q_PROPERTY(QString sslPrivateKeyPath READ sslPrivateKeyPath WRITE setSslPrivateKeyPath)
+    Q_PROPERTY(QString sslCaCertPath READ sslCaCertPath WRITE setSslCaCertPath)
+
+    /* SSH Settings */
+    Q_PROPERTY(QString sshPassword READ sshPassword WRITE setSshPassword)
+    Q_PROPERTY(bool askForSshPassword READ askForSshPassword WRITE setAskForSshPassword)
+    Q_PROPERTY(QString sshUser READ sshUser WRITE setSshUser)
+    Q_PROPERTY(QString sshHost READ sshHost WRITE setSshHost)
+    Q_PROPERTY(uint sshPort READ sshPort WRITE setSshPort)
+    Q_PROPERTY(QString sshPrivateKey READ getSshPrivateKeyPath WRITE setSshPrivateKeyPath)
+    Q_PROPERTY(bool sshAgent READ sshAgent WRITE setSshAgent)
+    Q_PROPERTY(QString sshAgentPath READ sshAgentPath WRITE setSshAgentPath)
+
+    /* Advanced settings */
+    Q_PROPERTY(QString keysPattern READ keysPattern WRITE setKeysPattern)
+    Q_PROPERTY(QString namespaceSeparator READ namespaceSeparator WRITE setNamespaceSeparator)
+    Q_PROPERTY(uint executeTimeout READ executeTimeout WRITE setExecutionTimeout)
+    Q_PROPERTY(uint connectionTimeout READ connectionTimeout WRITE setConnectionTimeout)    
+    Q_PROPERTY(bool overrideClusterHost READ overrideClusterHost WRITE setClusterHostOverride)
+    Q_PROPERTY(bool ignoreSSLErrors READ ignoreAllSslErrors WRITE setIgnoreAllSslErrors)
+    Q_PROPERTY(uint databaseScanLimit READ databaseScanLimit WRITE setDatabaseScanLimit)
+    Q_PROPERTY(QString defaultFormatter READ defaultFormatter WRITE setDefaultFormatter)
+    Q_PROPERTY(QString iconColor READ iconColor WRITE setIconColor)
+
+
+public:
+    static const char DEFAULT_NAMESPACE_SEPARATOR = ':';
+    static const char DEFAULT_KEYS_GLOB_PATTERN = '*';
+    static const bool DEFAULT_LUA_KEYS_LOADING = false;
+    static const uint DEFAULT_DB_SCAN_LIMIT = 20;
+    static constexpr const char* SSH_SECRET_ID = "ssh_password";
+
+public:
+    ServerConfig(const QString & host = "127.0.0.1", const QString & auth = "",
+                     const uint port = DEFAULT_REDIS_PORT, const QString & name = "");
+
+    explicit ServerConfig(const QVariantHash& options);
+
+    QString keysPattern() const;
+    void setKeysPattern(QString keyGlobPattern);
+
+    QString namespaceSeparator() const;
+    void setNamespaceSeparator(QString);
+
+    void setLuaKeysLoading(bool);
+
+    uint databaseScanLimit() const;
+    void setDatabaseScanLimit(uint limit);
+
+    Q_INVOKABLE bool useSshTunnel() const;
+
+    QWeakPointer<TreeOperations> owner() const;
+    void setOwner(QWeakPointer<TreeOperations> o);
+
+    QVariantMap filterHistory();
+    void setFilterHistory(QVariantMap filterHistory);
+
+    bool askForSshPassword() const;
+    void setAskForSshPassword(bool v);
+
+    QString defaultFormatter() const;
+    void setDefaultFormatter(const QString& v);
+
+    QString iconColor() const;
+    void setIconColor(const QString& v);
+
+private:
+    QWeakPointer<TreeOperations> m_owner;
+};
+
+Q_DECLARE_METATYPE(ServerConfig)

+ 22 - 0
src/app/models/connectiongroup.cpp

@@ -0,0 +1,22 @@
+#include "connectiongroup.h"
+
+#include "connections-tree/items/servergroup.h"
+
+ConnectionGroup::ConnectionGroup(QSharedPointer<ConnectionsTree::ServerGroup> g)
+    : m_group(g) {}
+
+ConnectionGroup::ConnectionGroup() : m_group(nullptr) {}
+
+QString ConnectionGroup::name() const {
+  if (!m_group) return QString();
+
+  return m_group->getDisplayName();
+}
+
+void ConnectionGroup::setName(const QString &n) {
+  if (m_group) m_group->setName(n);
+}
+
+QSharedPointer<ConnectionsTree::ServerGroup> ConnectionGroup::serverGroup() const {
+  return m_group;
+}

+ 29 - 0
src/app/models/connectiongroup.h

@@ -0,0 +1,29 @@
+#pragma once
+#include <QObject>
+#include <QSharedPointer>
+
+namespace ConnectionsTree {
+class ServerGroup;
+}
+
+class ConnectionGroup {
+  Q_GADGET
+
+  Q_PROPERTY(QString name READ name WRITE setName)
+
+ public:
+  ConnectionGroup();
+
+  ConnectionGroup(QSharedPointer<ConnectionsTree::ServerGroup> g);
+
+  QString name() const;
+
+  void setName(const QString& n);
+
+  QSharedPointer<ConnectionsTree::ServerGroup> serverGroup() const;
+
+ private:
+  QSharedPointer<ConnectionsTree::ServerGroup> m_group;
+};
+
+Q_DECLARE_METATYPE(ConnectionGroup)

+ 459 - 0
src/app/models/connectionsmanager.cpp

@@ -0,0 +1,459 @@
+#include "connectionsmanager.h"
+
+#include <QAbstractItemModel>
+#include <QDebug>
+#include <QFile>
+#include <QJsonDocument>
+#include <QJsonObject>
+#include <QUrlQuery>
+
+#include "app/events.h"
+#include "configmanager.h"
+#include "modules/bulk-operations/bulkoperationsmanager.h"
+#include "modules/connections-tree/items/serveritem.h"
+#include "modules/connections-tree/items/servergroup.h"
+#include "modules/value-editor/tabsmodel.h"
+
+ConnectionsManager::ConnectionsManager(const QString& configPath,
+                                       QSharedPointer<Events> events)
+    : ConnectionsTree::Model(), m_configPath(configPath), m_events(events) {
+  connect(this, &ConnectionsTree::Model::error, m_events.data(),
+          &Events::error);
+}
+
+void ConnectionsManager::loadConnections() {
+  if (!m_configPath.isEmpty() && QFile::exists(m_configPath)) {
+    loadConnectionsConfigFromFile(m_configPath);
+  }
+
+  emit connectionsLoaded();
+}
+
+void ConnectionsManager::addNewConnection(
+    const ServerConfig& config, bool saveToConfig,
+    QSharedPointer<ConnectionsTree::ServerGroup> group) {
+  createServerItemForConnection(config, group);
+
+  if (saveToConfig) saveConfig();
+
+  buildConnectionsCache();
+}
+
+void ConnectionsManager::addNewGroup(const QString& name) {
+  auto group = QSharedPointer<ConnectionsTree::ServerGroup>(
+      new ConnectionsTree::ServerGroup(
+          name, *static_cast<ConnectionsTree::Model*>(this)));
+
+  addGroup(group);
+
+  saveConfig();
+}
+
+void ConnectionsManager::updateGroup(const ConnectionGroup &group)
+{
+    auto serverGroup = group.serverGroup();
+
+    if (!serverGroup){
+        qWarning() << "invalid server group";
+        return;
+    }
+
+    emit itemChanged(serverGroup);
+
+    saveConfig();
+
+    buildConnectionsCache();
+}
+
+void ConnectionsManager::updateConnection(const ServerConfig& config) {
+  if (!config.owner()) return addNewConnection(config);
+
+  auto treeOperations = config.owner().toStrongRef();
+
+  if (!treeOperations) return;
+
+  treeOperations->setConfig(config);
+
+  saveConfig();
+}
+
+bool ConnectionsManager::importConnections(const QString& path) {
+  if (loadConnectionsConfigFromFile(path, true)) {
+    emit sizeChanged();
+    return true;
+  }
+  return false;
+}
+
+bool ConnectionsManager::loadConnectionsConfigFromFile(const QString& config,
+                                                       bool saveChangesToFile) {
+  QJsonArray connections;
+
+  QFile conf(config);
+
+  if (!conf.open(QIODevice::ReadOnly)) return false;
+
+  QByteArray data = conf.readAll();
+  conf.close();
+
+  QJsonDocument jsonConfig = QJsonDocument::fromJson(data);
+
+  if (jsonConfig.isEmpty()) return true;
+
+  if (!jsonConfig.isArray()) {
+    return false;
+  }
+
+  connections = jsonConfig.array();
+
+  for (QJsonValue connection : connections) {
+    if (!connection.isObject()) continue;
+
+    auto obj = connection.toObject();
+
+    bool isValidGroup = obj.contains("type") && obj.contains("connections") &&
+            obj.contains("name") && obj["connections"].isArray() &&
+            obj["type"].toString().toLower() == "group";
+
+    if (isValidGroup) {
+      auto groupConnections = obj["connections"].toArray();
+
+      auto group = QSharedPointer<ConnectionsTree::ServerGroup>(
+          new ConnectionsTree::ServerGroup(
+              obj["name"].toString(),
+              *static_cast<ConnectionsTree::Model*>(this)));
+
+      for (const QJsonValue &c : qAsConst(groupConnections)) {
+        if (!c.isObject()) continue;
+
+        ServerConfig conf(c.toObject().toVariantHash());
+
+        if (conf.isNull()) continue;
+
+        conf.setId(QUuid::createUuid().toByteArray());
+        addNewConnection(conf, false, group);
+      }
+
+      addGroup(group);      
+    } else {
+        ServerConfig conf(obj.toVariantHash());
+        if (conf.isNull()) continue;
+        addNewConnection(conf, false);
+    }
+  }
+
+  if (saveChangesToFile) saveConfig();
+
+  buildConnectionsCache();
+
+  return true;
+}
+
+void ConnectionsManager::tryToConnect(const ServerConfig &config, QJSValue jsCallback)
+{
+    RedisClient::Connection testConnection(config);
+    m_events->registerLoggerForConnection(testConnection);
+
+    try {
+      jsCallback.call(QJSValueList{testConnection.connect()});
+    } catch (const RedisClient::Connection::Exception&) {
+      jsCallback.call(QJSValueList{false});
+    }
+}
+
+void ConnectionsManager::saveConfig() {
+  saveConnectionsConfigToFile(m_configPath);
+}
+
+bool ConnectionsManager::saveConnectionsConfigToFile(
+    const QString& pathToFile) {
+  QJsonArray connections;
+
+  auto addConfig = [](QSharedPointer<ConnectionsTree::TreeItem> i,
+                      QJsonArray& connections) {
+    auto srvItem = i.dynamicCast<ConnectionsTree::ServerItem>();
+
+    if (!srvItem) return;
+
+    auto op = srvItem->getOperations().dynamicCast<TreeOperations>();
+
+    if (!op) return;
+
+    auto config = op->config();
+    QSet<QString> ignoreFields {"id"};
+
+    if (config.askForSshPassword()) {
+        ignoreFields.insert(ServerConfig::SSH_SECRET_ID);
+    }
+
+    connections.push_back(QJsonValue(config.toJsonObject(ignoreFields)));
+  };
+
+  for (auto item : m_treeItems) {
+    if (item->type() == "server_group") {
+      QJsonObject group;
+      group["type"] = "group";
+      group["name"] = item->getDisplayName();
+
+      QJsonArray groupConnections;
+
+      for (auto srv : item->getAllChilds()) {
+        addConfig(srv, groupConnections);
+      }
+
+      group["connections"] = groupConnections;
+      connections.push_back(QJsonValue(group));
+
+    } else if (item->type() == "server") {
+      addConfig(item, connections);
+    }
+  }
+
+  return saveJsonArrayToFile(connections, pathToFile);
+}
+
+void ConnectionsManager::testConnectionSettings(const ServerConfig& config,
+                                                QJSValue jsCallback) {
+  if (!jsCallback.isCallable()) {
+    qDebug() << "JS callback is not callable";
+    return;
+  }
+
+  if (config.askForSshPassword()) {
+    m_jsCallback = jsCallback;
+
+    emit askUserForConnectionSecret(config, ServerConfig::SSH_SECRET_ID);
+  } else {
+    tryToConnect(config, jsCallback);
+  }
+}
+
+void ConnectionsManager::proceedWithConnectionSecret(const ServerConfig &config)
+{
+    if (m_jsCallback.isCallable()) {
+        tryToConnect(config, m_jsCallback);
+        m_jsCallback = QJSValue();
+        return;
+    }
+
+    if (!config.owner()) {
+        qWarning() << "Invalid config with secret";
+        return;
+    }
+
+    auto treeOperations = config.owner().toStrongRef();
+
+    if (!treeOperations) {
+        qWarning() << "Config with secret doesn't have owner";
+        return;
+    }
+
+    treeOperations->proceedWithSecret(config);
+}
+
+ServerConfig ConnectionsManager::createEmptyConfig() const {
+  return ServerConfig();
+}
+
+ServerConfig ConnectionsManager::parseConfigFromRedisConnectionString(const QString& connectionString) const {
+    QUrl url = QUrl(connectionString);
+
+    QUrlQuery query = QUrlQuery(url.query());
+
+    ServerConfig config;
+
+    config.setHost(url.host().isEmpty() || url.host() == "localhost" ? "127.0.0.1" : url.host());
+
+    config.setPort(url.port() == -1 ? 6379 : url.port());
+
+    config.setUsername(url.userName());
+
+    config.setAuth(url.password().isEmpty() ? query.queryItemValue("password") : url.password());
+
+    if (url.scheme() == "rediss" || (!query.isEmpty() && query.queryItemValue("ssl") == "true")) {
+        config.setSsl(true);
+    }
+
+    return config;
+}
+
+bool ConnectionsManager::isRedisConnectionStringValid(
+    const QString& connectionString) {
+  QUrl url;
+  if (connectionString.startsWith("redis://") ||
+      connectionString.startsWith("rediss://")) {
+    url = QUrl(connectionString);
+  } else {
+    url = QUrl(QString("redis://%1").arg(connectionString));
+  }
+
+  return url.isValid() &&
+         (url.scheme() == "redis" || url.scheme() == "rediss") &&
+         !url.host().isEmpty();
+}
+
+int ConnectionsManager::size() {
+  int connectionsCount = 0;
+
+  for (auto item : qAsConst(m_treeItems)) {
+    if (item->type() == "server_group") {
+      connectionsCount += item->childCount();
+    } else if (item->type() == "server") {
+      connectionsCount++;
+    }
+  }
+  return connectionsCount;
+}
+
+QSharedPointer<RedisClient::Connection> ConnectionsManager::getByIndex(
+    int index) {
+  auto op = m_connectionsCache.values().at(index)->getOperations();
+
+  if (!op) return QSharedPointer<RedisClient::Connection>();
+
+  auto treeOp = op.dynamicCast<TreeOperations>();
+
+  if (!treeOp) return QSharedPointer<RedisClient::Connection>();
+
+  return treeOp->connection();
+}
+
+QStringList ConnectionsManager::getConnections() {
+  return m_connectionsCache.keys();
+}
+
+void ConnectionsManager::applyGroupChanges() {
+  ConnectionsTree::Model::applyGroupChanges();
+
+  buildConnectionsCache();
+
+  saveConfig();
+}
+
+void ConnectionsManager::createServerItemForConnection(
+    const ServerConfig& config,
+    QSharedPointer<ConnectionsTree::ServerGroup> group) {
+  using namespace ConnectionsTree;
+
+  auto treeModel =
+      QSharedPointer<TreeOperations>(new TreeOperations(config, m_events));
+
+  connect(treeModel.data(), &TreeOperations::createNewConnection, this,
+          [this](const ServerConfig& config) { addNewConnection(config); });
+
+  connect(treeModel.data(), &TreeOperations::secretRequired, this,
+          &ConnectionsManager::askUserForConnectionSecret);
+
+  QWeakPointer<TreeItem> parent;
+
+  if (group) {
+    parent = group.toWeakRef();
+  }
+
+  auto serverItem = QSharedPointer<ServerItem>(
+      new ServerItem(treeModel.dynamicCast<ConnectionsTree::Operations>(),
+                     *static_cast<ConnectionsTree::Model*>(this), parent));
+  serverItem->setWeakPointer(serverItem.toWeakRef());
+
+  connect(
+      treeModel.data(), &TreeOperations::configUpdated, this,
+      [this, serverItem]() {
+        if (!serverItem) return;
+
+        emit itemChanged(
+            serverItem.dynamicCast<ConnectionsTree::TreeItem>().toWeakRef());
+      });
+
+  connect(treeModel.data(), &TreeOperations::filterHistoryUpdated,
+          this, [this]() {
+      saveConfig();
+  });
+
+  connect(serverItem.data(), &ConnectionsTree::ServerItem::editActionRequested,
+          this, [this, treeModel]() {
+            if (!treeModel) return;
+
+            auto config = treeModel->config();
+
+            emit connectionAboutToBeEdited(config.name());
+
+            // NOTE(u_glide): Do not show temproary stored password in the UI
+            if (config.askForSshPassword()) {
+                config.setSshPassword(QString());
+            }
+
+            emit editConnection(config);
+          });
+
+  connect(serverItem.data(),
+          &ConnectionsTree::ServerItem::deleteActionRequested, this,
+          [this, serverItem, treeModel, group]() {
+            if (!serverItem || !treeModel) return;
+
+            emit connectionAboutToBeEdited(treeModel->config().name());
+
+            if (group) {
+              group->removeConnection(serverItem);
+            } else {
+              removeRootItem(serverItem);
+            }
+
+            buildConnectionsCache();
+
+            emit sizeChanged();
+            saveConfig();
+          });
+
+  if (group) {
+    group->addServer(serverItem);
+  } else {
+    addRootItem(serverItem);
+  }
+}
+
+void ConnectionsManager::addGroup(
+    QSharedPointer<ConnectionsTree::ServerGroup> group) {
+  connect(group.data(), &ConnectionsTree::ServerGroup::editActionRequested,
+          this, [this, group]() {
+            if (!group) return;
+
+            ConnectionGroup g(group);
+
+            emit editConnectionGroup(g);
+          });
+
+  connect(group.data(), &ConnectionsTree::ServerGroup::deleteActionRequested,
+          this, [this, group]() {
+            if (!group) return;
+
+            removeRootItem(group);
+
+            buildConnectionsCache();
+
+            emit sizeChanged();
+            saveConfig();
+          });
+
+  addRootItem(group);
+
+  buildConnectionsCache();
+}
+
+void ConnectionsManager::buildConnectionsCache() {
+  m_connectionsCache.clear();
+
+  for (auto item : m_treeItems) {
+    if (item->type() == "server_group") {
+      QString nameTemplate = QString("[%1] %2").arg(item->getDisplayName());
+
+      for (auto srv : item->getAllChilds()) {
+        QString name = nameTemplate.arg(srv->getDisplayName());
+        m_connectionsCache[name] =
+            srv.dynamicCast<ConnectionsTree::ServerItem>();
+      }
+    } else if (item->type() == "server") {
+      m_connectionsCache[item->getDisplayName()] =
+          item.dynamicCast<ConnectionsTree::ServerItem>();
+    }
+  }
+}

+ 103 - 0
src/app/models/connectionsmanager.h

@@ -0,0 +1,103 @@
+#pragma once
+#include <qredisclient/connection.h>
+
+#include <QSharedPointer>
+#include <functional>
+
+#include "app/models/connectionconf.h"
+#include "bulk-operations/connections.h"
+#include "connections-tree/model.h"
+#include "treeoperations.h"
+#include "connectiongroup.h"
+
+namespace ValueEditor {
+class TabsModel;
+}
+
+namespace ConnectionsTree {
+class ServerGroup;
+}
+
+class Events;
+
+class ConnectionsManager : public ConnectionsTree::Model,
+                           public BulkOperations::ConnectionsModel {
+  Q_OBJECT
+
+  Q_PROPERTY(int connectionsCount READ size NOTIFY sizeChanged)
+
+ public:
+  ConnectionsManager(const QString& m_configPath,
+                     QSharedPointer<Events> events);  
+
+  void loadConnections();
+
+  Q_INVOKABLE void addNewConnection(const ServerConfig& config,
+                                    bool saveToConfig = true,
+                                    QSharedPointer<ConnectionsTree::ServerGroup> group =
+                                        QSharedPointer<ConnectionsTree::ServerGroup>());
+
+  Q_INVOKABLE void addNewGroup(const QString& name);
+
+  Q_INVOKABLE void updateGroup(const ConnectionGroup& group);
+
+  Q_INVOKABLE void updateConnection(const ServerConfig& config);
+
+  Q_INVOKABLE bool importConnections(const QString&);
+
+  Q_INVOKABLE bool saveConnectionsConfigToFile(const QString&);
+
+  Q_INVOKABLE void testConnectionSettings(const ServerConfig& config, QJSValue jsCallback);
+
+  Q_INVOKABLE void proceedWithConnectionSecret(const ServerConfig& config);
+
+  Q_INVOKABLE ServerConfig createEmptyConfig() const;
+
+  Q_INVOKABLE ServerConfig parseConfigFromRedisConnectionString(const QString&) const;
+
+  Q_INVOKABLE bool isRedisConnectionStringValid(const QString&);
+
+  void saveConfig();
+
+  Q_INVOKABLE int size() override;
+
+  // BulkOperations model methods
+  QSharedPointer<RedisClient::Connection> getByIndex(int index) override;
+
+  QStringList getConnections() override;
+
+  void applyGroupChanges() override;
+
+ signals:
+  void editConnection(ServerConfig config);
+
+  void editConnectionGroup(ConnectionGroup group);
+
+  void connectionAboutToBeEdited(QString name);
+
+  void sizeChanged();
+
+  void connectionsLoaded();
+
+  void askUserForConnectionSecret(const ServerConfig& config, const QString& id);
+
+ protected:
+  bool loadConnectionsConfigFromFile(const QString& config,
+                                     bool saveChangesToFile = false);
+
+  void tryToConnect(const ServerConfig& config, QJSValue jsCallback);
+
+ private:
+  void createServerItemForConnection(const ServerConfig &config,
+      QSharedPointer<ConnectionsTree::ServerGroup> group=QSharedPointer<ConnectionsTree::ServerGroup>());
+
+  void addGroup(QSharedPointer<ConnectionsTree::ServerGroup> serverGroup);
+
+  void buildConnectionsCache();
+
+ private:
+  QString m_configPath;
+  QSharedPointer<Events> m_events;
+  QJSValue m_jsCallback;
+  QMap<QString, QSharedPointer<ConnectionsTree::ServerItem>> m_connectionsCache;
+};

+ 374 - 0
src/app/models/key-models/abstractkey.h

@@ -0,0 +1,374 @@
+#pragma once
+#include <qredisclient/redisclient.h>
+#include <qredisclient/utils/text.h>
+#include <QByteArray>
+#include <QCoreApplication>
+#include <QDebug>
+
+#include <QPair>
+#include <QSharedPointer>
+#include <QString>
+#include <QVariant>
+#include "modules/value-editor/keymodel.h"
+#include "rowcache.h"
+#include "app/models/connectionconf.h"
+
+template <typename T>
+class KeyModel : public ValueEditor::Model {
+ public:
+  KeyModel(QSharedPointer<RedisClient::Connection> connection,
+           QByteArray fullPath, int dbIndex, long long ttl,
+           QByteArray rowsCountCmd = QByteArray(),
+           QByteArray rowsLoadCmd = QByteArray())
+      : m_connection(connection),
+        m_keyFullPath(fullPath),
+        m_dbIndex(dbIndex),
+        m_ttl(ttl),
+        m_rowCount(0),
+        m_isMultiRow(!rowsCountCmd.isEmpty()),
+        m_rowsCountCmd(rowsCountCmd),
+        m_rowsLoadCmd(rowsLoadCmd),
+        m_scanCursor(0),
+        m_notifier(new ValueEditor::ModelSignals(), &QObject::deleteLater) {}
+
+  virtual QString getKeyName() override {
+    return printableString(m_keyFullPath);
+  }
+
+  virtual QString getKeyTitle(int limit=-1) override {
+    QString fullTitle = QString("%1::db%2::%3")
+        .arg(m_connection->getConfig().name())
+        .arg(m_dbIndex)
+        .arg(getKeyName());
+
+    int length = fullTitle.size();
+
+    if (limit == -1 || length <= limit){
+        return fullTitle;
+    } else {
+        return QString("%1 ... %2").arg(fullTitle.mid(0, limit/2)).arg(fullTitle.mid(length - limit/2));
+    }
+  }
+
+  virtual long long getTTL() override { return m_ttl; }
+
+  virtual bool isMultiRow() const override { return m_isMultiRow; }
+
+  virtual bool isRowLoaded(int rowIndex) override {
+    return m_rowsCache.isRowLoaded(rowIndex);
+  }
+
+  virtual unsigned long rowsCount() override {
+    if (isMultiRow())
+      return m_rowCount;
+    else
+      return 1;
+  }
+
+  virtual void setKeyName(const QByteArray& newKeyName,
+                          ValueEditor::Model::Callback c) override {
+    // NOTE(u_glide): DUMP + RESTORE + DEL is cluster compatible alternative to RENAME command
+    executeCmd(
+        {"DUMP", m_keyFullPath}, c,
+        [this, newKeyName](RedisClient::Response r, Callback c) {
+          executeCmd(
+              {"RESTORE", newKeyName,
+               QString::number(m_ttl > 0 ? m_ttl : 0).toLatin1(),
+               r.value().toByteArray()},
+              c,
+              [this, newKeyName](RedisClient::Response r, Callback c) {
+                if (!r.isOkMessage()) {
+                  return c(QCoreApplication::translate(
+                               "RESP", "Cannot rename key %1: %2")
+                               .arg(getKeyName())
+                               .arg(r.value().toString()));
+                }
+
+                executeCmd(
+                    {"DEL", m_keyFullPath}, [](const QString&) {},
+                    [](RedisClient::Response, Callback) {});
+
+                m_keyFullPath = newKeyName;
+                c(QString());
+              },
+              RedisClient::Response::Type::Status);
+        },
+        RedisClient::Response::Type::String);
+  }
+
+  virtual void setTTL(const long long ttl,
+                      ValueEditor::Model::Callback c) override {
+    executeCmd(
+        {"EXPIRE", m_keyFullPath, QString::number(ttl).toLatin1()}, c,
+        [this, ttl](RedisClient::Response r, Callback c) {
+          if (r.value().toInt() == 0) {
+            return c(
+                QCoreApplication::translate("RESP", "Cannot set TTL for key %1")
+                    .arg(getKeyName()));
+          }
+
+          if (ttl >= 0)
+            m_ttl = ttl;
+          else
+            m_ttl = -1;
+
+          c(QString());
+        },
+        RedisClient::Response::Type::Integer);
+  }
+
+  virtual void persistKey(Callback c) override {
+    executeCmd(
+        {"PERSIST", m_keyFullPath}, c,
+        [this](RedisClient::Response r, Callback c) {
+          if (r.value().toInt() == 0) {
+            return c(QCoreApplication::translate(
+                         "RESP",
+                         "Cannot persist key '%1'. <br> Key does not exist or "
+                         "does not have an assigned TTL value")
+                         .arg(getKeyName()));
+          }
+
+          m_ttl = -1;
+
+          c(QString());
+        },
+        RedisClient::Response::Type::Integer);
+  }
+
+  virtual void removeKey(ValueEditor::Model::Callback c) override {
+    executeCmd({"DEL", m_keyFullPath}, c,
+               [this](RedisClient::Response, Callback c) {
+                 m_notifier->removed();
+                 c(QString());
+               });
+  }
+
+  virtual void loadRows(QVariant rowStart, unsigned long count,
+                        LoadRowsCallback callback) override {
+    if (m_rowsLoadCmd.mid(1, 4).toLower() == "scan") {
+      QList<QByteArray> cmdParts = {m_rowsLoadCmd, m_keyFullPath,
+                                    QString::number(m_scanCursor).toLatin1(),
+                                    "COUNT", QString::number(count).toLatin1()};
+
+      auto self = ValueEditor::Model::sharedFromThis().toWeakRef();
+
+      m_connection->cmd(
+          cmdParts, m_notifier.data(), -1,
+          [this, callback, rowStart, self](RedisClient::Response r) {
+            if (!r.isValidScanResponse()) {
+              callback(QCoreApplication::translate(
+                           "RESP", "Cannot parse scan response"),
+                       0);
+              return;
+            }
+
+            if (r.getCursor() > 0) {
+              m_scanCursor = r.getCursor();
+            }
+
+            try {
+              unsigned long addedRows =
+                  addLoadedRowsToCache(r.getCollection(), rowStart);
+              callback(QString(), addedRows);
+            } catch (const std::runtime_error& e) {
+              callback(QString(e.what()), 0);
+            }
+          },
+          [self, callback](QString err) {
+            if (!self) {
+              return;
+            }
+
+            return callback(
+                QCoreApplication::translate("RESP", "Connection error: ") + err,
+                0);
+          });
+
+    } else {
+      getRowsRange(
+          getRangeCmd(rowStart, count),
+          [this, callback, rowStart](const QString& err, QVariantList result) {
+            if (!err.isEmpty()) return callback(err, 0);
+
+            unsigned long addedRows = addLoadedRowsToCache(result, rowStart);
+            callback(QString(), addedRows);
+          });
+    }
+  }
+
+  virtual void clearRowCache() override { m_rowsCache.clear(); }
+
+  virtual QSharedPointer<ValueEditor::ModelSignals> getConnector()
+      const override {
+    return m_notifier;
+  }
+
+  virtual QSharedPointer<RedisClient::Connection> getConnection()
+      const override {
+    return m_connection;
+  }
+
+  virtual QString getDefaultFormatter() const override{
+      if (!m_connection)
+          return QString("auto");
+
+      // TODO(u_glide): Pass ServerConfig to KeyModel and remove this
+      return m_connection->getConfig().getInternalParameters().value("default_formatter", QString("auto")).toString();
+  }
+
+  virtual unsigned int dbIndex() const override { return m_dbIndex; }
+
+  virtual void loadRowsCount(ValueEditor::Model::Callback c) override {
+    if (!isMultiRow()) {
+      m_rowCount = 1;
+      return c(QString());
+    }
+
+    executeCmd(
+        {m_rowsCountCmd, m_keyFullPath}, c,
+        [this](RedisClient::Response r, Callback c) {
+          m_rowCount = r.value().toUInt();
+          c(QString());
+        },
+        RedisClient::Response::Type::Integer);
+  }
+
+ protected:
+  // multi row internal operations
+  virtual QList<QByteArray> getRangeCmd(QVariant rowStartId,
+                                        unsigned long count) {
+    QList<QByteArray> cmd;
+
+    unsigned long rowStart = rowStartId.toULongLong();
+    unsigned long rowEnd = std::min(m_rowCount, rowStart + count) - 1;
+
+    if (m_rowsLoadCmd.contains(' ')) {
+      QList<QByteArray> suffixCmd(m_rowsLoadCmd.split(' '));
+
+      cmd << suffixCmd.takeFirst();
+      cmd << m_keyFullPath << QString::number(rowStart).toLatin1()
+          << QString::number(rowEnd).toLatin1();
+      cmd += suffixCmd;
+
+    } else {
+      cmd << m_rowsLoadCmd << m_keyFullPath
+          << QString::number(rowStart).toLatin1()
+          << QString::number(rowEnd).toLatin1();
+    }
+    return cmd;
+  }
+
+  virtual void getRowsRange(
+      const QList<QByteArray>& rangeCmd,
+      std::function<void(const QString&, QVariantList)> callback) {
+    try {
+      m_connection->command(
+          rangeCmd, getConnector().data(),
+          [this, callback](RedisClient::Response r, QString e) {
+            if (!e.isEmpty()) {
+              return callback(e, QVariantList());
+            }
+
+            if (r.type() != RedisClient::Response::Array) {
+              return callback(QCoreApplication::translate(
+                                  "RESP", "Cannot load rows for key %1: %2")
+                                  .arg(getKeyName()),
+                              QVariantList());
+            }
+
+            return callback(QString(), r.value().toList());
+          },
+          -1);
+    } catch (const RedisClient::Connection::Exception& e) {
+      callback(
+          QCoreApplication::translate("RESP", "Cannot load rows for key %1: %2")
+              .arg(getKeyName())
+              .arg(e.what()),
+          QVariantList());
+    }
+  }
+
+  // row validator
+  virtual bool isRowValid(const QVariantMap& row) {
+    if (row.isEmpty()) return false;
+
+    QSet<QString> validKeys;
+
+    foreach (QByteArray role, getRoles().values()) { validKeys.insert(role); }
+
+    QMapIterator<QString, QVariant> i(row);
+
+    while (i.hasNext()) {
+      i.next();
+
+      if (!validKeys.contains(i.key())) return false;
+    }
+
+    return true;
+  }
+
+  virtual void setRemovedIfEmpty() {
+    if (m_rowCount == 0) {
+      m_notifier->removed();
+    }
+  }
+
+  typedef std::function<void(RedisClient::Response r, Callback c)> CmdHandler;
+
+  virtual void executeCmd(QList<QByteArray> cmd, Callback c,
+                          CmdHandler handler = CmdHandler(),
+                          RedisClient::Response::Type expectedType =
+                              RedisClient::Response::Type::Unknown) {
+    m_connection->cmd(
+        cmd, m_notifier.data(), -1,
+        [c, handler, expectedType](RedisClient::Response r) {
+          if (expectedType != RedisClient::Response::Type::Unknown &&
+              r.type() != expectedType) {
+            return c(QCoreApplication::translate(
+                         "RESP", "Server returned unexpected response: ") +
+                     r.value().toString());
+          }
+
+          if (handler) {
+            return handler(r, c);
+          } else {
+            return c(QString());
+          }
+        },
+        [c](QString err) {
+          return c(QCoreApplication::translate("RESP", "Connection error: ") +
+                   err);
+        });
+  }
+
+  virtual int addLoadedRowsToCache(const QVariantList& rows,
+                                   QVariant rowStart) = 0;
+
+  QVariant filter(const QString& key) const override {
+    return m_filters.value(key, QVariant());
+  };
+
+  void setFilter(const QString& k, QVariant v) override {
+      m_filters[k] = v;
+      qDebug() << "filter:" << k << v;
+  }
+
+ protected:
+  QSharedPointer<RedisClient::Connection> m_connection;
+  QByteArray m_keyFullPath;
+  int m_dbIndex;
+  long long m_ttl;
+  unsigned long m_rowCount;
+  bool m_isMultiRow;
+
+  // CMD strings
+  QByteArray m_rowsCountCmd;
+  QByteArray m_rowsLoadCmd;
+
+  MappedCache<T> m_rowsCache;
+  long long m_scanCursor;
+  QSharedPointer<ValueEditor::ModelSignals> m_notifier;
+
+  QVariantMap m_filters;
+};

+ 73 - 0
src/app/models/key-models/bfkey.cpp

@@ -0,0 +1,73 @@
+#include "bfkey.h"
+
+#include <QJsonDocument>
+
+BloomFilterKeyModel::BloomFilterKeyModel(
+    QSharedPointer<RedisClient::Connection> connection, QByteArray fullPath,
+    int dbIndex, long long ttl, QString filterFamily)
+    : KeyModel(connection, fullPath, dbIndex, ttl), m_type(filterFamily) {}
+
+QString BloomFilterKeyModel::type() { return m_type; }
+
+QStringList BloomFilterKeyModel::getColumnNames() {
+  return QStringList() << "value";
+}
+
+QHash<int, QByteArray> BloomFilterKeyModel::getRoles() {
+  QHash<int, QByteArray> roles;
+  roles[Roles::Value] = "value";
+  return roles;
+}
+
+QVariant BloomFilterKeyModel::getData(int rowIndex, int dataRole) {
+  if (rowIndex > 0 || !isRowLoaded(rowIndex)) return QVariant();
+  if (dataRole == Roles::Value)
+    return QJsonDocument::fromVariant(m_rowsCache[rowIndex])
+        .toJson(QJsonDocument::Compact);
+
+  return QVariant();
+}
+
+void BloomFilterKeyModel::addRow(const QVariantMap& row, Callback c) {
+  QByteArray value = row.value("value").toByteArray();
+
+  executeCmd({QString("%1.ADD").arg(m_type).toLatin1(), m_keyFullPath, value},
+             [this, c](const QString& err) {
+               m_rowCount++;
+               return c(err);
+             });
+}
+
+void BloomFilterKeyModel::loadRows(QVariant, unsigned long,
+                                   LoadRowsCallback callback) {
+  auto onConnectionError = [callback](const QString& err) {
+    return callback(err, 0);
+  };
+
+  auto responseHandler = [this, callback](const RedisClient::Response& r, Callback) {
+    m_rowsCache.clear();
+    auto value = r.value().toList();
+
+    QVariantMap row;
+
+    for (auto item = value.cbegin(); item != value.cend(); ++item) {
+      auto key = item->toByteArray();
+      ++item;
+
+      if (item == value.cend()) {
+        emit m_notifier->error(QCoreApplication::translate(
+            "RESP", "Data was loaded from server partially."));
+        break;
+      }
+
+      auto keyVal = item->toByteArray();
+      row[key] = keyVal;
+    }
+
+    m_rowsCache.push_back(row);
+    callback(QString(), 1);
+  };
+
+  executeCmd({QString("%1.INFO").arg(m_type).toLatin1(), m_keyFullPath},
+             onConnectionError, responseHandler, RedisClient::Response::Array);
+}

+ 34 - 0
src/app/models/key-models/bfkey.h

@@ -0,0 +1,34 @@
+#pragma once
+#include "stringkey.h"
+
+class BloomFilterKeyModel : public KeyModel<QVariant> {
+ public:
+  BloomFilterKeyModel(QSharedPointer<RedisClient::Connection> connection,
+                      QByteArray fullPath, int dbIndex, long long ttl, QString filterFamily="bf");
+
+  QString type() override;
+  QStringList getColumnNames() override;
+  QHash<int, QByteArray> getRoles() override;
+  QVariant getData(int rowIndex, int dataRole) override;
+
+  void addRow(const QVariantMap&, Callback c) override;
+
+  virtual void updateRow(int, const QVariantMap&,
+                         Callback) override {
+      // NOTE(u_glide): BF/CF is read-only
+  }
+  void loadRows(QVariant, unsigned long, LoadRowsCallback callback) override;
+
+  void removeRow(int, Callback) override {
+      // NOTE(u_glide): BF/CF is read-only
+  }
+
+  virtual unsigned long rowsCount() override { return m_rowCount; }
+
+ protected:
+  int addLoadedRowsToCache(const QVariantList&, QVariant) override { return 1; }
+
+ private:
+  enum Roles { Value = Qt::UserRole + 1 };
+  QString m_type;
+};

+ 149 - 0
src/app/models/key-models/hashkey.cpp

@@ -0,0 +1,149 @@
+#include "hashkey.h"
+#include <qredisclient/connection.h>
+#include <QObject>
+
+HashKeyModel::HashKeyModel(QSharedPointer<RedisClient::Connection> connection,
+                           QByteArray fullPath, int dbIndex, long long ttl)
+    : KeyModel(connection, fullPath, dbIndex, ttl, "HLEN", "HSCAN") {}
+
+QString HashKeyModel::type() { return "hash"; }
+
+QStringList HashKeyModel::getColumnNames() {
+  return QStringList() << "rowNumber"
+                       << "key"
+                       << "value";
+}
+
+QHash<int, QByteArray> HashKeyModel::getRoles() {
+  QHash<int, QByteArray> roles;
+  roles[Roles::RowNumber] = "rowNumber";
+  roles[Roles::Key] = "key";
+  roles[Roles::Value] = "value";
+  return roles;
+}
+
+QVariant HashKeyModel::getData(int rowIndex, int dataRole) {
+  if (!isRowLoaded(rowIndex)) return QVariant();
+
+  QPair<QByteArray, QByteArray> row = m_rowsCache[rowIndex];
+
+  if (dataRole == Roles::Key)
+    return row.first;
+  else if (dataRole == Roles::Value)
+    return row.second;
+  else if (dataRole == Roles::RowNumber)
+    return rowIndex;
+
+  return QVariant();
+}
+
+void HashKeyModel::updateRow(int rowIndex, const QVariantMap &row, Callback c) {
+  if (!isRowLoaded(rowIndex) || !isRowValid(row)) {
+    c(QCoreApplication::translate("RESP", "Invalid row"));
+    return;
+  }
+
+  QPair<QByteArray, QByteArray> cachedRow = m_rowsCache[rowIndex];
+
+  bool keyChanged = cachedRow.first != row["key"].toByteArray();
+  bool valueChanged = cachedRow.second != row["value"].toByteArray();
+
+  QPair<QByteArray, QByteArray> newRow(
+      (keyChanged) ? row["key"].toByteArray() : cachedRow.first,
+      (valueChanged) ? row["value"].toByteArray() : cachedRow.second);
+
+  auto afterValueUpdate = [this, c, rowIndex, newRow](const QString &err) {
+    if (err.isEmpty()) m_rowsCache.replace(rowIndex, newRow);
+
+    return c(err);
+  };
+
+  if (keyChanged) {
+    deleteHashRow(cachedRow.first,
+                  [this, c, newRow, afterValueUpdate](const QString &err) {
+                    if (err.size() > 0) return c(err);
+
+                    setHashRow(newRow.first, newRow.second, afterValueUpdate);
+                  });
+  } else {
+    setHashRow(newRow.first, newRow.second, afterValueUpdate);
+  }
+}
+
+void HashKeyModel::addRow(const QVariantMap &row, Callback c) {
+  if (!isRowValid(row)) {
+    c(QCoreApplication::translate("RESP", "Invalid row"));
+    return;
+  }
+
+  setHashRow(
+      row["key"].toByteArray(), row["value"].toByteArray(),
+      [this, c](const QString &err) {
+        if (err.isEmpty()) m_rowCount++;
+        return c(err);
+      },
+      false);
+}
+
+void HashKeyModel::removeRow(int i, Callback c) {
+  if (!isRowLoaded(i)) return;
+
+  QPair<QByteArray, QByteArray> row = m_rowsCache[i];
+
+  deleteHashRow(row.first, [this, i, c](const QString &err) {
+    if (err.isEmpty()) {
+      m_rowCount--;
+      m_rowsCache.removeAt(i);
+      setRemovedIfEmpty();
+    }
+
+    return c(err);
+  });
+}
+
+void HashKeyModel::setHashRow(const QByteArray &hashKey,
+                              const QByteArray &hashValue, Callback c,
+                              bool updateIfNotExist) {
+  QList<QByteArray> rawCmd{(updateIfNotExist) ? "HSET" : "HSETNX",
+                           m_keyFullPath, hashKey, hashValue};
+
+  executeCmd(rawCmd, c,
+             [updateIfNotExist](RedisClient::Response r, Callback c) {
+               if (updateIfNotExist == false && r.value().toInt() == 0) {
+                 return c(QCoreApplication::translate(
+                     "RESP", "Value with the same key already exists"));
+               } else {
+                 return c(QString());
+               }
+             });
+}
+
+void HashKeyModel::deleteHashRow(const QByteArray &hashKey, Callback c) {
+  executeCmd({"HDEL", m_keyFullPath, hashKey}, c);
+}
+
+int HashKeyModel::addLoadedRowsToCache(const QVariantList &rows,
+                                       QVariant rowStartId) {
+  QList<QPair<QByteArray, QByteArray>> result;
+
+  for (QVariantList::const_iterator item = rows.begin(); item != rows.end();
+       ++item) {
+    QPair<QByteArray, QByteArray> value;
+    value.first = item->toByteArray();
+    ++item;
+
+    if (item == rows.end()) {
+      emit m_notifier->error(QCoreApplication::translate(
+          "RESP", "Data was loaded from server partially."));
+      return 0;
+    }
+
+    value.second = item->toByteArray();
+    result.push_back(value);
+  }
+
+  auto rowStart = rowStartId.toLongLong();
+  m_rowsCache.addLoadedRange({rowStart, rowStart + result.size() - 1}, result);
+
+  return result.size();
+}

+ 28 - 0
src/app/models/key-models/hashkey.h

@@ -0,0 +1,28 @@
+#pragma once
+#include "abstractkey.h"
+
+class HashKeyModel : public KeyModel<QPair<QByteArray, QByteArray>> {
+ public:
+  HashKeyModel(QSharedPointer<RedisClient::Connection> connection,
+               QByteArray fullPath, int dbIndex, long long ttl);
+
+  QString type() override;
+  QStringList getColumnNames() override;
+  QHash<int, QByteArray> getRoles() override;
+
+  QVariant getData(int rowIndex, int dataRole) override;
+  void addRow(const QVariantMap &, Callback) override;
+  virtual void updateRow(int rowIndex, const QVariantMap &, Callback) override;
+  void removeRow(int, Callback) override;
+
+ protected:
+  int addLoadedRowsToCache(const QVariantList &list,
+                           QVariant rowStart) override;
+
+ private:
+  enum Roles { RowNumber = Qt::UserRole + 1, Key, Value };
+
+  void setHashRow(const QByteArray &hashKey, const QByteArray &hashValue,
+                  Callback c, bool updateIfNotExist = true);
+  void deleteHashRow(const QByteArray &hashKey, Callback c);
+};

+ 167 - 0
src/app/models/key-models/keyfactory.cpp

@@ -0,0 +1,167 @@
+#include "keyfactory.h"
+
+#include <qredisclient/redisclient.h>
+#include <qredisclient/utils/text.h>
+
+#include <QFile>
+#include <QObject>
+
+#include "bfkey.h"
+#include "hashkey.h"
+#include "listkey.h"
+#include "rejsonkey.h"
+#include "setkey.h"
+#include "sortedsetkey.h"
+#include "stream.h"
+#include "stringkey.h"
+#include "unknownkey.h"
+
+KeyFactory::KeyFactory() {}
+
+void KeyFactory::loadKey(
+    QSharedPointer<RedisClient::Connection> connection, QByteArray keyFullPath,
+    int dbIndex,
+    std::function<void(QSharedPointer<ValueEditor::Model>, const QString&)>
+        callback) {
+  auto processError = [callback, keyFullPath](const QString& err) {
+    QString msg(QCoreApplication::translate(
+        "RESP", "Cannot load key %1, connection error occurred: %2"));
+    callback(QSharedPointer<ValueEditor::Model>(),
+             msg.arg(printableString(keyFullPath)).arg(err));
+  };
+
+  auto loadModel = [this, connection, keyFullPath, dbIndex, callback,
+                    processError](RedisClient::Response resp) {
+    QSharedPointer<ValueEditor::Model> result;
+
+    if (resp.isErrorMessage() ||
+        resp.type() != RedisClient::Response::Type::Status) {
+      QString msg(QCoreApplication::translate(
+          "RESP", "Cannot load key %1, connection error occurred: %2"));
+      callback(
+          result,
+          msg.arg(printableString(keyFullPath)).arg(resp.value().toString()));
+      return;
+    }
+
+    QString type = resp.value().toString();
+
+    if (type == "none") {
+      QString msg(QCoreApplication::translate(
+          "RESP",
+          "Cannot load key %1 because it doesn't exist in database."
+          " Please reload connection tree and try again."));
+      callback(result, msg.arg(printableString(keyFullPath)));
+      return;
+    }
+
+    auto parseTtl = [this, type, connection, keyFullPath, dbIndex, callback,
+                     processError](const RedisClient::Response& ttlResult) {
+      long long ttl = -1;
+
+      if (ttlResult.type() == RedisClient::Response::Integer) {
+        ttl = ttlResult.value().toLongLong();
+      }
+
+      auto result = createModel(type, connection, keyFullPath, dbIndex, ttl);
+
+      callback(result, QString());
+    };
+
+    connection->cmd({"ttl", keyFullPath}, this, -1, parseTtl, processError);
+  };
+
+  try {
+    connection->cmd({"type", keyFullPath}, this, dbIndex, loadModel,
+                    processError);
+  } catch (const RedisClient::Connection::Exception& e) {
+    callback(QSharedPointer<ValueEditor::Model>(),
+             QCoreApplication::translate("RESP",
+                                         "Cannot retrieve type of the key: ") +
+                 QString(e.what()));
+  }
+}
+
+void KeyFactory::createNewKeyRequest(
+    QSharedPointer<RedisClient::Connection> connection,
+    QSharedPointer<ConnectionsTree::Operations::OpenNewKeyDialogCallback> callback,
+    int dbIndex, QString keyPrefix) {
+  if (connection.isNull() || dbIndex < 0) return;
+  emit newKeyDialog(NewKeyRequest(connection, dbIndex, callback, keyPrefix));
+}
+
+void KeyFactory::submitNewKeyRequest(NewKeyRequest r) {
+  QSharedPointer<ValueEditor::Model> result = createModel(
+      r.keyType(), r.connection(), r.keyName().toUtf8(), r.dbIndex(), -1);
+
+  if (!result) return;
+
+  auto onRowAdded = [this, r, result](const QString& err) {
+    if (err.size() > 0) {
+      emit error(err);
+      return;
+    }
+
+    r.callback();
+    emit keyAdded();
+  };
+
+  r.connection()->cmd(
+      {"PING"}, this, r.dbIndex(),
+      [onRowAdded, result, r](const RedisClient::Response& resp) {
+        auto testResp = resp.value().toByteArray();
+        if (testResp != "PONG") {
+          return onRowAdded(testResp);
+        }
+
+        auto val = r.value();
+
+        if (!r.valueFilePath().isEmpty() && QFile::exists(r.valueFilePath())) {
+          QFile valueFile(r.valueFilePath());
+
+          if (!valueFile.open(QIODevice::ReadOnly)) {
+            return onRowAdded(QCoreApplication::translate(
+                "RESP", "Cannot open file with key value"));
+          }
+
+          val["value"] = valueFile.readAll();
+        }
+
+        result->addRow(val, onRowAdded);
+      },
+      onRowAdded);
+}
+
+QSharedPointer<ValueEditor::Model> KeyFactory::createModel(
+    QString type, QSharedPointer<RedisClient::Connection> connection,
+    QByteArray keyFullPath, int dbIndex, long long ttl) {
+  if (type == "string") {
+    return QSharedPointer<ValueEditor::Model>(
+        new StringKeyModel(connection, keyFullPath, dbIndex, ttl));
+  } else if (type == "list") {
+    return QSharedPointer<ValueEditor::Model>(
+        new ListKeyModel(connection, keyFullPath, dbIndex, ttl));
+  } else if (type == "set") {
+    return QSharedPointer<ValueEditor::Model>(
+        new SetKeyModel(connection, keyFullPath, dbIndex, ttl));
+  } else if (type == "zset") {
+    return QSharedPointer<ValueEditor::Model>(
+        new SortedSetKeyModel(connection, keyFullPath, dbIndex, ttl));
+  } else if (type == "hash") {
+    return QSharedPointer<ValueEditor::Model>(
+        new HashKeyModel(connection, keyFullPath, dbIndex, ttl));
+  } else if (type == "ReJSON-RL" || type == "ReJSON") {
+    return QSharedPointer<ValueEditor::Model>(
+        new ReJSONKeyModel(connection, keyFullPath, dbIndex, ttl));
+  } else if (type == "stream") {
+    return QSharedPointer<ValueEditor::Model>(
+        new StreamKeyModel(connection, keyFullPath, dbIndex, ttl));
+  } else if (type.startsWith("MBbloom")) {
+      QString ff = type.endsWith("CF")? "cf" : "bf";
+      return QSharedPointer<ValueEditor::Model>(
+          new BloomFilterKeyModel(connection, keyFullPath, dbIndex, ttl, ff));
+  }
+
+  return QSharedPointer<ValueEditor::Model>(
+      new UnknownKeyModel(connection, keyFullPath, dbIndex, ttl, type));
+}

+ 37 - 0
src/app/models/key-models/keyfactory.h

@@ -0,0 +1,37 @@
+#pragma once
+#include <QJSValue>
+#include "exception.h"
+#include "modules/value-editor/abstractkeyfactory.h"
+#include "newkeyrequest.h"
+#include "modules/connections-tree/operations.h"
+
+class KeyFactory : public QObject, public ValueEditor::AbstractKeyFactory {
+  Q_OBJECT
+ public:
+  KeyFactory();
+
+  void loadKey(
+      QSharedPointer<RedisClient::Connection> connection,
+      QByteArray keyFullPath, int dbIndex,
+      std::function<void(QSharedPointer<ValueEditor::Model>, const QString&)>
+          callback) override;
+
+ public slots:
+  void createNewKeyRequest(
+      QSharedPointer<RedisClient::Connection> connection,
+      QSharedPointer<ConnectionsTree::Operations::OpenNewKeyDialogCallback>
+          callback,
+      int dbIndex, QString keyPrefix);
+
+  void submitNewKeyRequest(NewKeyRequest r);
+
+ signals:
+  void newKeyDialog(NewKeyRequest r);
+  void keyAdded();
+  void error(const QString& err);
+
+ private:
+  QSharedPointer<ValueEditor::Model> createModel(
+      QString type, QSharedPointer<RedisClient::Connection> connection,
+      QByteArray keyFullPath, int dbIndex, long long ttl);
+};

+ 158 - 0
src/app/models/key-models/listkey.cpp

@@ -0,0 +1,158 @@
+#include "listkey.h"
+#include <qredisclient/connection.h>
+
+const static QByteArray LIST_ITEM_REMOVAL_STUB("---VALUE_REMOVED_BY_RESP_APP---");
+
+ListKeyModel::ListKeyModel(QSharedPointer<RedisClient::Connection> connection,
+                           QByteArray fullPath, int dbIndex, long long ttl)
+    : ListLikeKeyModel(connection, fullPath, dbIndex, ttl, "LLEN", "LRANGE") {}
+
+QString ListKeyModel::type() { return "list"; }
+
+void ListKeyModel::updateRow(int rowIndex, const QVariantMap &row, Callback c) {
+  if (!isRowLoaded(rowIndex) || !isRowValid(row)) {
+    return c(QCoreApplication::translate("RESP", "Invalid row"));
+  }
+
+  int dbRowIndex = rowIndex;
+
+  if (isReverseOrder()) {
+    dbRowIndex = -rowIndex - 1;
+  }
+
+  QByteArray newRow(row["value"].toByteArray());
+
+  auto afterRowUpdate = [this, rowIndex, newRow, c](const QString &err) {
+    if (err.isEmpty()) m_rowsCache.replace(rowIndex, newRow);
+
+    return c(err);
+  };
+
+  verifyListItemPosition(dbRowIndex, [this, dbRowIndex, c, newRow,
+                                       afterRowUpdate](const QString &err) {
+    if (err.size() > 0) return c(err);
+
+    setListRow(dbRowIndex, newRow, afterRowUpdate);
+  });
+}
+
+void ListKeyModel::addRow(const QVariantMap &row, Callback c) {
+  if (!isRowValid(row)) {
+    emit m_notifier->error(QCoreApplication::translate("RESP", "Invalid row"));
+    return;
+  }
+
+  addListRow(row["value"].toByteArray(), [this, c](const QString &err) {
+    if (err.isEmpty()) m_rowCount++;
+
+    return c(err);
+  });
+}
+
+void ListKeyModel::removeRow(int i, ValueEditor::Model::Callback c) {
+  if (!isRowLoaded(i)) return;
+
+  auto onItemRemoval = [this, c, i](const QString &err) {
+    if (err.isEmpty()) {
+      m_rowCount--;
+      m_rowsCache.removeAt(i);
+      setRemovedIfEmpty();
+    };
+
+    return c(err);
+  };
+
+  auto onItemHidding = [this, c, onItemRemoval](const QString &err) {
+    if (err.size() > 0) return c(err);
+
+    // Remove all system values from list
+    deleteListRow(0, LIST_ITEM_REMOVAL_STUB, onItemRemoval);
+  };
+
+  int dbRowIndex = i;
+
+  if (isReverseOrder()) {
+    dbRowIndex = -i - 1;
+  }
+
+  verifyListItemPosition(
+      dbRowIndex, [this, dbRowIndex, c, onItemHidding](const QString &err) {
+        if (err.size() > 0) return c(err);
+
+        // Replace value by system string
+        setListRow(dbRowIndex, LIST_ITEM_REMOVAL_STUB, onItemHidding);
+      });
+}
+
+QList<QByteArray> ListKeyModel::getRangeCmd(QVariant rowStartId, unsigned long count)
+{
+    if (isReverseOrder()) {
+        long rowStart = -rowStartId.toLongLong() - 1;
+        long rowStop = rowStart - count + 1;
+
+        QList<QByteArray> cmd {m_rowsLoadCmd, m_keyFullPath,
+                              QString::number(rowStop).toLatin1(),
+                              QString::number(rowStart).toLatin1()};
+        return cmd;
+    } else {
+        return KeyModel::getRangeCmd(rowStartId, count);
+    }
+}
+
+int ListKeyModel::addLoadedRowsToCache(const QVariantList &rows,
+                                       QVariant rowStartId) {
+  if (isReverseOrder()) {
+    return ListLikeKeyModel::addLoadedRowsToCache(
+        QList<QVariant>(rows.rbegin(), rows.rend()), rowStartId);
+  } else {
+    return ListLikeKeyModel::addLoadedRowsToCache(rows, rowStartId);
+  }
+}
+
+void ListKeyModel::verifyListItemPosition(int row, Callback c) {
+  auto verifyResponse = [this, row](RedisClient::Response r, Callback c) {
+    QVariantList currentState = r.value().toList();        
+    QByteArray cachedValue;
+
+    if (isReverseOrder()) {
+        cachedValue = m_rowsCache[-row - 1];
+    } else {
+        cachedValue = m_rowsCache[row];
+    }
+
+    bool isChanged = currentState.size() != 1 ||
+                     currentState[0].toByteArray() != QString(cachedValue);
+
+    if (isChanged) {
+      return c(QCoreApplication::translate("RESP",
+                                           "The row has been changed on server."
+                                           "Reload and try again."));
+    } else {
+      return c(QString());
+    }
+  };
+
+  executeCmd({"LRANGE", m_keyFullPath, QString::number(row).toLatin1(),
+              QString::number(row).toLatin1()},
+             c, verifyResponse);
+}
+
+void ListKeyModel::addListRow(const QByteArray &value, Callback c) {
+  executeCmd({"LPUSH", m_keyFullPath, value}, c);
+}
+
+void ListKeyModel::setListRow(int pos, const QByteArray &value, Callback c) {
+  executeCmd({"LSET", m_keyFullPath, QString::number(pos).toLatin1(), value},
+             c);
+}
+
+void ListKeyModel::deleteListRow(int count, const QByteArray &value,
+                                 Callback c) {
+  executeCmd({"LREM", m_keyFullPath, QString::number(count).toLatin1(), value},
+             c);
+}
+
+bool ListKeyModel::isReverseOrder() const
+{
+    return m_filters.value("order", "default") == "reverse";
+}

+ 32 - 0
src/app/models/key-models/listkey.h

@@ -0,0 +1,32 @@
+#pragma once
+#include <QByteArray>
+#include "listlikekey.h"
+
+class ListKeyModel : public ListLikeKeyModel {
+ public:
+  ListKeyModel(QSharedPointer<RedisClient::Connection> connection,
+               QByteArray fullPath, int dbIndex, long long ttl);
+
+  QString type() override;  
+
+  void addRow(const QVariantMap &, ValueEditor::Model::Callback c) override;
+  virtual void updateRow(int rowIndex, const QVariantMap &,
+                         ValueEditor::Model::Callback c) override;
+  void removeRow(int, ValueEditor::Model::Callback c) override;
+
+protected:
+  virtual QList<QByteArray> getRangeCmd(QVariant rowStartId,
+                                        unsigned long count) override;
+
+  int addLoadedRowsToCache(const QVariantList& rows,
+                           QVariant rowStart) override;
+
+
+ private:
+  void verifyListItemPosition(int row, Callback c);
+  void addListRow(const QByteArray &value, Callback c);
+  void setListRow(int pos, const QByteArray &value, Callback c);
+  void deleteListRow(int count, const QByteArray &value, Callback c);
+
+  bool isReverseOrder() const;
+};

+ 42 - 0
src/app/models/key-models/listlikekey.cpp

@@ -0,0 +1,42 @@
+#include "listlikekey.h"
+
+ListLikeKeyModel::ListLikeKeyModel(
+    QSharedPointer<RedisClient::Connection> connection, QByteArray fullPath,
+    int dbIndex, long long ttl, QByteArray rowsCountCmd, QByteArray rowsLoadCmd)
+    : KeyModel(connection, fullPath, dbIndex, ttl, rowsCountCmd, rowsLoadCmd) {}
+
+QStringList ListLikeKeyModel::getColumnNames() {
+  return QStringList() << "rowNumber"
+                       << "value";
+}
+
+QHash<int, QByteArray> ListLikeKeyModel::getRoles() {
+  QHash<int, QByteArray> roles;
+  roles[Roles::Value] = "value";
+  roles[Roles::RowNumber] = "rowNumber";
+  return roles;
+}
+
+QVariant ListLikeKeyModel::getData(int rowIndex, int dataRole) {
+  if (!isRowLoaded(rowIndex)) return QVariant();
+
+  switch (dataRole) {
+    case Value:
+      return m_rowsCache[rowIndex];
+    case RowNumber:
+      return rowIndex;
+  }
+
+  return QVariant();
+}
+
+int ListLikeKeyModel::addLoadedRowsToCache(const QVariantList &rows,
+                                           QVariant rowStartId) {
+  QList<QByteArray> result;
+  auto rowStart = rowStartId.toLongLong();
+
+  foreach (QVariant row, rows) { result.push_back(row.toByteArray()); }
+
+  m_rowsCache.addLoadedRange({rowStart, rowStart + result.size() - 1}, result);
+  return result.size();
+}

+ 20 - 0
src/app/models/key-models/listlikekey.h

@@ -0,0 +1,20 @@
+#pragma once
+#include "abstractkey.h"
+
+class ListLikeKeyModel : public KeyModel<QByteArray> {
+ public:
+  ListLikeKeyModel(QSharedPointer<RedisClient::Connection> connection,
+                   QByteArray fullPath, int dbIndex, long long ttl,
+                   QByteArray rowsCountCmd, QByteArray rowsLoadCmd);
+
+  QStringList getColumnNames() override;
+  QHash<int, QByteArray> getRoles() override;
+  QVariant getData(int rowIndex, int dataRole) override;
+
+ protected:
+  enum Roles { RowNumber = Qt::UserRole + 1, Value };
+
+ protected:
+  int addLoadedRowsToCache(const QVariantList& rows,
+                           QVariant rowStart) override;
+};

+ 43 - 0
src/app/models/key-models/newkeyrequest.cpp

@@ -0,0 +1,43 @@
+#include "newkeyrequest.h"
+
+NewKeyRequest::NewKeyRequest(QSharedPointer<RedisClient::Connection> connection, int dbIndex, QSharedPointer<ConnectionsTree::Operations::OpenNewKeyDialogCallback> callback, QString keyPrefix)
+    : m_connection(connection),
+      m_dbIndex(dbIndex),
+      m_callback(callback),
+      m_keyName(keyPrefix),
+      m_valueFilePath(QString()){
+}
+
+void NewKeyRequest::loadAdditionalKeyTypesInfo(QJSValue jsCallback) {
+    if (!m_connection) {
+        qWarning() << "Invalid connection";
+        return;
+    }
+
+    m_jsCallback = jsCallback;
+
+    qDebug() << m_jsCallback.isCallable();
+
+    m_connection->refreshServerInfo([this](){
+        if (!m_jsCallback.isCallable()) {
+            qDebug() << "JS callback is not callable";
+            return;
+        }
+
+        if (!m_connection) {
+            m_jsCallback.call(QJSValueList{});
+            return;
+        }
+
+        auto loadedModules = m_connection->getEnabledModules().keys();
+
+        QJSValueList supportedKeyTypesExposedByModules;
+
+        for (QString mod : loadedModules) {
+            if (mod == "ReJSON")
+                supportedKeyTypesExposedByModules.append(QJSValue(mod));
+        }
+
+        m_jsCallback.call(supportedKeyTypesExposedByModules);
+    });
+}

+ 68 - 0
src/app/models/key-models/newkeyrequest.h

@@ -0,0 +1,68 @@
+#pragma once
+#include <qredisclient/connection.h>
+#include <QObject>
+#include <QSharedPointer>
+#include <functional>
+#include <QJSValue>
+#include "modules/connections-tree/operations.h"
+
+class NewKeyRequest {
+  Q_GADGET
+
+  Q_PROPERTY(QString dbIdString READ dbIdString)
+  Q_PROPERTY(QString keyName READ keyName WRITE setKeyName)
+  Q_PROPERTY(QString keyType READ keyType WRITE setKeyType)
+  Q_PROPERTY(QVariantMap value READ value WRITE setValue)
+  Q_PROPERTY(QString valueFilePath READ valueFilePath WRITE setValueFilePath)  
+
+ public:
+  NewKeyRequest(QSharedPointer<RedisClient::Connection> connection, int dbIndex,
+                QSharedPointer<ConnectionsTree::Operations::OpenNewKeyDialogCallback> callback,
+                QString keyPrefix = QString());
+
+  NewKeyRequest() {}
+
+  QString dbIdString() {
+    return QString("%1:db%2")
+        .arg(m_connection->getConfig().name())
+        .arg(m_dbIndex);
+  }
+
+  int dbIndex() { return m_dbIndex; }
+
+  QString keyName() { return m_keyName; }
+
+  void setKeyName(QString k) { m_keyName = k; }
+
+  QString keyType() { return m_keyType; }
+
+  void setKeyType(QString k) { m_keyType = k; }
+
+  QVariantMap value() const { return m_value; }
+
+  void setValue(const QVariantMap& v) { m_value = v; }
+
+  QString valueFilePath() const { return m_valueFilePath; }
+
+  void setValueFilePath(const QString& path) { m_valueFilePath = path; }
+
+  QSharedPointer<RedisClient::Connection> connection() { return m_connection; }
+
+  void callback() const {
+    if (m_callback) m_callback->call();
+  }
+
+  Q_INVOKABLE void loadAdditionalKeyTypesInfo(QJSValue jsCallback);
+
+ private:
+  QSharedPointer<RedisClient::Connection> m_connection = nullptr;
+  int m_dbIndex = -1;
+  QSharedPointer<ConnectionsTree::Operations::OpenNewKeyDialogCallback> m_callback;
+  QJSValue m_jsCallback;
+  QString m_keyName;
+  QString m_keyType;
+  QVariantMap m_value;
+  QString m_valueFilePath;
+};
+
+Q_DECLARE_METATYPE(NewKeyRequest)

+ 77 - 0
src/app/models/key-models/rejsonkey.cpp

@@ -0,0 +1,77 @@
+#include "rejsonkey.h"
+#include <qredisclient/connection.h>
+
+ReJSONKeyModel::ReJSONKeyModel(
+    QSharedPointer<RedisClient::Connection> connection, QByteArray fullPath,
+    int dbIndex, long long ttl)
+    : KeyModel(connection, fullPath, dbIndex, ttl) {}
+
+QString ReJSONKeyModel::type() { return "ReJSON"; }
+
+QStringList ReJSONKeyModel::getColumnNames() {
+  return QStringList() << "value";
+}
+
+QHash<int, QByteArray> ReJSONKeyModel::getRoles() {
+  QHash<int, QByteArray> roles;
+  roles[Roles::Value] = "value";
+  return roles;
+}
+
+QVariant ReJSONKeyModel::getData(int rowIndex, int dataRole) {
+  if (!isRowLoaded(rowIndex)) return QVariant();
+
+  if (dataRole == Roles::Value) return m_rowsCache[rowIndex];
+
+  return QVariant();
+}
+
+void ReJSONKeyModel::updateRow(int rowIndex, const QVariantMap& row,
+                               Callback c) {
+  if (rowIndex > 0 || !isRowValid(row)) {
+    qDebug() << "Row is not valid";
+    return;
+  }
+
+  QByteArray value = row.value("value").toByteArray();
+
+  if (value.isEmpty()) return;
+
+  auto responseHandler = [this, value](RedisClient::Response r, Callback c) {
+    if (r.isOkMessage()) {
+      m_rowsCache.clear();
+      m_rowsCache.addLoadedRange({0, 0}, (QList<QByteArray>() << value));
+      return c(QString());
+    } else {
+      return c(r.value().toString());
+    }
+  };
+
+  executeCmd({"JSON.SET", m_keyFullPath, ".", value}, c, responseHandler);
+}
+
+void ReJSONKeyModel::addRow(const QVariantMap& row, Callback c) {
+  updateRow(0, row, c);
+}
+
+void ReJSONKeyModel::loadRows(QVariant, unsigned long,
+                              LoadRowsCallback callback) {
+  auto onConnectionError = [callback](const QString& err) {
+    return callback(err, 0);
+  };
+
+  auto responseHandler = [this, callback](RedisClient::Response r, Callback) {
+    m_rowsCache.clear();
+    m_rowsCache.push_back(r.value().toByteArray());
+
+    callback(QString(), 1);
+  };
+
+  executeCmd({"JSON.GET", m_keyFullPath, "noescape"}, onConnectionError, responseHandler,
+             RedisClient::Response::String);
+}
+
+void ReJSONKeyModel::removeRow(int, Callback) {
+  m_rowCount--;
+  setRemovedIfEmpty();
+}

+ 25 - 0
src/app/models/key-models/rejsonkey.h

@@ -0,0 +1,25 @@
+#pragma once
+#include "abstractkey.h"
+
+class ReJSONKeyModel : public KeyModel<QByteArray> {
+ public:
+  ReJSONKeyModel(QSharedPointer<RedisClient::Connection> connection,
+                 QByteArray fullPath, int dbIndex, long long ttl);
+
+  QString type() override;
+  QStringList getColumnNames() override;
+  QHash<int, QByteArray> getRoles() override;
+  QVariant getData(int rowIndex, int dataRole) override;
+
+  void addRow(const QVariantMap&, ValueEditor::Model::Callback c) override;
+  virtual void updateRow(int rowIndex, const QVariantMap& row,
+                         ValueEditor::Model::Callback c) override;
+  void loadRows(QVariant, unsigned long, LoadRowsCallback callback) override;
+  void removeRow(int, ValueEditor::Model::Callback c) override;
+
+ protected:
+  int addLoadedRowsToCache(const QVariantList&, QVariant) override { return 1; }
+
+ private:
+  enum Roles { Value = Qt::UserRole + 1 };
+};

+ 112 - 0
src/app/models/key-models/rowcache.h

@@ -0,0 +1,112 @@
+#pragma once
+#include <QHash>
+#include <QList>
+#include <QPair>
+#include <exception>
+
+typedef qlonglong RowIndex;
+
+class CacheRange : public QPair<RowIndex, RowIndex> {
+ public:
+  CacheRange(const RowIndex& f = -1, const RowIndex& s = -1)
+      : QPair<RowIndex, RowIndex>(f, s) {}
+
+  bool isEmpty() const { return first == -1 && second == -1; }
+};
+
+template <typename T>
+class MappedCache {
+ public:
+  MappedCache() : m_valid(false) {}
+
+  bool isValid() const { return m_valid; }
+
+  void addLoadedRange(const CacheRange& range, const QList<T>& dataForRange) {
+    if (!isValid()) clear();
+
+    m_mapping[range] = dataForRange;
+  }
+
+  bool isRowLoaded(RowIndex index) {
+    CacheRange i = findTargetRange(index);
+    return !i.isEmpty();
+  }
+
+  T getRow(RowIndex index) {
+    if (!isRowLoaded(index)) return T();
+
+    CacheRange i = findTargetRange(index);
+    return m_mapping[i].at(index - i.first);
+  }
+
+  T operator[](RowIndex index) { return getRow(index); }
+
+  void replace(RowIndex index, T row) {
+    if (!isRowLoaded(index)) {
+      throw std::out_of_range("Invalid row");
+    }
+    CacheRange i = findTargetRange(index);
+    return m_mapping[i].replace(index - i.first, row);
+  }
+
+  void removeAt(RowIndex index) {
+    if (!isRowLoaded(index)) {
+      throw std::out_of_range("Invalid row");
+    }
+    CacheRange i = findTargetRange(index);
+
+    m_mapping[i].removeAt(index - i.first);
+    CacheRange newKey{i.first, i.second - 1};
+    replaceRangeInMapping(newKey, i);
+    m_valid = false;
+  }
+
+  void push_back(const T& row) {
+    CacheRange newKey{0, 1};
+
+    if (m_mapping.size() > 0) {
+      newKey.first += m_mapping.lastKey().first;
+      newKey.second += m_mapping.lastKey().second;
+
+      m_mapping.last().push_back(row);
+      replaceRangeInMapping(newKey);
+    } else {
+      m_mapping.insert(newKey, QList<T>{row});
+    }
+  }
+
+  unsigned long long size() const {
+    unsigned long long cacheSize = 0;
+    for (auto cachePage : m_mapping) {
+      cacheSize += cachePage.size();
+    }
+    return cacheSize;
+  }
+
+  void clear() {
+    m_mapping.clear();
+    m_valid = true;
+  }
+
+ private:
+  CacheRange findTargetRange(RowIndex index) {
+    for (auto i = m_mapping.constBegin(); i != m_mapping.constEnd(); ++i) {
+      if (i.key().first <= index && index <= i.key().second) {
+        return i.key();
+      }
+    }
+    return CacheRange();
+  }
+
+  void replaceRangeInMapping(const CacheRange& newRange,
+                             const CacheRange& current = CacheRange()) {
+    CacheRange replaceKey = current.isEmpty() ? m_mapping.lastKey() : current;
+
+    m_mapping[newRange] = m_mapping[replaceKey];
+    m_mapping.remove(replaceKey);
+  }
+
+ private:
+  QMap<CacheRange, QList<T>> m_mapping;
+  bool m_valid;
+};

+ 67 - 0
src/app/models/key-models/setkey.cpp

@@ -0,0 +1,67 @@
+#include "setkey.h"
+#include <qredisclient/connection.h>
+
+SetKeyModel::SetKeyModel(QSharedPointer<RedisClient::Connection> connection,
+                         QByteArray fullPath, int dbIndex, long long ttl)
+    : ListLikeKeyModel(connection, fullPath, dbIndex, ttl, "SCARD", "SSCAN") {}
+
+QString SetKeyModel::type() { return "set"; }
+
+void SetKeyModel::updateRow(int rowIndex, const QVariantMap &row, Callback c) {
+  if (!isRowLoaded(rowIndex) || !isRowValid(row)) {
+    emit m_notifier->error(QCoreApplication::translate("RESP", "Invalid row"));
+    return;
+  }
+
+  QByteArray cachedRow = m_rowsCache[rowIndex];
+  QByteArray newRow(row["value"].toByteArray());
+
+  auto onRowAdded = [this, c, rowIndex, newRow](const QString &err) {
+    if (err.isEmpty()) m_rowsCache.replace(rowIndex, newRow);
+    return c(err);
+  };
+
+  deleteSetRow(cachedRow, [this, c, newRow, onRowAdded](const QString &err) {
+    if (err.size() > 0) return c(err);
+
+    addSetRow(newRow, onRowAdded);
+  });
+}
+
+void SetKeyModel::addRow(const QVariantMap &row, Callback c) {
+  if (!isRowValid(row)) {
+    return c(QCoreApplication::translate("RESP", "Invalid row"));
+  }
+
+  addSetRow(row["value"].toByteArray(), [this, c](const QString &err) {
+    if (err.isEmpty()) {
+      m_rowCount++;
+    }
+
+    return c(err);
+  });
+}
+
+void SetKeyModel::removeRow(int i, Callback c) {
+  if (!isRowLoaded(i)) return;
+
+  QByteArray value = m_rowsCache[i];
+  deleteSetRow(value, [this, c, i](const QString &err) {
+    if (err.isEmpty()) {
+      m_rowCount--;
+      m_rowsCache.removeAt(i);
+
+      setRemovedIfEmpty();
+    }
+
+    return c(err);
+  });
+}
+
+void SetKeyModel::addSetRow(const QByteArray &value, Callback c) {
+  executeCmd({"SADD", m_keyFullPath, value}, c);
+}
+
+void SetKeyModel::deleteSetRow(const QByteArray &value, Callback c) {
+  executeCmd({"SREM", m_keyFullPath, value}, c);
+}

+ 19 - 0
src/app/models/key-models/setkey.h

@@ -0,0 +1,19 @@
+#pragma once
+#include "listlikekey.h"
+
+class SetKeyModel : public ListLikeKeyModel {
+ public:
+  SetKeyModel(QSharedPointer<RedisClient::Connection> connection,
+              QByteArray fullPath, int dbIndex, long long ttl);
+
+  QString type() override;
+
+  void addRow(const QVariantMap &, Callback c) override;
+  virtual void updateRow(int rowIndex, const QVariantMap &,
+                         Callback c) override;
+  void removeRow(int, Callback c) override;
+
+ private:
+  void addSetRow(const QByteArray &value, Callback c);
+  void deleteSetRow(const QByteArray &value, Callback c);
+};

+ 149 - 0
src/app/models/key-models/sortedsetkey.cpp

@@ -0,0 +1,149 @@
+#include "sortedsetkey.h"
+#include <qredisclient/connection.h>
+
+SortedSetKeyModel::SortedSetKeyModel(
+    QSharedPointer<RedisClient::Connection> connection, QByteArray fullPath,
+    int dbIndex, long long ttl)
+    : KeyModel(connection, fullPath, dbIndex, ttl, "ZCARD",
+               "ZRANGE WITHSCORES") {}
+
+QString SortedSetKeyModel::type() { return "zset"; }
+
+QStringList SortedSetKeyModel::getColumnNames() {
+  return QStringList() << "rowNumber"
+                       << "value"
+                       << "score";
+}
+
+QHash<int, QByteArray> SortedSetKeyModel::getRoles() {
+  QHash<int, QByteArray> roles;
+  roles[Roles::RowNumber] = "rowNumber";
+  roles[Roles::Value] = "value";
+  roles[Roles::Score] = "score";
+  return roles;
+}
+
+QVariant SortedSetKeyModel::getData(int rowIndex, int dataRole) {
+  if (!isRowLoaded(rowIndex)) return QVariant();
+
+  QPair<QByteArray, QByteArray> row = m_rowsCache[rowIndex];
+
+  if (dataRole == Roles::Value)
+    return row.first;
+  else if (dataRole == Roles::Score)
+    return row.second.toDouble();
+  else if (dataRole == Roles::RowNumber)
+    return rowIndex;
+
+  return QVariant();
+}
+
+void SortedSetKeyModel::updateRow(int rowIndex, const QVariantMap &row,
+                                  Callback c) {
+  if (!isRowLoaded(rowIndex) || !isRowValid(row)) {
+    emit m_notifier->error(QCoreApplication::translate("RESP", "Invalid row"));
+    return;
+  }
+
+  QPair<QByteArray, QByteArray> cachedRow = m_rowsCache[rowIndex];
+
+  bool valueChanged = cachedRow.first != row["value"].toByteArray();
+  bool scoreChanged = cachedRow.second != row["score"].toByteArray();
+
+  QPair<QByteArray, QByteArray> newRow(
+      (valueChanged) ? row["value"].toByteArray() : cachedRow.first,
+      (scoreChanged) ? row["score"].toByteArray() : cachedRow.second);
+
+  auto onRowAdded = [this, c, rowIndex, newRow](const QString &err) {
+    if (err.isEmpty()) m_rowsCache.replace(rowIndex, newRow);
+
+    return c(err);
+  };
+
+  if (valueChanged) {
+    deleteSortedSetRow(
+        cachedRow.first, [this, c, onRowAdded, newRow](const QString &err) {
+          if (err.size() > 0) return c(err);
+
+          addSortedSetRow(newRow.first, newRow.second, onRowAdded, false);
+        });
+  } else {
+    addSortedSetRow(newRow.first, newRow.second, onRowAdded, true);
+  }
+}
+
+void SortedSetKeyModel::addRow(const QVariantMap &row, Callback c) {
+  if (!isRowValid(row)) {
+    return c(QCoreApplication::translate("RESP", "Invalid row"));
+  }
+
+  auto onAdded = [this, c](const QString &err) {
+    if (err.isEmpty()) m_rowCount++;
+
+    return c(err);
+  };
+
+  addSortedSetRow(row["value"].toByteArray(), row["score"].toByteArray(),
+                  onAdded);
+}
+
+void SortedSetKeyModel::removeRow(int i, Callback c) {
+  if (!isRowLoaded(i)) return;
+
+  QByteArray value = m_rowsCache[i].first;
+
+  executeCmd({"ZREM", m_keyFullPath, value}, [this, c, i](const QString &err) {
+    if (err.isEmpty()) {
+      m_rowCount--;
+      m_rowsCache.removeAt(i);
+      setRemovedIfEmpty();
+    }
+
+    return c(err);
+  });
+}
+
+void SortedSetKeyModel::addSortedSetRow(const QByteArray &value,
+                                        QByteArray score, Callback c,
+                                        bool updateExisting) {
+  QList<QByteArray> cmd;
+
+  if (updateExisting) {
+    cmd = {"ZADD", m_keyFullPath, "XX", score, value};
+  } else {
+    cmd = {"ZADD", m_keyFullPath, score, value};
+  }
+
+  executeCmd(cmd, c, CmdHandler(), RedisClient::Response::Integer);
+}
+
+void SortedSetKeyModel::deleteSortedSetRow(const QByteArray &value,
+                                           Callback c) {
+  executeCmd({"ZREM", m_keyFullPath, value}, c);
+}
+
+int SortedSetKeyModel::addLoadedRowsToCache(const QVariantList &rows,
+                                            QVariant rowStartId) {
+  QList<QPair<QByteArray, QByteArray>> result;
+
+  for (QVariantList::const_iterator item = rows.begin(); item != rows.end();
+       ++item) {
+    QPair<QByteArray, QByteArray> value;
+    value.first = item->toByteArray();
+    ++item;
+
+    if (item == rows.end()) {
+      emit m_notifier->error(QCoreApplication::translate(
+          "RESP", "Data was loaded from server partially."));
+      return 0;
+    }
+
+    value.second = item->toByteArray();
+    result.push_back(value);
+  }
+
+  auto rowStart = rowStartId.toLongLong();
+  m_rowsCache.addLoadedRange({rowStart, rowStart + result.size() - 1}, result);
+
+  return result.size();
+}

+ 28 - 0
src/app/models/key-models/sortedsetkey.h

@@ -0,0 +1,28 @@
+#pragma once
+#include "abstractkey.h"
+
+class SortedSetKeyModel : public KeyModel<QPair<QByteArray, QByteArray>> {
+ public:
+  SortedSetKeyModel(QSharedPointer<RedisClient::Connection> connection,
+                    QByteArray fullPath, int dbIndex, long long ttl);
+
+  QString type() override;
+  QStringList getColumnNames() override;
+  QHash<int, QByteArray> getRoles() override;
+  QVariant getData(int rowIndex, int dataRole) override;
+
+  void addRow(const QVariantMap&, Callback c) override;
+  virtual void updateRow(int rowIndex, const QVariantMap&, Callback c) override;
+  void removeRow(int, Callback c) override;
+
+ protected:
+  int addLoadedRowsToCache(const QVariantList& list,
+                           QVariant rowStart) override;
+
+ private:
+  enum Roles { RowNumber = Qt::UserRole + 1, Value, Score };
+
+  void addSortedSetRow(const QByteArray& value, QByteArray score, Callback c,
+                       bool updateExisting = false);
+  void deleteSortedSetRow(const QByteArray& value, Callback c);
+};

+ 198 - 0
src/app/models/key-models/stream.cpp

@@ -0,0 +1,198 @@
+#include "stream.h"
+#include <QJsonDocument>
+#include <QJsonArray>
+#include <QJsonObject>
+#include <QJsonValue>
+
+#include "app/jsonutils.h"
+
+StreamKeyModel::StreamKeyModel(
+    QSharedPointer<RedisClient::Connection> connection, QByteArray fullPath,
+    int dbIndex, long long ttl)
+    : KeyModel(connection, fullPath, dbIndex, ttl, "XLEN", QByteArray()) {}
+
+QString StreamKeyModel::type() { return "stream"; }
+
+QStringList StreamKeyModel::getColumnNames() {
+  return QStringList() << "rowNumber"
+                       << "id"
+                       << "value";
+}
+
+QHash<int, QByteArray> StreamKeyModel::getRoles() {
+  QHash<int, QByteArray> roles;
+  roles[Roles::RowNumber] = "rowNumber";
+  roles[Roles::ID] = "id";
+  roles[Roles::Value] = "value";
+  return roles;
+}
+
+QVariant StreamKeyModel::getData(int rowIndex, int dataRole) {
+  if (!isRowLoaded(rowIndex)) return QVariant();
+  switch (dataRole) {
+    case Value:
+      return QJsonDocument::fromVariant(m_rowsCache[rowIndex].second)
+          .toJson(QJsonDocument::Compact);
+    case ID:
+      return m_rowsCache[rowIndex].first;
+    case RowNumber:
+      return rowIndex;
+  }
+
+  return QVariant();
+}
+
+void StreamKeyModel::addRow(const QVariantMap &row,
+                            ValueEditor::Model::Callback c) {
+  if (!isRowValid(row)) {
+    c(QCoreApplication::translate("RESP", "Invalid row"));
+    return;
+  }
+
+  QList<QByteArray> cmd = {"XADD", m_keyFullPath, row["id"].toByteArray()};
+
+  QJsonParseError err;
+  QJsonDocument jsonValues =
+      QJsonDocument::fromJson(row["value"].toByteArray(), &err);
+
+  if (err.error != QJsonParseError::NoError || !jsonValues.isObject()) {
+    return c(QCoreApplication::translate("RESP", "Invalid row"));
+  }
+
+  auto valuesObject = jsonValues.object();
+
+  for (auto key : valuesObject.keys()) {
+    cmd.append(key.toUtf8());
+
+    if (valuesObject[key].isArray()) {
+        QJsonDocument d = QJsonDocument(valuesObject[key].toArray());
+        cmd.append(d.toJson(QJsonDocument::Compact));
+    } else if (valuesObject[key].isObject()) {
+        QJsonDocument d = QJsonDocument(valuesObject[key].toObject());
+        cmd.append(d.toJson(QJsonDocument::Compact));
+    } else {
+        cmd.append(valuesObject[key].toVariant().toByteArray());
+    }
+  }
+
+  executeCmd(cmd, c);
+}
+
+void StreamKeyModel::updateRow(int, const QVariantMap &,
+                               ValueEditor::Model::Callback) {
+    //NOTE(u_glide): Redis Streams doesn't support editing (yet?)
+}
+
+void StreamKeyModel::removeRow(int i, ValueEditor::Model::Callback c) {
+  if (!isRowLoaded(i)) return;
+
+  executeCmd({"XDEL", m_keyFullPath, m_rowsCache[i].first}, c);
+}
+
+void StreamKeyModel::loadRowsCount(ValueEditor::Model::Callback c)
+{
+  executeCmd(
+      {"XINFO", "STREAM", m_keyFullPath}, c,
+      [this](RedisClient::Response r, Callback c) {
+        auto info = r.value().toList();
+        auto it = info.begin();
+
+        while (it != info.end()) {
+          if (!it->canConvert(QMetaType::QByteArray)) {
+            continue;
+          }
+
+          QByteArray propertyName = it->toByteArray();
+
+          it++;
+
+          if (it == info.end())
+              break;
+
+          if (propertyName == QByteArray("length")) {
+            m_rowCount = it->toLongLong();
+          } else if (propertyName == QByteArray("first-entry") ||
+                     propertyName == QByteArray("last-entry")) {
+            auto list = it->toList();
+
+            if (list.size() > 0) {
+              m_filters[QString::fromLatin1(propertyName)] = list[0];
+            }
+          }
+
+          it++;
+        }
+
+        c(QString());
+      },
+      RedisClient::Response::Type::Array);
+}
+
+int StreamKeyModel::addLoadedRowsToCache(const QVariantList &rows,
+                                         QVariant rowStartId) {
+  QList<QPair<QByteArray, QVariant>> result;
+
+  for (QVariantList::const_iterator item = rows.begin(); item != rows.end();
+       ++item) {
+    QPair<QByteArray, QVariant> value;
+    auto rowValues = item->toList();
+    value.first = rowValues[0].toByteArray();
+
+    QVariantList valuesList = rowValues[1].toList();
+    QVariantMap mappedVal;
+
+    for (QVariantList::const_iterator valItem = valuesList.begin();
+         valItem != valuesList.end(); ++valItem) {               
+      auto valKey = valItem->toByteArray();
+      valItem++;
+
+      QByteArray fieldValue = valItem->toByteArray();
+
+      if (JSONUtils::isJSON(fieldValue)) {
+        auto doc = QJsonDocument::fromJson(fieldValue);
+
+        if (doc.isObject() || doc.isArray()) {
+            mappedVal[valKey] = doc.toVariant();
+        } else {
+            mappedVal[valKey] = fieldValue;
+        }
+      } else {
+          mappedVal[valKey] = fieldValue;
+      }
+    }
+
+    value.second = mappedVal;
+    result.push_back(value);
+  }
+
+  auto rowStart = rowStartId.toLongLong();
+  m_rowsCache.addLoadedRange({rowStart, rowStart + result.size() - 1}, result);
+
+  return result.size();
+}
+
+QList<QByteArray> StreamKeyModel::getRangeCmd(QVariant rowStartId,
+                                              unsigned long count) {
+  QList<QByteArray> cmd;
+  cmd << "XREVRANGE" << m_keyFullPath;
+
+  if (filter("end").isNull()) {  // end
+    cmd << "+";
+  } else {
+    cmd << QString::number(filter("end").toLongLong()).toLatin1();
+  }
+
+  if (filter("start").isNull()) {  // start
+    unsigned long rowStart = rowStartId.toULongLong();
+
+    if (isRowLoaded(rowStart - 1)) {
+      cmd << m_rowsCache[rowStart - 1].first;
+    } else {
+       cmd << "-";
+    }
+  } else {
+    cmd << QString::number(filter("start").toLongLong()).toLatin1();
+  }
+
+  return cmd << "COUNT" << QString::number(count).toLatin1();
+}

+ 31 - 0
src/app/models/key-models/stream.h

@@ -0,0 +1,31 @@
+#pragma once
+#include "abstractkey.h"
+
+class StreamKeyModel : public KeyModel<QPair<QByteArray, QVariant>> {
+ public:
+  StreamKeyModel(QSharedPointer<RedisClient::Connection> connection,
+                 QByteArray fullPath, int dbIndex, long long ttl);
+
+  QString type() override;
+  QStringList getColumnNames() override;
+  QHash<int, QByteArray> getRoles() override;
+
+  QVariant getData(int rowIndex, int dataRole) override;
+
+  void addRow(const QVariantMap &, Callback) override;
+
+  virtual void updateRow(int rowIndex, const QVariantMap &, Callback) override;
+
+  void removeRow(int, Callback) override;
+
+   void loadRowsCount(ValueEditor::Model::Callback c) override;
+
+ protected:
+  int addLoadedRowsToCache(const QVariantList &list,
+                           QVariant rowStart) override;
+  virtual QList<QByteArray> getRangeCmd(QVariant rowStartId,
+                                        unsigned long count) override;
+
+ protected:
+  enum Roles { RowNumber = Qt::UserRole + 1, ID, Value };
+};

+ 98 - 0
src/app/models/key-models/stringkey.cpp

@@ -0,0 +1,98 @@
+#include "stringkey.h"
+#include <qredisclient/connection.h>
+
+StringKeyModel::StringKeyModel(
+    QSharedPointer<RedisClient::Connection> connection, QByteArray fullPath,
+    int dbIndex, long long ttl)
+    : KeyModel(connection, fullPath, dbIndex, ttl), m_type("string") {}
+
+QString StringKeyModel::type() { return m_type; }
+
+QStringList StringKeyModel::getColumnNames() {
+  return QStringList() << "value";
+}
+
+QHash<int, QByteArray> StringKeyModel::getRoles() {
+  QHash<int, QByteArray> roles;
+  roles[Roles::Value] = "value";
+  return roles;
+}
+
+QVariant StringKeyModel::getData(int rowIndex, int dataRole) {
+  if (rowIndex > 0 || !isRowLoaded(rowIndex)) return QVariant();
+  if (dataRole == Roles::Value) return m_rowsCache[rowIndex];
+
+  return QVariant();
+}
+
+void StringKeyModel::updateRow(int rowIndex, const QVariantMap& row,
+                               Callback c) {
+  if (rowIndex > 0 || !isRowValid(row)) {
+    qDebug() << "Row is not valid";
+    return;
+  }
+
+  QByteArray value = row.value("value").toByteArray();
+
+  executeCmd(
+      {"SET", m_keyFullPath, value}, [this, c, value](const QString& err) {
+        if (err.isEmpty()) {
+          m_rowsCache.clear();
+          m_rowsCache.addLoadedRange({0, 0}, (QList<QByteArray>() << value));
+        }
+
+        return c(err);
+      });
+}
+
+void StringKeyModel::addRow(const QVariantMap& row, Callback c) {
+  if (m_type == "hyperloglog") {
+      QByteArray value = row.value("value").toByteArray();
+
+      executeCmd(
+          {"PFADD", m_keyFullPath, value}, [this, c](const QString& err) {
+            m_rowCount++;
+            return c(err);
+          });
+  } else {
+    updateRow(0, row, c);
+  }
+}
+
+void StringKeyModel::loadRows(QVariant, unsigned long,
+                              LoadRowsCallback callback) {
+  auto onConnectionError = [callback](const QString& err) {
+    return callback(err, 0);
+  };
+
+  auto responseHandler = [this, callback](RedisClient::Response r, Callback) {
+    m_rowsCache.clear();
+
+    QByteArray value = r.value().toByteArray();
+
+    m_rowsCache.push_back(value);
+    m_rowCount = 1;
+
+    // Detect HyperLogLog
+    if (value.startsWith("HYLL")) {
+      executeCmd(
+          {"PFCOUNT", m_keyFullPath}, [callback](const QString&) { callback(QString(), 1); },
+          [this, callback](RedisClient::Response r, Callback) {
+            m_type = "hyperloglog";
+            m_rowCount = r.value().toUInt();
+            callback(QString(), m_rowCount);
+          },
+          RedisClient::Response::Integer);
+    } else {
+      callback(QString(), 1);
+    }
+  };
+
+  executeCmd({"GET", m_keyFullPath}, onConnectionError, responseHandler,
+             RedisClient::Response::String);
+}
+
+void StringKeyModel::removeRow(int, Callback) {
+  m_rowCount--;
+  setRemovedIfEmpty();
+}

+ 31 - 0
src/app/models/key-models/stringkey.h

@@ -0,0 +1,31 @@
+#pragma once
+#include "abstractkey.h"
+
+class StringKeyModel : public KeyModel<QByteArray> {
+ public:
+  StringKeyModel(QSharedPointer<RedisClient::Connection> connection,
+                 QByteArray fullPath, int dbIndex, long long ttl);
+
+  QString type() override;
+  QStringList getColumnNames() override;
+  QHash<int, QByteArray> getRoles() override;
+  QVariant getData(int rowIndex, int dataRole) override;
+
+  void addRow(const QVariantMap&, Callback c) override;
+  virtual void updateRow(int rowIndex, const QVariantMap& row,
+                         Callback c) override;
+  void loadRows(QVariant, unsigned long, LoadRowsCallback callback) override;
+  void removeRow(int, Callback c) override;
+
+  virtual unsigned long rowsCount() override {
+      return m_rowCount;
+  }
+
+ protected:
+  int addLoadedRowsToCache(const QVariantList&, QVariant) override { return 1; }
+
+ private:
+  enum Roles { Value = Qt::UserRole + 1 };
+
+  QString m_type;
+};

+ 7 - 0
src/app/models/key-models/unknownkey.cpp

@@ -0,0 +1,7 @@
+#include "unknownkey.h"
+#include <qredisclient/connection.h>
+
+UnknownKeyModel::UnknownKeyModel(
+    QSharedPointer<RedisClient::Connection> connection, QByteArray fullPath,
+    int dbIndex, long long ttl, QString type)
+    : KeyModel(connection, fullPath, dbIndex, ttl), m_type(type) {}

+ 44 - 0
src/app/models/key-models/unknownkey.h

@@ -0,0 +1,44 @@
+#pragma once
+#include "abstractkey.h"
+
+#define EMPTY_METHOD override {qWarning() << "Operation is not supported";}
+
+class UnknownKeyModel : public KeyModel<QByteArray> {
+ public:
+  UnknownKeyModel(QSharedPointer<RedisClient::Connection> connection,
+                 QByteArray fullPath, int dbIndex, long long ttl, QString type);
+
+  QString type() override { return m_type; }
+
+  QStringList getColumnNames() override {
+      return QStringList() << "";
+  }
+  QHash<int, QByteArray> getRoles() override {
+    return QHash<int, QByteArray>();
+  }
+
+  QVariant getData(int, int) override {return QVariant();}
+
+  void addRow(const QVariantMap&, Callback) EMPTY_METHOD
+
+  virtual void updateRow(int, const QVariantMap&,
+                         Callback) EMPTY_METHOD
+
+  void loadRows(QVariant, unsigned long, LoadRowsCallback callback) override {
+      return callback("unknown-data-type", 0);
+  }
+
+  void removeRow(int, Callback) EMPTY_METHOD
+
+  virtual unsigned long rowsCount() override {
+      return 0;
+  }
+
+ protected:
+  int addLoadedRowsToCache(const QVariantList&, QVariant) override { return 1; }
+
+ private:
+  enum Roles { Value = Qt::UserRole + 1 };
+
+  QString m_type;
+};

+ 559 - 0
src/app/models/treeoperations.cpp

@@ -0,0 +1,559 @@
+#include "treeoperations.h"
+
+#include <asyncfuture.h>
+#include <qredisclient/redisclient.h>
+#include <QRegExp>
+#include <QRegularExpression>
+#include <QRegularExpressionMatchIterator>
+#include <QSet>
+#include <QtConcurrent>
+#include <algorithm>
+
+#include "app/events.h"
+#include "connections-tree/items/serveritem.h"
+#include "connections-tree/items/databaseitem.h"
+#include "connections-tree/items/namespaceitem.h"
+#include "connections-tree/keysrendering.h"
+
+TreeOperations::TreeOperations(const ServerConfig &config,
+    QSharedPointer<Events> events)
+    : m_events(events), m_dbCount(0),
+      m_connectionMode(RedisClient::Connection::Mode::Normal),
+      m_config(config){
+  m_connection = QSharedPointer<RedisClient::Connection>(
+              new RedisClient::Connection(config));
+  m_events->registerLoggerForConnection(*m_connection);
+}
+
+void TreeOperations::loadDatabases(
+    QSharedPointer<RedisClient::Connection> c,
+    QSharedPointer<AsyncFuture::Deferred<void>> d,
+    std::function<void(RedisClient::DatabaseList, const QString&)> callback) {
+  if (!d) return;
+
+  auto connection = c->clone(false);
+  auto connectionWRef = connection.toWeakRef();
+
+  d->onCanceled([connectionWRef]() {
+    QtConcurrent::run([connectionWRef]() {
+      auto connection = connectionWRef.toStrongRef();
+      if (connection) connection->disconnect();
+    });
+  });
+
+  m_events->registerLoggerForConnection(*connection);
+
+  if (!connect(connection)) {
+    return callback(RedisClient::DatabaseList(),
+                    QString("Cannot connect to redis-server"));
+  }
+
+  if (d && d->future().isCanceled()) {
+    return;
+  }
+
+  RedisClient::DatabaseList availableDatabeses = connection->getKeyspaceInfo();
+
+  if (connection->mode() == RedisClient::Connection::Mode::Cluster) {
+    return callback(availableDatabeses, QString());
+  }
+
+  // detect all databases
+  RedisClient::Response scanningResp;
+  int lastDbIndex =
+      (availableDatabeses.size() == 0) ? 0 : availableDatabeses.lastKey() + 1;
+
+  if (m_dbCount > 0) {
+    for (int index = lastDbIndex; index < m_dbCount; index++) {
+      availableDatabeses.insert(index, 0);
+    }
+
+    return callback(availableDatabeses, QString());
+  } else {
+    m_dbCount = lastDbIndex;
+
+    auto collectedDatabases = QSharedPointer<RedisClient::DatabaseList>(
+        new RedisClient::DatabaseList(availableDatabeses));
+
+    recursiveSelectScan(d, connection, collectedDatabases, callback);
+  }
+}
+
+void TreeOperations::recursiveSelectScan(
+    QSharedPointer<AsyncFuture::Deferred<void>> d,
+    QSharedPointer<RedisClient::Connection> c,
+    QSharedPointer<RedisClient::DatabaseList> dbList,
+    std::function<void(RedisClient::DatabaseList, const QString&)> callback) {
+  if (d && d->future().isCanceled()) {
+    return;
+  }
+
+  if (m_dbCount >= m_config.databaseScanLimit() || !c) {
+    return callback(*dbList, QString());
+  }
+
+  auto errHandler = [callback, dbList](const QString& err) {
+    if (dbList && dbList->size() > 0) {
+      callback(*dbList, QString());
+    } else {
+      callback(RedisClient::DatabaseList(), err);
+    }
+  };
+
+  c->cmd(
+      {"select", QString::number(m_dbCount).toLatin1()}, this, -1,
+      [this, dbList, c, callback, d](const RedisClient::Response& scanningResp) {
+        if (d && d->future().isCanceled()) {
+          return;
+        }
+
+        if (!scanningResp.isOkMessage()) {
+          callback(*dbList, QString());
+          return;
+        }
+
+        dbList->insert(m_dbCount, 0);
+        m_dbCount++;
+
+        recursiveSelectScan(d, c, dbList, callback);
+      },
+      errHandler);
+}
+
+bool TreeOperations::connect(QSharedPointer<RedisClient::Connection> c) {
+  if (c->isConnected()) return true;
+
+  try {
+    if (!c->connect(true)) {
+      emit m_events->error(
+          QCoreApplication::translate(
+              "RESP", "Cannot connect to server '%1'. Check log for details.")
+              .arg(m_connection->getConfig().name()));
+      return false;
+    }
+
+    m_connectionMode = c->mode();
+    return true;
+  } catch (const RedisClient::Connection::SSHSupportException& e) {
+      emit m_events->error(
+          QCoreApplication::translate("RESP", "Open Source version of RESP.app <b>doesn't support SSH tunneling</b>.<br /><br /> "
+                                             "To get fully-featured application, please buy subscription on "
+                                             "<a href='https://resp.app/subscriptions'>resp.app</a>. <br/><br />"
+                                             "Every single subscription gives us funds to continue "
+                                             "the development process and provide support to our users. <br />"
+                                             "If you have any questions please feel free to contact us "
+                                             "at <a href='mailto:support@resp.app'>support@resp.app</a> "
+                                             "or join <a href='https://t.me/RedisDesktopManager'>Telegram chat</a>.")
+      );
+      return false;
+  } catch (const RedisClient::Connection::Exception& e) {
+    emit m_events->error(
+        QCoreApplication::translate("RESP", "Connection error: ") +
+        QString(e.what()));
+    return false;
+  }
+}
+
+void TreeOperations::requestBulkOperation(
+    ConnectionsTree::AbstractNamespaceItem& ns,
+    BulkOperations::Manager::Operation op,
+    BulkOperations::AbstractOperation::OperationCallback callback) {
+  QString pattern =
+      QString("%1%2*")
+          .arg(QString::fromUtf8(ns.getFullPath()))
+          .arg(ns.getFullPath().size() > 0 ? m_config.namespaceSeparator()
+                                           : "");
+  QRegExp filter(pattern, Qt::CaseSensitive, QRegExp::Wildcard);
+
+  auto dbIndex = ns.getDbIndex();
+
+  getReadyConnection([this, dbIndex, filter, op,
+                      callback](QSharedPointer<RedisClient::Connection> c) {
+    // NOTE(u_glide): Use "clean" connection wihout logger here for better
+    // performance
+    emit m_events->requestBulkOperation(c->clone(), dbIndex, op, filter,
+                                        callback);
+  });
+}
+
+void TreeOperations::getReadyConnection(TreeOperations::PendingOperation callback)
+{
+    if (m_config.askForSshPassword() && m_config.sshPassword().isEmpty()) {
+        m_pendingOperation = callback;
+        m_config.setOwner(sharedFromThis().toWeakRef());
+        emit secretRequired(m_config, ServerConfig::SSH_SECRET_ID);
+    } else {
+        return callback(m_connection);
+    }
+}
+
+QFuture<void> TreeOperations::getDatabases(
+    QSharedPointer<GetDatabasesCallback> callback) {
+  m_dbScanOp = QSharedPointer<AsyncFuture::Deferred<void>>(
+      new AsyncFuture::Deferred<void>());
+
+  getReadyConnection(
+      [this, callback](QSharedPointer<RedisClient::Connection> c) {
+        QtConcurrent::run(this, &TreeOperations::loadDatabases, c, m_dbScanOp,
+                          [callback](RedisClient::DatabaseList dbs, const QString& err){
+            callback->call(dbs, err);
+        });
+      });
+
+  return m_dbScanOp->future();
+}
+
+void TreeOperations::loadNamespaceItems(
+    uint dbIndex, const QString& filter,
+    QSharedPointer<LoadNamespaceItemsCallback> callback) {
+  QString keyPattern = filter.isEmpty() ? m_config.keysPattern() : filter;
+
+  if (m_filterHistory.contains(keyPattern)) {
+    m_filterHistory[keyPattern] = m_filterHistory[keyPattern].toInt() + 1;
+  } else {
+    m_filterHistory[keyPattern] = 1;
+  }
+  m_config.setFilterHistory(m_filterHistory);
+  emit filterHistoryUpdated();
+
+  QSettings settings;
+  qlonglong scanLimit = settings.value("app/scanLimit", DEFAULT_SCAN_LIMIT).toLongLong();
+
+  getReadyConnection([this, dbIndex, filter, callback,
+                      keyPattern, scanLimit](QSharedPointer<RedisClient::Connection> c) {
+    if (!connect(c)) return;
+
+    auto processErr = [callback](const QString& err) {
+      return callback->call(
+          RedisClient::Connection::RawKeysList(),
+          QCoreApplication::translate("RESP", "Cannot load keys: %1").arg(err));
+    };
+
+    auto callbackWrapper = [callback](const RedisClient::Connection::RawKeysList &keys,
+        const QString &err) {
+      return callback->call(keys, err);
+    };
+
+    try {
+      if (m_connection->mode() == RedisClient::Connection::Mode::Cluster) {
+        m_connection->getClusterKeys(callbackWrapper, keyPattern, scanLimit);
+      } else {
+        m_connection->cmd(
+            {"ping"}, this, dbIndex,
+            [this, callbackWrapper, keyPattern,
+             processErr, scanLimit](const RedisClient::Response& r) {
+              if (r.isErrorMessage()) {
+                return processErr(r.value().toString());
+              }
+              m_connection->getDatabaseKeys(callbackWrapper, keyPattern, -1, scanLimit);
+            },
+            [processErr](const QString& err) { return processErr(err); });
+      }
+
+    } catch (const RedisClient::Connection::Exception& error) {
+      processErr(error.what());
+    }
+  });
+}
+
+void TreeOperations::disconnect() { m_connection->disconnect(); }
+
+void TreeOperations::resetConnection() {
+  auto oldConnection = m_connection;
+  setConnection(oldConnection->clone());
+
+  QtConcurrent::run([oldConnection]() { oldConnection->disconnect(); });
+}
+
+QString TreeOperations::getNamespaceSeparator() {
+  return m_config.namespaceSeparator();
+}
+
+QString TreeOperations::defaultFilter() { return m_config.keysPattern(); }
+
+QVariantMap TreeOperations::getFilterHistory() {
+    m_filterHistory = m_config.filterHistory();
+    return m_filterHistory;
+}
+
+QString TreeOperations::connectionName() const {
+    return m_config.name();
+}
+
+void TreeOperations::openKeyTab(QSharedPointer<ConnectionsTree::KeyItem> key,
+                                bool openInNewTab) {
+  getReadyConnection(
+      [this, key, openInNewTab](QSharedPointer<RedisClient::Connection> c) {
+        emit m_events->openValueTab(c, key, openInNewTab);
+      });
+}
+
+void TreeOperations::openConsoleTab(int dbIndex) {
+  getReadyConnection(
+      [this, dbIndex](QSharedPointer<RedisClient::Connection> c) {
+        emit m_events->openConsole(c, dbIndex, true);
+      });
+}
+
+void TreeOperations::openNewKeyDialog(int dbIndex,
+                                      QSharedPointer<OpenNewKeyDialogCallback> callback,
+                                      QString keyPrefix) {
+  getReadyConnection([this, dbIndex, callback,
+                      keyPrefix](QSharedPointer<RedisClient::Connection> c) {
+    emit m_events->newKeyDialog(c, callback, dbIndex, keyPrefix);
+  });
+}
+
+void TreeOperations::openServerStats() {
+  getReadyConnection([this](QSharedPointer<RedisClient::Connection> c) {
+    emit m_events->openServerStats(c);
+  });
+}
+
+void TreeOperations::duplicateConnection() {
+  emit createNewConnection(m_config);
+}
+
+void TreeOperations::notifyDbWasUnloaded(int dbIndex) {
+  emit m_events->closeDbKeys(m_connection, dbIndex);
+}
+
+void TreeOperations::deleteDbKey(ConnectionsTree::KeyItem& key,
+                                 QSharedPointer<DeleteDbKeyCallback> callback) {
+  getReadyConnection(
+      [this, &key, callback](QSharedPointer<RedisClient::Connection> c) {
+        c->cmd(
+            {"DEL", key.getFullPath()}, this, key.getDbIndex(),
+            [this, &key](RedisClient::Response) {
+              key.setRemoved();
+              QRegExp filter(key.getFullPath(), Qt::CaseSensitive,
+                             QRegExp::Wildcard);
+              if (m_events)
+                m_events->closeDbKeys(m_connection, key.getDbIndex(), filter);
+            },
+            [this, callback](const QString& err) {
+              QString errorMsg =
+                  QCoreApplication::translate("RESP", "Delete key error: %1")
+                      .arg(err);
+              callback->call(errorMsg);
+              if (m_events) m_events->error(errorMsg);
+            });
+      });
+}
+
+void TreeOperations::deleteDbKeys(ConnectionsTree::DatabaseItem& db) {
+  auto self = sharedFromThis().toWeakRef();
+  requestBulkOperation(
+      db, BulkOperations::Manager::Operation::DELETE_KEYS,
+      [self, this, &db](QRegExp filter, int, const QStringList&) {
+        if (!self) {
+          return;
+        }
+        uint dbIndex = db.getDbIndex();
+        db.reload();
+
+        if (m_events && m_connection) {
+          getReadyConnection(
+              [this, dbIndex, filter](QSharedPointer<RedisClient::Connection> c) {
+                emit m_events->closeDbKeys(c, dbIndex, filter);
+              });
+        }
+      });
+}
+
+void TreeOperations::deleteDbNamespace(ConnectionsTree::NamespaceItem& ns) {
+  auto self = sharedFromThis().toWeakRef();
+  requestBulkOperation(
+      ns, BulkOperations::Manager::Operation::DELETE_KEYS,
+      [this, self, &ns](QRegExp filter, int, const QStringList&) {
+        if (!self) {
+          return;
+        }
+        uint dbIndex = ns.getDbIndex();
+        ns.setRemoved();
+
+        if (m_events && m_connection) {
+          getReadyConnection(
+              [this, dbIndex, filter](QSharedPointer<RedisClient::Connection> c) {
+                emit m_events->closeDbKeys(c, dbIndex, filter);
+              });
+        }
+      });
+}
+
+void TreeOperations::setTTL(ConnectionsTree::AbstractNamespaceItem& ns) {
+  requestBulkOperation(ns, BulkOperations::Manager::Operation::TTL,
+                       [](QRegExp, int, const QStringList&) {});
+}
+
+void TreeOperations::copyKeys(ConnectionsTree::AbstractNamespaceItem& ns) {
+  requestBulkOperation(ns, BulkOperations::Manager::Operation::COPY_KEYS,
+                       [](QRegExp, int, const QStringList&) {});
+}
+
+void TreeOperations::importKeysFromRdb(ConnectionsTree::DatabaseItem& db) {
+  getReadyConnection([this, &db](QSharedPointer<RedisClient::Connection> c) {
+    emit m_events->requestBulkOperation(
+        c->clone(), db.getDbIndex(),
+        BulkOperations::Manager::Operation::IMPORT_RDB_KEYS, QRegExp(".*"),
+        [&db](QRegExp, int, const QStringList&) { db.reload(); });
+  });
+}
+
+void TreeOperations::flushDb(int dbIndex,
+                             QSharedPointer<FlushDbCallback> callback) {
+
+  auto callbackWrapper = [callback](const QString &err) {
+    callback->call(err);
+  };
+
+  getReadyConnection(
+      [dbIndex, callbackWrapper](QSharedPointer<RedisClient::Connection> c) {
+        try {
+          c->flushDbKeys(dbIndex, callbackWrapper);
+        } catch (const RedisClient::Connection::Exception& e) {
+          throw ConnectionsTree::Operations::Exception(
+              QCoreApplication::translate("RESP", "Cannot flush database: ") +
+              QString(e.what()));
+        }
+      });
+}
+
+QFuture<bool> TreeOperations::connectionSupportsMemoryOperations() {
+    return m_connection->isCommandSupported({"MEMORY", "HELP"});
+}
+
+void TreeOperations::openKeyIfExists(const QByteArray& fullPath,
+    QSharedPointer<ConnectionsTree::DatabaseItem> parent,
+    QSharedPointer<OpenKeyIfExistsCallback> callback) {
+  if (!parent) {
+    qWarning() << "TreeOperations::openKeyIfExists > Invalid parent";
+    return;
+  }
+
+  getReadyConnection([this, fullPath, parent,
+                      callback](QSharedPointer<RedisClient::Connection> c) {
+    c->cmd(
+        {"exists", fullPath}, this, static_cast<int>(parent->getDbIndex()),
+        [this, parent, fullPath, callback](RedisClient::Response r) {
+          QVariant result = r.value();
+
+          if (result.toByteArray() == "1") {
+            auto key = QSharedPointer<ConnectionsTree::KeyItem>(
+                new ConnectionsTree::KeyItem(fullPath, parent.toWeakRef(),
+                                             parent->model(),
+                                             parent->keysShortNameRendering()));
+
+            emit m_events->openValueTab(m_connection, key, true);
+
+            callback->call(QString(), true);
+          } else {
+            callback->call(QString(), false);
+          }
+        },
+        [callback](const QString& err) { callback->call(err, false); });
+  });
+}
+
+void TreeOperations::getUsedMemory(const QList<QByteArray>& keys, int dbIndex,
+                                   QSharedPointer<GetUsedMemoryCallback> result,
+                                   QSharedPointer<GetUsedMemoryCallback> progress) {
+  QList<QList<QByteArray>> commands;
+
+  for (int index = 0; index < keys.size(); ++index) {
+    commands.append({"MEMORY", "USAGE", keys[index]});
+  }
+
+  int expectedResponses = commands.size();
+  auto processedResponses = QSharedPointer<int>(new int(0));
+  auto totalMemory = QSharedPointer<qlonglong>(new qlonglong(0));
+
+  m_connection->pipelinedCmd(
+      commands, this, dbIndex,
+      [this, expectedResponses, processedResponses, totalMemory, progress,
+       result](RedisClient::Response r, QString err) {
+        if (!err.isEmpty()) {
+          QString errorMsg =
+              QCoreApplication::translate(
+                  "RESP", "Cannot determine amount of used memory by key: %1")
+                  .arg(err);
+          m_events->error(errorMsg);          
+        } else {
+          QVariant incrResult = r.value();
+
+          if (incrResult.canConvert(QVariant::LongLong)) {
+            (*totalMemory) += incrResult.toLongLong();
+            (*processedResponses)++;
+          } else if (incrResult.canConvert(QVariant::List)) {
+            auto responses = incrResult.toList();
+
+            for (auto resp : responses) {
+              (*totalMemory) += resp.toLongLong();
+              (*processedResponses)++;
+            }
+          }
+
+          if (progress)
+            progress->call(*totalMemory);
+
+          if ((*processedResponses) >= expectedResponses && result) {
+            result->call(*totalMemory);
+          }
+        }
+      }, true);
+}
+
+QString TreeOperations::mode() {
+  if (m_connectionMode == RedisClient::Connection::Mode::Cluster) {
+    return QString("cluster");
+  } else if (m_connectionMode == RedisClient::Connection::Mode::Sentinel) {
+    return QString("sentinel");
+  } else {
+    return QString("standalone");
+  }
+}
+
+bool TreeOperations::isConnected() const { return m_connection->isConnected(); }
+
+QSharedPointer<RedisClient::Connection> TreeOperations::connection()
+{
+    return m_connection;
+}
+
+void TreeOperations::setConnection(QSharedPointer<RedisClient::Connection> c) {
+  m_connection = c;
+  m_events->registerLoggerForConnection(*c);
+}
+
+ServerConfig TreeOperations::config()
+{
+    m_config.setOwner(sharedFromThis().toWeakRef());
+    return m_config;
+}
+
+void TreeOperations::setConfig(const ServerConfig &c)
+{
+    m_config = c;
+    m_config.setOwner(sharedFromThis().toWeakRef());
+    m_connection->setConnectionConfig(m_config);
+    emit configUpdated();
+}
+
+void TreeOperations::proceedWithSecret(const ServerConfig &c)
+{
+    m_config = c;
+    m_config.setOwner(sharedFromThis().toWeakRef());
+    m_connection->setConnectionConfig(m_config);
+
+    if (m_pendingOperation) {
+        m_pendingOperation(m_connection);
+    } else {
+        qWarning() << "Unknown proceedWithSecret request";
+        return;
+    }
+}
+
+QString TreeOperations::iconColor()
+{
+    return m_config.iconColor();
+}

+ 147 - 0
src/app/models/treeoperations.h

@@ -0,0 +1,147 @@
+#pragma once
+#include <QEnableSharedFromThis>
+#include <QObject>
+#include <QSharedPointer>
+#include <functional>
+
+#include "app/models/connectionconf.h"
+#include "connections-tree/items/keyitem.h"
+#include "modules/bulk-operations/bulkoperationsmanager.h"
+#include "modules/connections-tree/operations.h"
+
+class Events;
+
+namespace ConnectionsTree {
+class ServerItem;
+class TreeItem;
+}  // namespace ConnectionsTree
+
+class TreeOperations : public QObject,
+                       public ConnectionsTree::Operations,
+                       public QEnableSharedFromThis<TreeOperations> {
+  Q_OBJECT
+ public:
+  TreeOperations(const ServerConfig& config, QSharedPointer<Events> events);
+
+  QFuture<void> getDatabases(
+      QSharedPointer<GetDatabasesCallback> callback) override;
+
+  void loadNamespaceItems(
+      uint dbIndex, const QString& filter,
+      QSharedPointer<LoadNamespaceItemsCallback> callback)
+      override;
+
+  void disconnect() override;
+
+  void resetConnection() override;
+
+  QString getNamespaceSeparator() override;
+
+  QString defaultFilter() override;
+
+  QVariantMap getFilterHistory() override;
+
+  QString connectionName() const override;
+
+  void openKeyTab(QSharedPointer<ConnectionsTree::KeyItem> key,
+                  bool openInNewTab = false) override;
+
+  void openConsoleTab(int dbIndex = 0) override;
+
+  void openNewKeyDialog(int dbIndex,
+                        QSharedPointer<OpenNewKeyDialogCallback> callback,
+                        QString keyPrefix = QString()) override;
+
+  void openServerStats() override;
+
+  void duplicateConnection() override;
+
+  void notifyDbWasUnloaded(int dbIndex) override;
+
+  void deleteDbKey(ConnectionsTree::KeyItem& key,
+                   QSharedPointer<DeleteDbKeyCallback> callback) override;
+
+  virtual void deleteDbKeys(ConnectionsTree::DatabaseItem& db) override;
+
+  void deleteDbNamespace(ConnectionsTree::NamespaceItem& ns) override;
+
+  virtual void setTTL(ConnectionsTree::AbstractNamespaceItem& ns) override;
+
+  virtual void copyKeys(ConnectionsTree::AbstractNamespaceItem& ns) override;
+
+  virtual void importKeysFromRdb(ConnectionsTree::DatabaseItem& ns) override;
+
+  virtual void flushDb(int dbIndex,
+                       QSharedPointer<FlushDbCallback> callback) override;
+
+  virtual QFuture<bool> connectionSupportsMemoryOperations() override;
+
+  virtual void openKeyIfExists(
+      const QByteArray& key,
+      QSharedPointer<ConnectionsTree::DatabaseItem> parent,
+      QSharedPointer<OpenKeyIfExistsCallback> callback) override;
+
+  virtual void getUsedMemory(const QList<QByteArray>& keys, int dbIndex,
+                             QSharedPointer<GetUsedMemoryCallback> result,
+                             QSharedPointer<GetUsedMemoryCallback> progress) override;
+
+  virtual QString mode() override;
+
+  virtual bool isConnected() const override;
+
+  QSharedPointer<RedisClient::Connection> connection();
+
+  void setConnection(QSharedPointer<RedisClient::Connection> c);
+
+  ServerConfig config();
+
+  void setConfig(const ServerConfig& c);
+
+  void proceedWithSecret(const ServerConfig& c);
+
+  QString iconColor() override;
+
+signals:
+  void createNewConnection(const ServerConfig& config);
+
+  void configUpdated();
+
+  void filterHistoryUpdated();
+
+  void secretRequired(const ServerConfig& config, const QString& id);
+
+ protected:
+  void loadDatabases(
+      QSharedPointer<RedisClient::Connection> c,
+      QSharedPointer<AsyncFuture::Deferred<void>> d,
+      std::function<void(RedisClient::DatabaseList, const QString&)> callback);
+
+  void recursiveSelectScan(
+      QSharedPointer<AsyncFuture::Deferred<void>> d,
+      QSharedPointer<RedisClient::Connection> c,
+      QSharedPointer<RedisClient::DatabaseList> dbList,
+      std::function<void(RedisClient::DatabaseList, const QString&)> callback);
+
+  bool connect(QSharedPointer<RedisClient::Connection> c);
+
+  void requestBulkOperation(
+      ConnectionsTree::AbstractNamespaceItem& ns,
+      BulkOperations::Manager::Operation op,
+      BulkOperations::AbstractOperation::OperationCallback callback);
+
+ private:
+  typedef std::function<void(QSharedPointer<RedisClient::Connection>)>
+      PendingOperation;
+  void getReadyConnection(PendingOperation callback);
+
+ private:
+  QSharedPointer<RedisClient::Connection> m_connection;
+  QSharedPointer<Events> m_events;
+  uint m_dbCount;
+  RedisClient::Connection::Mode m_connectionMode;
+  ServerConfig m_config;
+  QVariantMap m_filterHistory;
+  QWeakPointer<ConnectionsTree::ServerItem> m_serverItem;
+  QSharedPointer<AsyncFuture::Deferred<void>> m_dbScanOp;
+  PendingOperation m_pendingOperation;
+};

+ 635 - 0
src/app/qcompress.cpp

@@ -0,0 +1,635 @@
+#include "qcompress.h"
+
+#include <brotli/decode.h>
+#include <brotli/encode.h>
+#include <lz4.h>
+#include <lz4frame.h>
+#include <snappy.h>
+#include <zlib.h>
+#include <zstd.h>
+
+#include <QDebug>
+
+#define ZLIB_WINDOW_BIT 15 + 16
+#define ZLIB_PHP_WINDOW_BIT 15
+#define ZLIB_CHUNK_SIZE 32 * 1024
+#define ZLIB_LEVEL 6
+
+#define ZSTD_LEVEL 1
+
+#define BROTLI_BUFFER_SIZE 32 * 1024
+
+struct LZ4FCleanUp {
+  static inline void cleanup(LZ4F_dctx *p) { LZ4F_freeDecompressionContext(p); }
+};
+
+struct ZSTDCleanUp {
+  static inline void cleanup(ZSTD_DCtx *p) { ZSTD_freeDCtx(p); }
+};
+
+QByteArray gzipDecode(const QByteArray &val, int windowBits) {
+  z_stream strm;
+  strm.zalloc = Z_NULL;
+  strm.zfree = Z_NULL;
+  strm.opaque = Z_NULL;
+  strm.avail_in = 0;
+  strm.next_in = Z_NULL;
+  QByteArray output;
+
+  int ret = inflateInit2(&strm, windowBits);
+
+  if (ret != Z_OK) return QByteArray();
+
+  const char *input_data = val.data();
+  int input_data_left = val.length();
+
+  do {
+    int chunk_size = qMin(ZLIB_CHUNK_SIZE, input_data_left);
+
+    if (chunk_size <= 0) break;
+
+    strm.next_in = (unsigned char *)input_data;
+    strm.avail_in = chunk_size;
+
+    input_data += chunk_size;
+    input_data_left -= chunk_size;
+
+    do {
+      char out[ZLIB_CHUNK_SIZE];
+
+      strm.next_out = (unsigned char *)out;
+      strm.avail_out = ZLIB_CHUNK_SIZE;
+
+      ret = inflate(&strm, Z_NO_FLUSH);
+
+      switch (ret) {
+        case Z_NEED_DICT:
+          ret = Z_DATA_ERROR;
+        case Z_DATA_ERROR:
+        case Z_MEM_ERROR:
+        case Z_STREAM_ERROR:
+          inflateEnd(&strm);
+          return QByteArray();
+      }
+
+      int have = (ZLIB_CHUNK_SIZE - strm.avail_out);
+
+      if (have > 0) output.append((char *)out, have);
+    } while (strm.avail_out == 0);
+  } while (ret != Z_STREAM_END);
+
+  inflateEnd(&strm);
+
+  if (ret == Z_STREAM_END) {
+    return output;
+  } else {
+    return QByteArray();
+  }
+}
+
+QByteArray lz4RawDecode(const QByteArray &val) {
+  int offset = sizeof(int);
+
+  if (val.size() < offset) {
+    return QByteArray();
+  }
+
+  int dataSize;
+  memcpy(&dataSize, val.data(), offset);
+
+  QByteArray dst(dataSize, '\x00');
+
+  auto res = LZ4_decompress_safe(val.constData() + offset, dst.data(),
+                                 val.size() - offset, dst.capacity());
+
+  if (res < 0) {
+    qWarning() << "LZ4 raw decoding error";
+    return QByteArray();
+  }
+
+  return dst;
+}
+
+QByteArray lz4RawEncode(const QByteArray &val) {
+  int maxSize = LZ4_compressBound(val.size());
+
+  QByteArray dst(maxSize, '\x00');
+
+  int res = LZ4_compress_default(val.constData(), dst.data(), val.size(),
+                                 dst.capacity());
+
+  if (res == 0) {
+    qWarning() << "LZ4 raw decoding error";
+    return QByteArray();
+  }
+
+  return dst;
+}
+
+QByteArray lz4FrameDecode(const QByteArray &val) {
+  LZ4F_dctx *lz4_dctx = nullptr;
+  LZ4F_createDecompressionContext(&lz4_dctx, LZ4F_VERSION);
+
+  if (!lz4_dctx) {
+    qWarning() << "LZ4 error. Cannot initialize context";
+    return QByteArray();
+  }
+
+  QScopedPointer<LZ4F_dctx, LZ4FCleanUp> dctx(lz4_dctx);
+
+  LZ4F_frameInfo_t lz4_frameinfo;
+  size_t buffSize = val.size();
+
+  size_t res = LZ4F_getFrameInfo(dctx.data(), &lz4_frameinfo,
+                                 static_cast<const void *>(val.constData()),
+                                 static_cast<size_t *>(&buffSize));
+
+  if (LZ4F_isError(res)) {
+    qWarning() << "LZ4 error. Cannot retrive frame info";
+    return QByteArray();
+  }
+
+  size_t contentSize = lz4_frameinfo.contentSize;
+  size_t srcSize = val.size();
+
+  if (!(0 < contentSize && contentSize <= 255 * srcSize)) {
+    return QByteArray();
+  }
+
+  QByteArray dst(contentSize, '\x00');
+  size_t dstSize = dst.size();
+
+  static constexpr const LZ4F_decompressOptions_t opt{};
+
+  res = LZ4F_decompress(dctx.data(), dst.data(), &dstSize,
+                        val.data() + buffSize, &srcSize, &opt);
+
+  if (LZ4F_isError(res)) {
+    qWarning() << "LZ4 error. Cannot decode frame" << LZ4F_getErrorName(res);
+    return QByteArray();
+  }
+
+  return dst;
+}
+
+QByteArray gzipEncode(const QByteArray &val, int windowBits) {
+  int flush = 0;
+
+  z_stream strm;
+  strm.zalloc = Z_NULL;
+  strm.zfree = Z_NULL;
+  strm.opaque = Z_NULL;
+  strm.avail_in = 0;
+  strm.next_in = Z_NULL;
+  QByteArray output;
+
+  int ret = deflateInit2(&strm, qMax(-1, qMin(9, ZLIB_LEVEL)), Z_DEFLATED,
+                         windowBits, 8, Z_DEFAULT_STRATEGY);
+
+  if (ret != Z_OK) return output;
+
+  const char *input_data = val.data();
+  int input_data_left = val.length();
+
+  do {
+    int chunk_size = qMin(ZLIB_CHUNK_SIZE, input_data_left);
+
+    strm.next_in = (unsigned char *)input_data;
+    strm.avail_in = chunk_size;
+
+    input_data += chunk_size;
+    input_data_left -= chunk_size;
+
+    flush = (input_data_left <= 0 ? Z_FINISH : Z_NO_FLUSH);
+
+    do {
+      char out[ZLIB_CHUNK_SIZE];
+
+      strm.next_out = (unsigned char *)out;
+      strm.avail_out = ZLIB_CHUNK_SIZE;
+
+      ret = deflate(&strm, flush);
+
+      if (ret == Z_STREAM_ERROR) {
+        deflateEnd(&strm);
+        return QByteArray();
+      }
+
+      int have = (ZLIB_CHUNK_SIZE - strm.avail_out);
+
+      if (have > 0) output.append((char *)out, have);
+    } while (strm.avail_out == 0);
+  } while (flush != Z_FINISH);
+
+  (void)deflateEnd(&strm);
+
+  if (ret == Z_STREAM_END) {
+    return output;
+  } else {
+    return QByteArray();
+  }
+}
+
+QByteArray lz4FrameEncode(const QByteArray &val) {
+  QByteArray dst;
+  LZ4F_preferences_t opt{};
+  opt.frameInfo.contentSize = val.size();
+  size_t expectedSize = LZ4F_compressFrameBound(val.size(), &opt);
+  dst.resize(expectedSize);
+
+  size_t res =
+      LZ4F_compressFrame(dst.data(), dst.size(), val.data(), val.size(), &opt);
+
+  if (LZ4F_isError(res)) {
+    qWarning() << "LZ4 error. Cannot compress frame" << LZ4F_getErrorName(res);
+    return QByteArray();
+  }
+
+  if (expectedSize > res) {
+      dst.resize(res);
+  }
+
+  return dst;
+}
+
+QByteArray zstdDecode(const QByteArray &val) {
+  size_t buffSize = val.size();
+  auto decompressedSize = ZSTD_getFrameContentSize(
+      static_cast<const void *>(val.constData()), buffSize);
+
+  if (decompressedSize == 0UL || decompressedSize == ZSTD_CONTENTSIZE_ERROR) {
+    return QByteArray();
+  }
+
+  size_t srcSize = val.size();  
+
+  ZSTD_DCtx *const zstd_dctx = ZSTD_createDCtx();
+
+  if (!zstd_dctx) {
+    qWarning() << "ZSTD error. Cannot initialize context";
+    return QByteArray();
+  }
+
+  QScopedPointer<ZSTD_DCtx, ZSTDCleanUp> dctx(zstd_dctx);
+
+  QByteArray dst(decompressedSize, '\x00');
+  size_t dstSize = dst.size();
+
+  size_t const res =
+      ZSTD_decompress(static_cast<void *>(dst.data()), dstSize,
+                      static_cast<const void *>(val.data()), srcSize);
+
+  if (ZSTD_isError(res)) {
+    qWarning() << "ZSTD error. Cannot decode frame" << ZSTD_getErrorName(res);
+    return QByteArray();
+  }
+
+  dst.resize(res);
+
+  return dst;
+}
+
+QByteArray zstdEncode(const QByteArray &val) {
+  QByteArray dst;
+  dst.resize(ZSTD_compressBound(val.size()));
+
+  size_t res =
+      ZSTD_compress(dst.data(), dst.size(), val.data(), val.size(), ZSTD_LEVEL);
+
+  if (ZSTD_isError(res)) {
+    qWarning() << "ZSTD error. Cannot compress frame" << ZSTD_getErrorName(res);
+    return QByteArray();
+  }
+
+  dst.resize(res);
+
+  return dst;
+}
+
+QByteArray snappyDecode(const QByteArray &val) {
+  size_t size = 0;
+
+  bool res = snappy::GetUncompressedLength(val.constData(), val.size(), &size);
+
+  if (!res) {
+    qWarning() << "Snappy error: Cannot get uncompressed size";
+    QByteArray();
+  }
+
+  std::string output;
+
+  res = snappy::Uncompress(val.constData(), val.size(), &output);
+
+  if (!res) {
+    qWarning() << "Snappy error: Cannot uncompress buffer";
+    QByteArray();
+  }
+
+  return QByteArray::fromStdString(output);
+}
+
+QByteArray snappyEncode(const QByteArray &val) {
+  std::string output;
+
+  bool res = snappy::Compress(val.constData(), val.size(), &output);
+
+  if (!res) {
+    qWarning() << "Snappy error: Cannot compress buffer";
+    QByteArray();
+  }
+
+  return QByteArray::fromStdString(output);
+}
+
+QByteArray brotliDecode(const QByteArray &val)
+{
+    auto decoder = BrotliDecoderCreateInstance(nullptr, nullptr, nullptr);
+
+    if (!decoder) {
+        qWarning() << "BROTLI: Cannot create decoder";
+        return QByteArray();
+    }
+
+    QByteArray dst;
+    dst.resize(BROTLI_BUFFER_SIZE);
+
+    size_t availableIn = val.size(), availableOut = dst.size();
+    const uint8_t* nextIn = reinterpret_cast<const uint8_t*>(val.constData());
+    uint8_t* nextOut = reinterpret_cast<uint8_t*>(dst.data());
+    BrotliDecoderResult itResult;
+
+    do {
+      itResult = BrotliDecoderDecompressStream(
+          decoder, &availableIn, &nextIn, &availableOut, &nextOut, nullptr);
+      if (itResult == BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT) {
+        size_t offset = dst.size() - availableOut;
+        availableOut += dst.size();
+        dst.resize(dst.size() * 2);
+        nextOut = reinterpret_cast<uint8_t *>(dst.data()) + offset;
+        itResult = BROTLI_DECODER_RESULT_SUCCESS;
+      }
+
+      if (itResult != BROTLI_DECODER_RESULT_SUCCESS) {
+          qWarning() << "Brotli: Invalid input";
+          return QByteArray();
+      }
+    } while (!(availableIn == 0 &&
+               itResult == BROTLI_DECODER_RESULT_SUCCESS));
+
+    if (itResult == BROTLI_DECODER_RESULT_SUCCESS)
+        dst.resize(dst.size() - availableOut);
+
+    BrotliDecoderDestroyInstance(decoder);
+    return dst;
+}
+
+QByteArray brotliEncode(const QByteArray &val)
+{
+    auto encoder = BrotliEncoderCreateInstance(nullptr, nullptr, nullptr);
+
+    if (!encoder) {
+        qWarning() << "BROTLI: Cannot create encoder";
+        return QByteArray();
+    }
+
+    QByteArray dst;
+    dst.resize(BROTLI_BUFFER_SIZE);
+
+    size_t availableIn = val.size(), available_out = dst.size();
+    const uint8_t* nextIn = reinterpret_cast<const uint8_t*>(val.constData());
+    uint8_t* nextOut = reinterpret_cast<uint8_t*>(dst.data());
+    size_t totalOut = 0;
+
+    int itResult;
+
+    do
+    {
+        itResult = BrotliEncoderCompressStream
+        (
+            encoder, BROTLI_OPERATION_FINISH,
+            &availableIn, &nextIn, &available_out, &nextOut, &totalOut
+        );
+    }
+    while (!(availableIn == 0 && BrotliEncoderIsFinished(encoder)));
+
+    if (itResult == BROTLI_TRUE) {
+        dst.resize(totalOut);
+    }
+
+    BrotliEncoderDestroyInstance(encoder);
+    return dst;
+}
+
+bool validateLZ4Frame(const QByteArray &val) {
+  const auto magicHeader = QByteArray::fromHex("x04x22x4dx18");
+
+  if (!val.startsWith(magicHeader)) return false;
+
+  LZ4F_dctx *lz4_dctx = nullptr;
+  LZ4F_createDecompressionContext(&lz4_dctx, LZ4F_VERSION);
+
+  if (!lz4_dctx) {
+    qWarning() << "LZ4 error. Cannot initialize context";
+    return false;
+  }
+
+  QScopedPointer<LZ4F_dctx, LZ4FCleanUp> dctx(lz4_dctx);
+
+  LZ4F_frameInfo_t lz4_frameinfo;
+  size_t buffSize = val.size();
+
+  size_t res = LZ4F_getFrameInfo(dctx.data(), &lz4_frameinfo,
+                                 static_cast<const void *>(val.constData()),
+                                 static_cast<size_t *>(&buffSize));
+
+  if (LZ4F_isError(res)) {
+    qWarning() << "LZ4 error. Cannot retrive frame info";
+    return false;
+  }
+
+  return lz4_frameinfo.contentSize > 0;
+}
+
+bool validateZSTDFrame(const QByteArray &val) {
+  const auto magicHeader = QByteArray::fromHex("x28xB5x2FxFD");
+
+  if (!val.startsWith(magicHeader)) {
+    return false;
+  }
+  size_t buffSize = val.size();
+  unsigned long long decompressedSize = ZSTD_getFrameContentSize(
+      static_cast<const void *>(val.constData()), buffSize);
+
+  return !(decompressedSize == ZSTD_CONTENTSIZE_ERROR);
+}
+
+bool validateGZip(const QByteArray &val, int from = 0) {
+  return val.indexOf(QByteArray::fromHex("x1fx8b"), from) == 0;
+}
+
+bool validateSnappyFrame(const QByteArray &val) {
+  return snappy::IsValidCompressedBuffer(val.constData(), val.size());
+}
+
+bool isMagentoCacheFormat(unsigned f) {
+  return qcompress::MAGENTO_CACHE_GZIP <= f &&
+         f <= qcompress::MAGENTO_CACHE_SNAPPY;
+}
+
+QHash<unsigned, QByteArray> knownMagentoFormats() {
+  return {
+      {qcompress::MAGENTO_CACHE_GZIP, "gz"},
+      {qcompress::MAGENTO_SESSION_GZIP, "gz"},
+      {qcompress::MAGENTO_CACHE_LZ4, "l4"},
+      {qcompress::MAGENTO_SESSION_LZ4, "l4"},
+      {qcompress::MAGENTO_CACHE_ZSTD, "zs"},
+      {qcompress::MAGENTO_SESSION_SNAPPY, "sn"},
+      {qcompress::MAGENTO_CACHE_SNAPPY, "sn"},
+  };
+}
+
+static const QHash<unsigned, QByteArray> magentoFormats = knownMagentoFormats();
+
+QByteArray magentoPrefix(unsigned f) {
+  if (!magentoFormats.contains(f)) {
+    return QByteArray();
+  }
+
+  QByteArray id = magentoFormats[f];
+
+  if (isMagentoCacheFormat(f)) {
+    id += QByteArray(":") + QByteArray::fromHex("x1fx8b");
+  } else {
+    id = QByteArray(":") + id + QByteArray(":");
+  }
+
+  return id;
+}
+
+unsigned qcompress::guessFormat(const QByteArray &val) {
+  if (val.size() > 4) {
+    auto mFormats = magentoFormats.keys();
+
+    QByteArray prefix;
+
+    for (auto f : qAsConst(mFormats)) {
+      prefix = magentoPrefix(f);
+
+      if (val.startsWith(prefix)) {
+        return f;
+      }
+    }
+  }
+
+  if (val.size() > 2 && validateGZip(val)) {
+    return qcompress::GZIP;
+  } else if (val.size() > 4 && validateLZ4Frame(val)) {
+    return qcompress::LZ4;
+  } else if (val.size() > 4 && validateZSTDFrame(val)) {
+    return qcompress::ZSTD;
+  } else if (val.size() > 10 && validateSnappyFrame(val)) {
+    return qcompress::SNAPPY;
+  }
+
+  return qcompress::UNKNOWN;
+}
+
+QByteArray qcompress::compress(const QByteArray &val, unsigned algo) {
+  switch (algo) {
+    case qcompress::GZIP:
+      return gzipEncode(val, ZLIB_WINDOW_BIT);
+    case qcompress::MAGENTO_SESSION_GZIP:
+    case qcompress::MAGENTO_CACHE_GZIP:
+      return magentoPrefix(algo) + gzipEncode(val, ZLIB_PHP_WINDOW_BIT);
+    case qcompress::LZ4:
+      return lz4FrameEncode(val);
+    case qcompress::MAGENTO_SESSION_LZ4:
+    case qcompress::MAGENTO_CACHE_LZ4:
+      return magentoPrefix(algo) + lz4RawEncode(val);
+    case qcompress::ZSTD:
+      return zstdEncode(val);
+    case qcompress::MAGENTO_CACHE_ZSTD:
+      return magentoPrefix(algo) + zstdEncode(val);
+    case qcompress::SNAPPY:
+      return snappyEncode(val);
+    case qcompress::MAGENTO_CACHE_SNAPPY:
+    case qcompress::MAGENTO_SESSION_SNAPPY:
+      return magentoPrefix(algo) + snappyEncode(val);
+    case qcompress::BROTLI:
+      return brotliEncode(val);
+    default:
+      return QByteArray();
+  }
+}
+
+QByteArray qcompress::decompress(const QByteArray &val, unsigned format) {
+  int offset = 0;
+
+  if (magentoFormats.contains(format)) {
+    offset = magentoPrefix(format).size();
+  }
+
+  switch (format) {
+    case qcompress::GZIP:
+      return gzipDecode(val, ZLIB_WINDOW_BIT);
+    case qcompress::MAGENTO_SESSION_GZIP:
+    case qcompress::MAGENTO_CACHE_GZIP:
+    case qcompress::GZIP_PHP:
+      return gzipDecode(val.mid(offset), ZLIB_PHP_WINDOW_BIT);
+    case qcompress::LZ4:
+      return lz4FrameDecode(val);
+    case qcompress::MAGENTO_SESSION_LZ4:
+    case qcompress::MAGENTO_CACHE_LZ4:
+    case qcompress::LZ4_RAW:
+      return lz4RawDecode(val.mid(offset));
+    case qcompress::ZSTD:
+      return zstdDecode(val);
+    case qcompress::MAGENTO_CACHE_ZSTD:
+      return zstdDecode(val.mid(offset));
+    case qcompress::SNAPPY:
+      return snappyDecode(val);
+    case qcompress::MAGENTO_CACHE_SNAPPY:
+    case qcompress::MAGENTO_SESSION_SNAPPY:
+      return snappyDecode(val.mid(offset));
+    case qcompress::BROTLI:
+      return brotliDecode(val);
+    default:
+      return QByteArray();
+  }
+}
+
+QString qcompress::nameOf(unsigned alg) {
+  switch (alg) {
+    case qcompress::GZIP:
+      return "gzip";
+    case qcompress::LZ4:
+      return "lz4";
+    case qcompress::MAGENTO_SESSION_GZIP:
+      return "magento-session-gzip";
+    case qcompress::MAGENTO_SESSION_LZ4:
+      return "magento-session-lz4";
+    case qcompress::MAGENTO_CACHE_GZIP:
+      return "magento-cache-gzip";
+    case qcompress::MAGENTO_CACHE_LZ4:
+      return "magento-cache-lz4";
+    case qcompress::MAGENTO_CACHE_ZSTD:
+      return "magento-cache-zstd";
+    case qcompress::MAGENTO_CACHE_SNAPPY:
+      return "magento-cache-snappy";
+    case qcompress::MAGENTO_SESSION_SNAPPY:
+      return "magento-session-snappy";
+    case qcompress::ZSTD:
+      return "ZSTD";
+    case qcompress::SNAPPY:
+      return "Snappy";
+    case qcompress::GZIP_PHP:
+      return "PHP gzcompress";
+    case qcompress::LZ4_RAW:
+      return "LZ4 Raw";
+    case qcompress::BROTLI:
+      return "Brotli";
+    case qcompress::UNKNOWN:
+    default:
+      return "unknown";
+  }
+}

+ 46 - 0
src/app/qcompress.h

@@ -0,0 +1,46 @@
+#pragma once
+#include <QByteArray>
+#include <QString>
+
+namespace qcompress {
+
+enum {
+  UNKNOWN,
+  GZIP,
+  LZ4,
+  ZSTD,
+  /*
+   * MAGENTO session is build on top of the following php lib to store
+   *compressed sessions:
+   * https://github.com/colinmollenhour/php-redis-session-abstract/blob/5f399c53534cd1fe07460407e510590840b2c6d0/src/Cm/RedisSession/Handler.php#L822-L828
+   **/
+  MAGENTO_SESSION_GZIP,
+  MAGENTO_SESSION_LZ4,
+  MAGENTO_SESSION_SNAPPY,
+  // MAGENTO_SESSION_ZSTD, // ZSTD is not yet supported -
+  // https://github.com/colinmollenhour/php-redis-session-abstract/issues/42
+
+  /*
+   * MAGENTO CACHE
+   * https://github.com/colinmollenhour/Cm_Cache_Backend_Redis/blob/a9c4a5ae6001e04097aa7302abd89c9496c563e0/Cm/Cache/Backend/Redis.php#L1202-L1207
+   */
+  MAGENTO_CACHE_GZIP,
+  MAGENTO_CACHE_LZ4,
+  MAGENTO_CACHE_ZSTD,
+  MAGENTO_CACHE_SNAPPY,
+
+  SNAPPY,
+  GZIP_PHP,
+  LZ4_RAW,
+  BROTLI
+};
+
+unsigned guessFormat(const QByteArray& val);
+
+QString nameOf(unsigned alg);
+
+QByteArray decompress(const QByteArray& val, unsigned algo);
+
+QByteArray compress(const QByteArray& val, unsigned algo);
+
+}  // namespace qcompress

+ 361 - 0
src/app/qmlutils.cpp

@@ -0,0 +1,361 @@
+#include "qmlutils.h"
+#include <qredisclient/utils/text.h>
+#include <qtextdocumentfragment.h>
+#include <QApplication>
+#include <QClipboard>
+#include <QDateTime>
+#include <QDebug>
+#include <QDir>
+#include <QFile>
+#include <QFileInfo>
+#include <QScreen>
+#include <QtCharts/QDateTimeAxis>
+#include <QtConcurrent>
+#include <QUrl>
+
+#include "apputils.h"
+#include "jsonutils.h"
+#include "qcompress.h"
+#include "value-editor/largetextmodel.h"
+
+#define MAX_CHART_DATA_POINTS 1000
+
+bool QmlUtils::isBinaryString(const QVariant &value) {
+  if (!value.canConvert(QVariant::ByteArray)) {
+    return false;
+  }
+  QByteArray val = value.toByteArray();   
+
+  return isBinary(val);
+}
+
+long QmlUtils::binaryStringLength(const QVariant &value) {
+  if (!value.canConvert(QVariant::ByteArray)) {
+    return -1;
+  }
+  QByteArray val = value.toByteArray();
+  return val.size();
+}
+
+QVariant QmlUtils::b64toByteArray(const QVariant &value)
+{
+    if (!value.canConvert(QVariant::String)) {
+      return -1;
+    }
+
+    return QVariant(QByteArray::fromBase64(value.toString().toUtf8()));
+}
+
+QByteArray QmlUtils::minifyJSON(const QVariant &value)
+{
+    if (!value.canConvert(QVariant::ByteArray)) {
+      return QByteArray();
+    }
+
+    QByteArray val = value.toByteArray();
+
+    return JSONUtils::minifyJSON(val);
+}
+
+QByteArray QmlUtils::prettyPrintJSON(const QVariant &value)
+{
+  if (!value.canConvert(QVariant::ByteArray)) {
+    return QByteArray();
+  }
+
+  QByteArray val = value.toByteArray();
+  return JSONUtils::prettyPrintJSON(val);
+}
+
+bool QmlUtils::isJSON(const QVariant &value)
+{
+    if (!value.canConvert(QVariant::ByteArray)) {
+      return false;
+    }
+
+    QByteArray val = value.toByteArray();
+    return JSONUtils::isJSON(val);
+}
+
+QVariant QmlUtils::decompress(const QVariant &value, unsigned alg) {
+  if (!value.canConvert(QVariant::ByteArray)) {
+    return 0;
+  }
+
+  return qcompress::decompress(value.toByteArray(), alg);
+}
+
+QVariant QmlUtils::compress(const QVariant &value, unsigned alg) {
+  return qcompress::compress(value.toByteArray(), alg);
+}
+
+unsigned QmlUtils::isCompressed(const QVariant &value) {
+  if (!value.canConvert(QVariant::ByteArray)) {
+    return 0;
+  }
+
+  return qcompress::guessFormat(value.toByteArray());
+}
+
+QString QmlUtils::compressionAlgName(unsigned alg) {
+    return qcompress::nameOf(alg);
+}
+
+QVariant QmlUtils::compressionMethodsNoMagic()
+{
+    QVariantList methodsWithoutMagicHeaders = {
+        qcompress::UNKNOWN,
+        qcompress::BROTLI,
+        qcompress::LZ4_RAW,
+
+        //NOTE(u_glide): Should be always last in this list
+        // QML side use it for conditions
+        qcompress::GZIP_PHP,
+    };
+
+    return methodsWithoutMagicHeaders;
+}
+
+QString QmlUtils::humanSize(long size) { return humanReadableSize(size); }
+
+QVariant QmlUtils::valueToBinary(const QVariant &value) {
+  if (!value.canConvert(QVariant::ByteArray)) {
+    return QVariant();
+  }
+
+  QByteArray val = value.toByteArray();
+  QVariantList list;
+
+  for (int index = 0; index < val.length(); ++index) {
+    list.append(QVariant((unsigned char)val.at(index)));
+  }
+  return QVariant(list);
+}
+
+QVariant QmlUtils::binaryListToValue(const QVariantList &binaryList) {
+  QByteArray value;
+  foreach (QVariant v, binaryList) { value.append((unsigned char)v.toInt()); }
+  return value;
+}
+
+QVariant QmlUtils::printable(const QVariant &value, bool htmlEscaped, int maxLength) {
+  if (!value.canConvert(QVariant::ByteArray)) {
+    return QVariant();
+  }
+
+  QByteArray val = value.toByteArray();
+
+  if (maxLength > 0 && val.size() > maxLength) {
+    val.truncate(maxLength);
+  }
+
+  if (htmlEscaped) {
+    return printableString(val).toHtmlEscaped();
+  } else {
+    return printableString(val);
+  }
+}
+
+QVariant QmlUtils::printableToValue(const QVariant &printable) {
+  if (!printable.canConvert(QVariant::String)) {
+    return QVariant();
+  }
+  QString val = printable.toString();
+  return printableStringToBinary(val);
+}
+
+QVariant QmlUtils::toUtf(const QVariant &value) {
+  if (!value.canConvert(QVariant::ByteArray)) {
+    return QVariant();
+  }
+  QByteArray val = value.toByteArray();
+  QString result = QString::fromUtf8(val.constData(), val.size());
+  return QVariant(result);
+}
+
+QString QmlUtils::getNativePath(const QString &path) {
+  return QDir::toNativeSeparators(path);
+}
+
+QString QmlUtils::getPathFromUrl(const QUrl &url) {
+  return url.isLocalFile() ? url.toLocalFile() : url.path();
+}
+
+QString QmlUtils::getUrlFromPath(const QString &path) {
+  return QUrl::fromLocalFile(path).toString();
+}
+
+QString QmlUtils::getDir(const QString &path) {
+  return QFileInfo(path).absoluteDir().absolutePath();
+}
+
+bool QmlUtils::fileExists(const QString &path) {
+    return QFileInfo::exists(path);
+}
+
+QString QmlUtils::replaceColorsInSvg(const QString &path, QVariant mapping)
+{
+    QFile svgFile(path.mid(3));
+    if (!svgFile.open(QIODevice::ReadOnly)) {
+        qWarning() << "Cannot open svg:" << path.mid(3);
+        return QString();
+    }
+
+    if (!mapping.canConvert<QVariantMap>()) {
+        qWarning() << "Invalid colors mapping:" << mapping;
+        return QString();
+    }
+
+    QVariantMap colors = mapping.toMap();
+
+    QString svgData = QString::fromUtf8(svgFile.readAll());
+
+    auto it = colors.constBegin();
+
+    while (it != colors.constEnd()) {
+        auto originalColor = it.key();
+        auto newColor = QColor(it.value().toString());
+
+        if (newColor.alphaF() < 1) {
+            svgData.replace(originalColor, QString("%1\" fill-opacity=\"%2").arg(newColor.name()).arg(newColor.alphaF()));
+        } else {
+            svgData = svgData.replace(originalColor, newColor.name());
+        }
+        ++it;
+    }
+
+    return QString("data:image/svg+xml;utf8,%1").arg(svgData);
+
+}
+
+QString QmlUtils::changeColorAlpha(QColor c, int a)
+{
+    c.setAlpha(a);
+    return c.name(QColor::HexArgb);
+}
+
+void QmlUtils::copyToClipboard(const QString &text) {
+  QClipboard *cb = QApplication::clipboard();
+
+  if (!cb) return;
+
+  cb->clear();
+  cb->setText(text);
+}
+
+bool QmlUtils::saveToFile(const QVariant &value, const QString &path) {
+  if (!value.canConvert(QVariant::ByteArray)) {
+    return false;
+  }
+
+  QtConcurrent::run([value, path]() {
+    QByteArray val = value.toByteArray();
+
+    QFile outputFile(path);
+    if (outputFile.open(QIODevice::WriteOnly)) {
+      QDataStream outStream(&outputFile);
+      outStream.writeRawData(val, val.size());
+      outputFile.close();
+      return true;
+    }
+    return false;
+  });
+
+  return true;
+}
+
+QtCharts::QDateTimeAxis *findDateTimeAxis(QtCharts::QXYSeries *series) {
+  using namespace QtCharts;
+
+  QList<QAbstractAxis *> axes = series->attachedAxes();
+
+  QDateTimeAxis *ax = nullptr;
+
+  for (QAbstractAxis *axis : axes) {
+    if (axis->type() == QAbstractAxis::AxisTypeDateTime) {
+      ax = qobject_cast<QDateTimeAxis *>(axis);
+      return ax;
+    }
+  }
+
+  return ax;
+}
+
+void QmlUtils::addNewValueToDynamicChart(QtCharts::QXYSeries *series,
+                                         qreal value) {
+  using namespace QtCharts;
+
+  QDateTimeAxis *ax = findDateTimeAxis(series);
+
+  if (!(ax && series)) {
+      qWarning() << "Cannot add value to dynamic chart. Invalid pointers.";
+      return;
+  }
+
+  int totalPoints = series->count();
+
+  if (totalPoints == 0) {
+    ax->setMin(QDateTime::currentDateTime());
+  }
+
+  bool dataNotChangedLastFivePoints = totalPoints > 10;
+
+  for (int i = 1; dataNotChangedLastFivePoints && i < 6; i++) {
+    if (value != series->at(totalPoints - i).y()) {
+      dataNotChangedLastFivePoints = false;
+      break;
+    }
+  }
+
+  if (dataNotChangedLastFivePoints) {
+    series->replace(totalPoints - 1, QDateTime::currentDateTime().toMSecsSinceEpoch(), value);
+  } else {
+    series->append(QDateTime::currentDateTime().toMSecsSinceEpoch(), value);
+  }
+
+  if (totalPoints > MAX_CHART_DATA_POINTS) {
+      series->removePoints(0, totalPoints - MAX_CHART_DATA_POINTS);
+      ax->setMin(QDateTime::fromMSecsSinceEpoch(series->at(0).x()));
+  }
+
+  if (series->attachedAxes().size() > 0) {
+    ax->setMax(QDateTime::currentDateTime());
+  }
+}
+
+QObject *QmlUtils::wrapLargeText(const QByteArray &text) {
+  // NOTE(u_glide): Use 50Kb chunks by default
+  int chunkSize = 50000;
+
+  auto w = new ValueEditor::LargeTextWrappingModel(QString::fromUtf8(text),
+                                                   chunkSize);
+  w->setParent(this);
+  return w;
+}
+
+void QmlUtils::deleteTextWrapper(QObject *w) {
+  if (w && w->parent() == this) {
+    w->deleteLater();
+  }
+}
+
+QString QmlUtils::escapeHtmlEntities(const QString &t) {
+  return t.toHtmlEscaped();
+}
+
+QString QmlUtils::standardKeyToString(QKeySequence::StandardKey key) {
+  return QKeySequence(key).toString(QKeySequence::NativeText);
+}
+
+double QmlUtils::getScreenScaleFactor() {
+    return QApplication::primaryScreen()->logicalDotsPerInch() / 96;
+}
+
+bool QmlUtils::isAppStoreBuild()
+{
+#ifdef RDM_APPSTORE
+    return true;
+#else
+    return false;
+#endif
+}

+ 50 - 0
src/app/qmlutils.h

@@ -0,0 +1,50 @@
+#pragma once
+#include <QObject>
+#include <QVariant>
+#include <QVariantList>
+#include <QUrl>
+#include <QtCharts/QXYSeries>
+#include <QKeySequence>
+
+class QmlUtils : public QObject
+{
+    Q_OBJECT
+public:
+    Q_INVOKABLE bool isBinaryString(const QVariant &value);
+    Q_INVOKABLE long binaryStringLength(const QVariant &value);    
+    Q_INVOKABLE QVariant b64toByteArray(const QVariant &value);
+    Q_INVOKABLE QByteArray minifyJSON(const QVariant &value);
+    Q_INVOKABLE QByteArray prettyPrintJSON(const QVariant &value);
+    Q_INVOKABLE bool isJSON(const QVariant &value);
+
+    Q_INVOKABLE unsigned isCompressed(const QVariant &value);
+    Q_INVOKABLE QVariant decompress(const QVariant &value, unsigned alg);
+    Q_INVOKABLE QVariant compress(const QVariant &value, unsigned alg);
+    Q_INVOKABLE QString compressionAlgName(unsigned alg);
+    Q_INVOKABLE QVariant compressionMethodsNoMagic();
+
+    Q_INVOKABLE QString humanSize(long size);
+    Q_INVOKABLE QVariant valueToBinary(const QVariant &value);
+    Q_INVOKABLE QVariant binaryListToValue(const QVariantList& binaryList);
+    Q_INVOKABLE QVariant printable(const QVariant &value, bool htmlEscaped=false, int maxLength=-1);
+    Q_INVOKABLE QVariant printableToValue(const QVariant &printable);
+    Q_INVOKABLE QVariant toUtf(const QVariant &value);
+    Q_INVOKABLE QString getNativePath(const QString &path);
+    Q_INVOKABLE QString getPathFromUrl(const QUrl &url);
+    Q_INVOKABLE QString getUrlFromPath(const QString &path);
+    Q_INVOKABLE QString getDir(const QString &path);
+    Q_INVOKABLE bool fileExists(const QString& path);
+
+    Q_INVOKABLE QString replaceColorsInSvg(const QString& path, QVariant mapping);
+    Q_INVOKABLE QString changeColorAlpha(QColor c, int a);
+
+    Q_INVOKABLE void copyToClipboard(const QString &text);
+    Q_INVOKABLE bool saveToFile(const QVariant &value, const QString &path);
+    Q_INVOKABLE void addNewValueToDynamicChart(QtCharts::QXYSeries* series, qreal value);
+    Q_INVOKABLE QObject* wrapLargeText(const QByteArray &text);
+    Q_INVOKABLE void deleteTextWrapper(QObject* w);
+    Q_INVOKABLE QString escapeHtmlEntities(const QString& t);
+    Q_INVOKABLE QString standardKeyToString(QKeySequence::StandardKey key);
+    Q_INVOKABLE double getScreenScaleFactor();    
+    Q_INVOKABLE bool isAppStoreBuild();
+};

+ 98 - 0
src/main.cpp

@@ -0,0 +1,98 @@
+#include <QDir>
+#include <QFileInfo>
+#include <QGuiApplication>
+#include <QScreen>
+#include <QDebug>
+
+#if defined(Q_OS_WIN) | defined(Q_OS_LINUX)
+#include <QProcess>
+#define RELAUNCH_CODE 1001
+#endif
+
+#ifdef CRASHPAD_INTEGRATION
+#include "crashpad/handler.h"
+#endif
+
+#ifdef LINUX_SIGNALS
+#include <sigwatch.h>
+#endif
+
+#ifdef IGNORE_QML_WARNINGS
+static const QtMessageHandler QT_DEFAULT_MESSAGE_HANDLER =
+    qInstallMessageHandler(0);
+
+void customMessageHandler(QtMsgType type, const QMessageLogContext &context,
+                          const QString &msg) {
+  switch (type) {
+    case QtWarningMsg: {
+      if (!msg.contains("QML IconLabel")) {
+        (*QT_DEFAULT_MESSAGE_HANDLER)(type, context, msg);
+      }
+    } break;
+    default:  // Call the default handler.
+      (*QT_DEFAULT_MESSAGE_HANDLER)(type, context, msg);
+      break;
+  }
+}
+#endif
+
+#include "app/app.h"
+
+int main(int argc, char *argv[])
+{             
+    int returnCode = 0;
+
+#ifdef CRASHPAD_INTEGRATION
+    QFileInfo appPath(QString::fromLocal8Bit(argv[0]));
+    QString appDir(appPath.absoluteDir().path());
+    startCrashpad(appDir);
+#endif
+
+#if defined(Q_OS_WIN) || defined(Q_OS_LINUX)
+    bool disableAutoScaling = false;
+
+
+#ifndef DISABLE_SCALING_TEST
+    {
+        QGuiApplication tmp(argc, argv);
+        disableAutoScaling = QGuiApplication::primaryScreen()
+                        && QGuiApplication::primaryScreen()->availableSize().width() <= 1920
+                        && QGuiApplication::primaryScreen()->devicePixelRatio() == 1;
+    }
+#endif
+
+    if (disableAutoScaling) {
+        qDebug() << "Disable auto-scaling";
+        QGuiApplication::setAttribute(Qt::AA_DisableHighDpiScaling);
+    } else {
+        qDebug() << "Enable auto-scaling";
+        QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+    }
+#endif
+
+    Application a(argc, argv);
+
+#ifdef IGNORE_QML_WARNINGS
+    qInstallMessageHandler(customMessageHandler);
+#endif
+
+#ifdef LINUX_SIGNALS
+    UnixSignalWatcher sigwatch;
+    sigwatch.watchForSignal(SIGINT);
+    sigwatch.watchForSignal(SIGTERM);
+    QObject::connect(&sigwatch, SIGNAL(unixSignal(int)), &a, SLOT(quit()));
+#endif
+    a.initModels();
+    a.initQml();
+    returnCode = a.exec();
+
+#if defined(Q_OS_WIN) | defined(Q_OS_LINUX)
+    if (returnCode == RELAUNCH_CODE) {
+        QProcess::startDetached(a.arguments()[0], a.arguments());
+        returnCode = 0;
+    }
+#endif
+
+    return returnCode;
+}
+

+ 175 - 0
src/modules/bulk-operations/bulkoperationsmanager.cpp

@@ -0,0 +1,175 @@
+#include "bulkoperationsmanager.h"
+#include <qredisclient/connection.h>
+#include <QDebug>
+
+#include <qpython.h>
+
+#include "operations/copyoperation.h"
+#include "operations/deleteoperation.h"
+#include "operations/rdbimport.h"
+#include "operations/ttloperation.h"
+
+BulkOperations::Manager::Manager(QSharedPointer<ConnectionsModel> model)
+    : QObject(nullptr), m_model(model), m_python(nullptr) {
+    Q_ASSERT(m_model);
+}
+
+void BulkOperations::Manager::setPython(QSharedPointer<QPython> p)
+{
+    if (!p) {
+        qWarning() << "Invalid python instance passed to BulkOperations";
+        return;
+    }
+
+    m_python = p;
+}
+
+bool BulkOperations::Manager::hasOperation() const {
+  return !m_operation.isNull();
+}
+
+bool BulkOperations::Manager::multiConnectionOperation() const {
+  return m_operation && m_operation->multiConnectionOperation();
+}
+
+bool BulkOperations::Manager::clearOperation() {
+  if (!hasOperation()) return true;
+
+  if (m_operation->isRunning()) {
+    return false;
+  }
+
+  m_operation.clear();
+  return true;
+}
+
+void BulkOperations::Manager::runOperation(int connectionIndex, int dbIndex) {
+  if (!hasOperation()) return;
+
+  if (m_operation->multiConnectionOperation()) {
+    if (!(connectionIndex >= 0 && dbIndex >= 0 &&
+          m_model->getByIndex(connectionIndex))) {
+      qWarning() << "invalid target connection";
+      return;
+    }
+
+    m_operation->run(m_model->getByIndex(connectionIndex), dbIndex);
+  } else {
+    m_operation->run();
+  }
+}
+
+void BulkOperations::Manager::getAffectedKeys() {
+  if (!hasOperation()) return;
+
+  m_operation->getAffectedKeys([this](QVariant r, QString e) {
+    if (!e.isEmpty()) {
+      emit error(e, "");
+      return;
+    }
+
+    emit affectedKeys(r);
+  });
+}
+
+QVariant BulkOperations::Manager::getTargetConnections() {
+  return QVariant(m_model->getConnections());
+}
+
+void BulkOperations::Manager::setOperationMetadata(const QVariantMap& meta) {
+  if (hasOperation()) m_operation->setMetadata(meta);
+}
+
+QString BulkOperations::Manager::operationName() const {
+  if (!hasOperation()) return QString();
+
+  return m_operation->getTypeName();
+}
+
+QString BulkOperations::Manager::connectionName() const {
+  if (!hasOperation()) return QString();
+
+  return m_operation->getConnection()->getConfig().name();
+}
+
+int BulkOperations::Manager::dbIndex() const {
+  if (!hasOperation()) return -1;
+
+  return m_operation->getDbIndex();
+}
+
+QString BulkOperations::Manager::keyPattern() const {
+  if (!hasOperation()) return QString();
+
+  return m_operation->getKeyPattern().pattern();
+}
+
+void BulkOperations::Manager::setKeyPattern(const QString& p) {
+  if (!hasOperation()) return;
+
+  m_operation->setKeyPattern(QRegExp(p, Qt::CaseSensitive, QRegExp::Wildcard));
+}
+
+int BulkOperations::Manager::operationProgress() const {
+  if (!hasOperation()) return -1;
+
+  return m_operation->currentProgress();
+}
+
+void BulkOperations::Manager::requestBulkOperation(
+    QSharedPointer<RedisClient::Connection> connection, int dbIndex,
+    BulkOperations::Manager::Operation op, QRegExp keyPattern,
+    AbstractOperation::OperationCallback callback) {
+  if (hasOperation()) {
+    qWarning() << "BulkOperationsManager already has bulk operation request";
+    return;
+  }
+
+  auto callbackWrapper = [this, callback](QRegExp filter, long processed,
+                                          const QStringList& e) {
+    if (e.size() > 0) {
+      emit error(QCoreApplication::translate(
+                     "RESP", "Failed to perform actions on %1 keys. ")
+                     .arg(e.size()),
+                 e.join("\n"));
+    } else {
+      emit operationFinished();
+    }
+
+    return callback(filter, processed, e);
+  };
+
+  if (op == Operation::DELETE_KEYS) {
+    m_operation = QSharedPointer<BulkOperations::AbstractOperation>(
+        new BulkOperations::DeleteOperation(connection, dbIndex,
+                                            callbackWrapper, keyPattern));
+  } else if (op == Operation::TTL) {
+    m_operation = QSharedPointer<BulkOperations::AbstractOperation>(
+        new BulkOperations::TtlOperation(connection, dbIndex, callbackWrapper,
+                                         keyPattern));
+  } else if (op == Operation::COPY_KEYS) {
+    m_operation = QSharedPointer<BulkOperations::AbstractOperation>(
+        new BulkOperations::CopyOperation(connection, dbIndex, callbackWrapper,
+                                          keyPattern));
+  } else if (op == Operation::IMPORT_RDB_KEYS) {
+    if (!m_python) {
+      qWarning() << "Python is not ready yet";
+      return;
+    }
+
+    m_operation = QSharedPointer<BulkOperations::AbstractOperation>(
+        new BulkOperations::RDBImportOperation(
+            connection, dbIndex, callbackWrapper, m_python, keyPattern));
+  }
+
+  QObject::connect(m_operation.data(),
+                   &BulkOperations::AbstractOperation::progress, this,
+                   [this](int) { emit operationProgressChanged(); });
+
+  emit operationNameChanged();
+  emit connectionNameChanged();
+  emit dbIndexChanged();
+  emit keyPatternChanged();
+  emit operationProgressChanged();
+  emit openDialog(m_operation->getTypeName());
+}

+ 87 - 0
src/modules/bulk-operations/bulkoperationsmanager.h

@@ -0,0 +1,87 @@
+#pragma once
+#include <qredisclient/response.h>
+#include <QObject>
+#include <QRegExp>
+#include <QSharedPointer>
+#include <QString>
+#include <QStringList>
+#include <QVariant>
+#include <functional>
+
+#include "connections.h"
+#include "operations/abstractoperation.h"
+
+class QPython;
+
+namespace BulkOperations {
+
+class Manager : public QObject {
+  Q_OBJECT
+
+  Q_PROPERTY(
+      QString operationName READ operationName NOTIFY operationNameChanged)
+  Q_PROPERTY(
+      QString connectionName READ connectionName NOTIFY connectionNameChanged)
+  Q_PROPERTY(int dbIndex READ dbIndex NOTIFY dbIndexChanged)
+  Q_PROPERTY(QString keyPattern READ keyPattern WRITE setKeyPattern NOTIFY
+                 keyPatternChanged)
+  Q_PROPERTY(int operationProgress READ operationProgress NOTIFY
+                 operationProgressChanged)
+ public:
+  enum class Operation {
+    DELETE_KEYS,
+    COPY_KEYS,
+    IMPORT_RDB_KEYS,
+    TTL,
+  };
+
+ public:
+  Manager(QSharedPointer<ConnectionsModel> model);
+
+  void setPython(QSharedPointer<QPython> p);
+
+  Q_INVOKABLE bool hasOperation() const;
+  Q_INVOKABLE bool multiConnectionOperation() const;
+  Q_INVOKABLE bool clearOperation();
+  Q_INVOKABLE void runOperation(int targetConnection = -1, int targetDb = -1);
+  Q_INVOKABLE void getAffectedKeys();
+  Q_INVOKABLE QVariant getTargetConnections();
+
+  Q_INVOKABLE void setOperationMetadata(const QVariantMap& meta);
+
+  // Property getters
+  QString operationName() const;
+
+  QString connectionName() const;
+
+  int dbIndex() const;
+
+  QString keyPattern() const;
+  void setKeyPattern(const QString& p);
+
+  int operationProgress() const;
+
+ signals:
+  void openDialog(const QString& operationName);
+  void affectedKeys(QVariant r);
+  void operationFinished();
+  void error(const QString& e, const QString& details);
+
+  // Property notifiers
+  void operationNameChanged();
+  void connectionNameChanged();
+  void dbIndexChanged();
+  void keyPatternChanged();
+  void operationProgressChanged();
+
+ public slots:
+  void requestBulkOperation(QSharedPointer<RedisClient::Connection> connection,
+                            int dbIndex, Operation op, QRegExp keyPattern,
+                            AbstractOperation::OperationCallback callback);
+
+ private:
+  QSharedPointer<AbstractOperation> m_operation;
+  QSharedPointer<ConnectionsModel> m_model;
+  QSharedPointer<QPython> m_python;
+};
+}  // namespace BulkOperations

+ 17 - 0
src/modules/bulk-operations/connections.h

@@ -0,0 +1,17 @@
+#pragma once
+#include <QSharedPointer>
+#include <QStringList>
+
+namespace RedisClient {
+class Connection;
+}
+
+namespace BulkOperations {
+
+class ConnectionsModel {
+ public:
+  virtual QSharedPointer<RedisClient::Connection> getByIndex(int index) = 0;
+
+  virtual QStringList getConnections() = 0;
+};
+}  // namespace BulkOperations

+ 116 - 0
src/modules/bulk-operations/operations/abstractoperation.cpp

@@ -0,0 +1,116 @@
+#include "abstractoperation.h"
+#include <qredisclient/utils/text.h>
+
+BulkOperations::AbstractOperation::AbstractOperation(
+    QSharedPointer<RedisClient::Connection> connection, int dbIndex,
+    OperationCallback callback, QRegExp keyPattern)
+    : m_connection(connection),
+      m_dbIndex(dbIndex),
+      m_keyPattern(keyPattern),
+      m_currentState(State::READY),
+      m_progress(0),
+      m_callback(callback),
+      m_lastProgressNotification(0) {}
+
+void BulkOperations::AbstractOperation::getAffectedKeys(
+    std::function<void(QVariant, QString)> callback) {
+  auto processingCallback =
+      [this, callback](const RedisClient::Connection::RawKeysList& keys,
+                       const QString& err) {
+        if (!err.isEmpty()) {
+          return callback(QVariant(), err);
+        }
+
+        m_affectedKeys.clear();
+
+        QStringList keyNames;
+
+        for (const QByteArray &k : keys) {
+          m_affectedKeys.append(k);
+          keyNames.append(printableString(k, true));
+        }
+
+        return callback(QVariant(keyNames), "");
+      };
+
+  try {
+    if (!m_connection->connect(true)) {
+      return callback(QVariant(), QCoreApplication::translate(
+                                      "RESP", "Cannot connect to redis-server"));
+    }
+
+    if (m_connection->mode() == RedisClient::Connection::Mode::Cluster) {
+      m_connection->getClusterKeys(processingCallback, m_keyPattern.pattern());
+    } else {
+      m_connection->getDatabaseKeys(processingCallback, m_keyPattern.pattern(),
+                                    m_dbIndex);
+    }
+
+  } catch (const RedisClient::Connection::Exception& e) {
+    return callback(QVariant(), QString(e.what()));
+  }
+}
+
+void BulkOperations::AbstractOperation::run(
+    QSharedPointer<RedisClient::Connection> targetConnection,
+    int targetDbIndex) {
+  if (!isMetadataValid()) {
+    qWarning() << QString("Invalid metadata for %1").arg(getTypeName());
+    return;
+  }
+
+  if (m_affectedKeys.size() > 0) {
+    performOperation(targetConnection, targetDbIndex);
+  } else {
+    getAffectedKeys([this, targetConnection, targetDbIndex](QVariant, QString) {
+      performOperation(targetConnection, targetDbIndex);
+    });
+  }
+}
+
+bool BulkOperations::AbstractOperation::isRunning() const {
+  return m_currentState == State::RUNNING;
+}
+
+QSharedPointer<RedisClient::Connection>
+BulkOperations::AbstractOperation::getConnection() {
+  return m_connection;
+}
+
+int BulkOperations::AbstractOperation::getDbIndex() const { return m_dbIndex; }
+
+QRegExp BulkOperations::AbstractOperation::getKeyPattern() const {
+  return m_keyPattern;
+}
+
+void BulkOperations::AbstractOperation::setKeyPattern(const QRegExp p) {
+  m_keyPattern = p;
+}
+
+int BulkOperations::AbstractOperation::currentProgress() const {
+  return m_progress;
+}
+
+void BulkOperations::AbstractOperation::setMetadata(const QVariantMap& meta) {
+  m_metadata = meta;
+}
+
+void BulkOperations::AbstractOperation::incrementProgress() {
+  QMutexLocker l(&m_processedKeysMutex);
+  m_progress++;
+
+  if (QDateTime::currentMSecsSinceEpoch() - m_lastProgressNotification >=
+      1000) {
+    qDebug() << "Notify UI about progress";
+    emit progress(m_progress);
+    m_lastProgressNotification = QDateTime::currentMSecsSinceEpoch();
+  }
+}
+
+void BulkOperations::AbstractOperation::processError(const QString& err) {
+  {
+      QMutexLocker l(&m_errorsMutex);
+      m_errors.append(m_errorMessagePrefix + err);
+  }
+  m_callback(m_keyPattern, m_progress, m_errors);
+}

+ 82 - 0
src/modules/bulk-operations/operations/abstractoperation.h

@@ -0,0 +1,82 @@
+#pragma once
+#include <QObject>
+#include <QRegExp>
+#include <QSharedPointer>
+
+#include <qredisclient/connection.h>
+
+namespace BulkOperations {
+
+class AbstractOperation : public QObject {
+  Q_OBJECT
+
+ public:
+  enum class State { READY, RUNNING, FINISHED };
+
+  typedef std::function<void(QRegExp affectedKeysFilter, long processed,
+                             const QStringList& errors)>
+      OperationCallback;
+
+ public:
+  AbstractOperation(QSharedPointer<RedisClient::Connection> connection,
+                    int dbIndex, OperationCallback callback,
+                    QRegExp keyPattern = QRegExp("*", Qt::CaseSensitive,
+                                                 QRegExp::Wildcard));
+
+  virtual ~AbstractOperation() {}
+
+  virtual void getAffectedKeys(std::function<void(QVariant, QString)> callback);
+
+  virtual void run(QSharedPointer<RedisClient::Connection> targetConnection =
+                       QSharedPointer<RedisClient::Connection>(),
+                   int targetDbIndex = 0);
+
+  virtual QString getTypeName() const = 0;
+
+  virtual bool multiConnectionOperation() const = 0;
+
+  bool isRunning() const;
+
+  QSharedPointer<RedisClient::Connection> getConnection();
+
+  int getDbIndex() const;
+
+  QRegExp getKeyPattern() const;
+
+  void setKeyPattern(const QRegExp p);
+
+  int currentProgress() const;
+
+  void setMetadata(const QVariantMap& meta);
+
+ signals:
+  void progress(int processed);
+
+ protected:
+  virtual bool isMetadataValid() const { return true; }
+
+  virtual void performOperation(
+      QSharedPointer<RedisClient::Connection> targetConnection,
+      int targetDbIndex) = 0;
+
+  void incrementProgress();
+
+  void processError(const QString& err);
+
+ protected:
+  QSharedPointer<RedisClient::Connection> m_connection;
+  int m_dbIndex;
+  QRegExp m_keyPattern;
+  State m_currentState;
+  int m_progress;
+  QList<QByteArray> m_affectedKeys;
+  QList<QByteArray> m_keysWithErrors;
+  QVariantMap m_metadata;
+  OperationCallback m_callback;
+  QStringList m_errors;
+  QMutex m_errorsMutex;
+  QMutex m_processedKeysMutex;
+  qint64 m_lastProgressNotification;
+  QString m_errorMessagePrefix;
+};
+}  // namespace BulkOperations

+ 125 - 0
src/modules/bulk-operations/operations/copyoperation.cpp

@@ -0,0 +1,125 @@
+#include "copyoperation.h"
+
+#include <QtConcurrent>
+
+#define RESTORE_BUFFER_LIMIT 100
+
+BulkOperations::CopyOperation::CopyOperation(
+    QSharedPointer<RedisClient::Connection> connection, int dbIndex,
+    OperationCallback callback, QRegExp keyPattern)
+    : BulkOperations::AbstractOperation(connection, dbIndex, callback,
+                                        keyPattern) {
+  m_errorMessagePrefix = QCoreApplication::translate("RESP", "Cannot copy key ");
+}
+
+void BulkOperations::CopyOperation::performOperation(
+    QSharedPointer<RedisClient::Connection> targetConnection,
+    int targetDbIndex) {
+  m_progress = 0;
+  m_dumpedKeys = 0;
+  m_errors.clear();
+
+  auto returnResults = [this]() {
+    m_callback(m_keyPattern, m_progress, m_errors);
+  };
+
+  if (m_affectedKeys.size() == 0) {
+    return returnResults();
+  }
+
+  QByteArray ttl =
+      QString::number(m_metadata["ttl"].toLongLong() * 1000).toUtf8();
+  QByteArray replace = m_metadata["replace"].toString().toUpper().toUtf8();
+
+  auto processKeyDumps = [this, returnResults, ttl, replace, targetConnection,
+                          targetDbIndex](const RedisClient::Response& r,
+                                         QString err) {
+    if (!err.isEmpty()) {
+      return processError(err);
+    }
+
+    {
+      QMutexLocker l(&m_processedKeysMutex);
+      QVariant incrResult = r.value();
+
+      auto getRestoreCmd = [this, r, replace, ttl](const QByteArray& dump) {
+        QList<QByteArray> restoreCmd{
+            "RESTORE", m_affectedKeys[m_dumpedKeys], ttl, dump};
+        if (!replace.isEmpty()) {
+          restoreCmd.append(replace);
+        }
+        return restoreCmd;
+      };
+
+      if (incrResult.canConvert(QVariant::ByteArray)) {
+        m_restoreBuffer.append(getRestoreCmd(incrResult.toByteArray()));
+        m_dumpedKeys++;
+      } else if (incrResult.canConvert(QVariant::List)) {
+        auto responses = incrResult.toList();
+
+        for (auto resp : qAsConst(responses)) {
+          m_restoreBuffer.append(getRestoreCmd(resp.toByteArray()));
+          m_dumpedKeys++;
+        }
+      }
+    }
+
+    if (m_restoreBuffer.size() > RESTORE_BUFFER_LIMIT ||
+        m_dumpedKeys == m_affectedKeys.size()) {
+      int batchSize = m_restoreBuffer.size();
+
+      targetConnection->pipelinedCmd(
+          m_restoreBuffer, this, targetDbIndex,
+          [this, returnResults, batchSize](const RedisClient::Response& r, QString err) {
+            if (!err.isEmpty() || r.isErrorMessage()) {
+              return processError(err.isEmpty()? r.value().toByteArray() : err);
+            }
+            {
+              QMutexLocker l(&m_processedKeysMutex);
+              m_progress += batchSize;
+              emit progress(m_progress);
+            }
+
+            if (m_progress >= m_affectedKeys.size()) {
+              returnResults();
+            }
+          }, false);
+      m_restoreBuffer.clear();
+    }
+  };
+
+  auto processKeys = [this, processKeyDumps]() {
+    QList<QList<QByteArray>> rawCmds;
+
+    for (const QByteArray &k : qAsConst(m_affectedKeys)) {
+      rawCmds.append({"DUMP", k});
+    }
+
+    m_connection->pipelinedCmd(rawCmds, this, -1, processKeyDumps, true);
+  };
+
+  auto verifySourceConnection = [this, processKeys, targetConnection]() {
+    m_connection->cmd(
+        {"ping"}, this, m_dbIndex,
+        [processKeys, this](const RedisClient::Response& r) {
+          if (r.isErrorMessage()) {
+            return processError(
+                QCoreApplication::translate("RESP", "Source connection error"));
+          }
+          QtConcurrent::run(processKeys);
+        },
+        [this](const QString& err) { processError(err); });
+  };
+
+  targetConnection->cmd(
+      {"ping"}, this, targetDbIndex,
+      [verifySourceConnection, this](const RedisClient::Response& r) {
+        if (r.isErrorMessage()) {
+          return processError(
+              QCoreApplication::translate("RESP", "Target connection error"));
+        }
+
+        verifySourceConnection();
+      },
+      [this](const QString& err) { processError(err); });
+}

+ 36 - 0
src/modules/bulk-operations/operations/copyoperation.h

@@ -0,0 +1,36 @@
+#pragma once
+#include <asyncfuture.h>
+#include <QObject>
+#include <QRegExp>
+#include <QSharedPointer>
+#include "abstractoperation.h"
+
+namespace BulkOperations {
+
+class CopyOperation : public AbstractOperation {
+  Q_OBJECT
+ public:
+  CopyOperation(QSharedPointer<RedisClient::Connection> connection, int dbIndex,
+                OperationCallback callback,
+                QRegExp keyPattern = QRegExp("*", Qt::CaseSensitive,
+                                             QRegExp::Wildcard));
+
+  QString getTypeName() const override { return QString("copy_keys"); }
+
+  bool multiConnectionOperation() const override { return true; }
+
+  bool isMetadataValid() const override {
+    return m_metadata.contains("ttl") && m_metadata.contains("replace");
+  }
+
+ protected:
+  void performOperation(
+      QSharedPointer<RedisClient::Connection> targetConnection,
+      int targetDbIndex) override;
+
+ private:
+   QList<QList<QByteArray>> m_restoreBuffer;
+   int m_dumpedKeys;
+
+};
+}  // namespace BulkOperations

+ 82 - 0
src/modules/bulk-operations/operations/deleteoperation.cpp

@@ -0,0 +1,82 @@
+#include "deleteoperation.h"
+
+#include <QtConcurrent>
+
+BulkOperations::DeleteOperation::DeleteOperation(
+    QSharedPointer<RedisClient::Connection> connection, int dbIndex,
+    OperationCallback callback, QRegExp keyPattern)
+    : BulkOperations::AbstractOperation(connection, dbIndex, callback,
+                                        keyPattern) {
+  m_errorMessagePrefix =
+      QCoreApplication::translate("RESP", "Cannot remove key ");
+}
+
+void BulkOperations::DeleteOperation::performOperation(
+    QSharedPointer<RedisClient::Connection>, int) {
+  m_progress = 0;
+  m_errors.clear();
+
+  auto returnResults = [this]() {
+    qDebug() << "Processed keys: " << m_progress;
+    m_callback(m_keyPattern, m_progress, m_errors);
+  };
+
+  if (m_affectedKeys.size() == 0) {
+    return returnResults();
+  }
+
+  AsyncFuture::observe(m_connection->isCommandSupported({"UNLINK"}))
+      .subscribe([this, returnResults](bool supportUnlink) {
+        QByteArray removalCmd{"DEL"};
+
+        if (supportUnlink) {
+          removalCmd = "UNLINK";
+        }
+
+        QtConcurrent::run(this, &DeleteOperation::deleteKeys, m_affectedKeys,
+                          removalCmd, [this, removalCmd, returnResults]() {
+                            // Retry on keys with errors
+                            if (m_keysWithErrors.size() > 0) {
+                              m_errors.clear();
+                              deleteKeys(m_keysWithErrors,
+                                         removalCmd, returnResults);
+                            } else {
+                              returnResults();
+                            }
+                          });
+      });
+}
+
+void BulkOperations::DeleteOperation::deleteKeys(
+    const QList<QByteArray> &keys, const QByteArray &rmCmd,
+    std::function<void()> callback) {
+  QList<QList<QByteArray>> rawCmds;
+
+  for (const QByteArray& k : keys) {
+    rawCmds.append({rmCmd, k});
+  }
+
+  int batchSize = m_connection->pipelineCommandsLimit();
+  int expectedResponses = rawCmds.size();
+
+  m_connection->pipelinedCmd(
+      rawCmds, this, m_dbIndex,
+      [this, expectedResponses, callback, batchSize](
+          const RedisClient::Response &r, QString err) {
+        if (!err.isEmpty() || r.isErrorMessage()) {
+          return processError(err.isEmpty() ? r.value().toByteArray() : err);
+        }
+
+        {
+          QMutexLocker l(&m_processedKeysMutex);
+          m_progress += batchSize;
+
+          emit progress(m_progress);
+        }
+
+        if (m_progress >= expectedResponses) {
+          callback();
+        }
+      },
+      false);
+}

+ 31 - 0
src/modules/bulk-operations/operations/deleteoperation.h

@@ -0,0 +1,31 @@
+#pragma once
+#include <asyncfuture.h>
+#include <QObject>
+#include <QRegExp>
+#include <QSharedPointer>
+#include "abstractoperation.h"
+
+namespace BulkOperations {
+
+class DeleteOperation : public AbstractOperation {
+  Q_OBJECT
+ public:
+  DeleteOperation(QSharedPointer<RedisClient::Connection> connection,
+                  int dbIndex, OperationCallback callback,
+                  QRegExp keyPattern = QRegExp("*", Qt::CaseSensitive,
+                                               QRegExp::Wildcard));
+
+  QString getTypeName() const override { return QString("delete_keys"); }
+
+  bool multiConnectionOperation() const override { return false; }
+
+ protected:
+  void performOperation(
+      QSharedPointer<RedisClient::Connection> targetConnection,
+      int targetDbIndex) override;
+
+  void deleteKeys(const QList<QByteArray> &keys,
+                  const QByteArray& rmCmd,
+                  std::function<void()> callback);
+};
+}  // namespace BulkOperations

+ 139 - 0
src/modules/bulk-operations/operations/rdbimport.cpp

@@ -0,0 +1,139 @@
+#include "rdbimport.h"
+
+#include <qpython.h>
+#include <qredisclient/utils/text.h>
+
+#include <QFileInfo>
+#include <QtConcurrent>
+
+BulkOperations::RDBImportOperation::RDBImportOperation(
+    QSharedPointer<RedisClient::Connection> connection, int dbIndex,
+    OperationCallback callback, QSharedPointer<QPython> p, QRegExp keyPattern)
+    : BulkOperations::AbstractOperation(connection, dbIndex, callback,
+                                        keyPattern),
+      m_python(p) {
+  m_python->importModule_sync("rdb");
+  m_errorMessagePrefix =
+      QCoreApplication::translate("RESP", "Cannot execute command ");
+}
+
+void BulkOperations::RDBImportOperation::getAffectedKeys(
+    std::function<void(QVariant, QString)> callback) {
+
+  m_keyPattern.setPatternSyntax(QRegExp::RegExp2);
+
+  if (!m_keyPattern.isValid()) {
+    return callback(QVariant(), QCoreApplication::translate(
+                                    "RESP", "Invalid regexp for keys filter."));
+  }
+
+  m_python->call_native(
+      "rdb.rdb_list_keys",
+      QVariantList{m_metadata["path"].toString(), m_metadata["db"].toInt(),
+                   m_keyPattern.pattern()},
+      [callback, this](QVariant v) {
+        m_affectedKeys.clear();
+
+        if (v.isNull()) {
+          return callback(QVariant(),
+                          QCoreApplication::translate(
+                              "RESP", "Cannot get the list of affected keys"));
+        }
+
+        QVariantList keys = v.toList();
+        QStringList keyNames;
+
+        for (const QVariant &k : qAsConst(keys)) {
+          m_affectedKeys.append(k.toByteArray());
+          keyNames.append(printableString(k.toByteArray(), true));
+        }
+
+        return callback(QVariant(keyNames), "");
+      });
+}
+
+bool BulkOperations::RDBImportOperation::isMetadataValid() const {
+  return m_metadata.contains("db") && m_metadata.contains("path") &&
+         QFileInfo::exists(m_metadata["path"].toString());
+}
+
+QList<QByteArray> convertToByteArray(QVariant v) {
+  QVariantList l = v.toList();
+
+  QList<QByteArray> result;
+
+  for (const QVariant &b : qAsConst(l)) {
+    result.append(b.toByteArray());
+  }
+
+  return result;
+}
+
+void BulkOperations::RDBImportOperation::performOperation(
+    QSharedPointer<RedisClient::Connection>, int) {
+  m_progress = 0;
+  m_errors.clear();
+
+  auto returnResults = [this]() {
+    m_callback(m_keyPattern, m_progress, m_errors);
+  };
+
+  if (m_affectedKeys.size() == 0) {
+    return returnResults();
+  }
+
+  auto processCommands = [this, returnResults](const QVariantList& commands) {
+    QList<QList<QByteArray>> rawCmds;
+
+    for (const QVariant &cmd : commands) {
+      auto rawCmd = convertToByteArray(cmd);
+
+      if (rawCmd.at(0).toLower() == QByteArray("select")) {
+        continue;
+      }
+
+      rawCmds.append(rawCmd);
+    }
+
+    int batchSize = m_connection->pipelineCommandsLimit();
+    int expectedResponses = rawCmds.size();
+
+    m_connection->pipelinedCmd(
+        rawCmds, this, m_dbIndex,
+        [this, returnResults, expectedResponses, batchSize](const RedisClient::Response& r,
+                                                 const QString& err) {
+          if (!err.isEmpty() || r.isErrorMessage()) {
+            return processError(err.isEmpty()? r.value().toByteArray() : err);
+          }
+
+          {
+            QMutexLocker l(&m_processedKeysMutex);            
+            m_progress += batchSize;
+            emit progress(m_progress);
+          }
+
+          if (m_progress >= expectedResponses) {
+            returnResults();
+          }
+        }, false);
+  };
+
+  m_python->call_native(
+      "rdb.rdb_export_as_commands",
+      QVariantList{m_metadata["path"].toString(), m_metadata["db"].toInt(),
+                   m_keyPattern.pattern()},
+      [processCommands, this](QVariant v) {
+        QVariantList commands = v.toList();
+
+        m_connection->cmd(
+            {"ping"}, this, m_dbIndex,
+            [processCommands, commands, this](const RedisClient::Response& r) {
+              if (r.isErrorMessage()) {
+                return processError(QCoreApplication::translate(
+                    "RESP", "Target connection error"));
+              }
+              QtConcurrent::run(processCommands, commands);
+            },
+            [this](const QString& err) { processError(err); });
+      });
+}

+ 38 - 0
src/modules/bulk-operations/operations/rdbimport.h

@@ -0,0 +1,38 @@
+#pragma once
+#include <asyncfuture.h>
+#include <QObject>
+#include <QRegExp>
+#include <QSharedPointer>
+#include "abstractoperation.h"
+
+class QPython;
+
+namespace BulkOperations {
+
+class RDBImportOperation : public AbstractOperation {
+  Q_OBJECT
+ public:
+  RDBImportOperation(QSharedPointer<RedisClient::Connection> connection,
+                     int dbIndex, OperationCallback callback,
+                     QSharedPointer<QPython> p,
+                     QRegExp keyPattern = QRegExp("*", Qt::CaseSensitive,
+                                                  QRegExp::Wildcard));
+
+  QString getTypeName() const override { return QString("rdb_import"); }
+
+  bool multiConnectionOperation() const override { return false; }
+
+  void getAffectedKeys(
+      std::function<void(QVariant, QString)> callback) override;
+
+  bool isMetadataValid() const override;
+
+ protected:
+  void performOperation(
+      QSharedPointer<RedisClient::Connection> targetConnection,
+      int targetDbIndex) override;
+
+ private:
+  QSharedPointer<QPython> m_python;
+};
+}  // namespace BulkOperations

+ 73 - 0
src/modules/bulk-operations/operations/ttloperation.cpp

@@ -0,0 +1,73 @@
+#include "ttloperation.h"
+
+#include <QtConcurrent>
+
+BulkOperations::TtlOperation::TtlOperation(
+    QSharedPointer<RedisClient::Connection> connection, int dbIndex,
+    OperationCallback callback, QRegExp keyPattern)
+    : BulkOperations::AbstractOperation(connection, dbIndex, callback,
+                                        keyPattern) {
+  m_errorMessagePrefix =
+      QCoreApplication::translate("RESP", "Cannot set TTL for key ");
+}
+
+void BulkOperations::TtlOperation::performOperation(
+    QSharedPointer<RedisClient::Connection>, int) {
+  m_progress = 0;
+  m_errors.clear();
+
+  auto returnResults = [this]() {
+    m_callback(m_keyPattern, m_progress, m_errors);
+  };
+
+  if (m_affectedKeys.size() == 0) {
+    return returnResults();
+  }
+
+  QByteArray ttl = m_metadata["ttl"].toString().toUtf8();
+
+  QtConcurrent::run(this, &TtlOperation::setTtl, m_affectedKeys, ttl,
+                    [this, ttl, returnResults]() {
+                      // Retry on keys with errors
+                      if (m_keysWithErrors.size() > 0) {
+                        m_errors.clear();
+                        setTtl(m_keysWithErrors, ttl,
+                               returnResults);
+                      } else {
+                        returnResults();
+                      }
+                    });
+}
+
+void BulkOperations::TtlOperation::setTtl(const QList<QByteArray>& keys,
+                                          const QByteArray& ttl,
+                                          std::function<void()> callback) {
+  QList<QList<QByteArray>> rawCmds;
+
+  for (const QByteArray& k : keys) {
+    rawCmds.append({"EXPIRE", k, ttl});
+  }
+
+  int batchSize = m_connection->pipelineCommandsLimit();
+  int expectedResponses = rawCmds.size();
+
+  m_connection->pipelinedCmd(
+      rawCmds, this, -1,
+      [this, expectedResponses, callback, batchSize](
+          const RedisClient::Response& r, QString err) {
+        if (!err.isEmpty() || r.isErrorMessage()) {
+          return processError(err.isEmpty() ? r.value().toByteArray() : err);
+        }
+
+        {
+          QMutexLocker l(&m_processedKeysMutex);
+          m_progress += batchSize;
+          emit progress(m_progress);
+        }
+
+        if (m_progress >= expectedResponses) {
+          callback();
+        }
+      },
+      false);
+}

+ 32 - 0
src/modules/bulk-operations/operations/ttloperation.h

@@ -0,0 +1,32 @@
+#pragma once
+#include <asyncfuture.h>
+#include <QObject>
+#include <QRegExp>
+#include <QSharedPointer>
+#include "abstractoperation.h"
+
+namespace BulkOperations {
+
+class TtlOperation : public AbstractOperation {
+  Q_OBJECT
+ public:
+  TtlOperation(QSharedPointer<RedisClient::Connection> connection, int dbIndex,
+               OperationCallback callback,
+               QRegExp keyPattern = QRegExp("*", Qt::CaseSensitive,
+                                            QRegExp::Wildcard));
+
+  QString getTypeName() const override { return QString("ttl"); }
+
+  bool multiConnectionOperation() const override { return false; }
+
+  bool isMetadataValid() const override { return m_metadata.contains("ttl"); }
+
+ protected:
+  void performOperation(
+      QSharedPointer<RedisClient::Connection> targetConnection,
+      int targetDbIndex) override;
+
+
+  void setTtl(const QList<QByteArray> &keys, const QByteArray &ttl, std::function<void()> callback);
+};
+}  // namespace BulkOperations

+ 26 - 0
src/modules/common/baselistmodel.cpp

@@ -0,0 +1,26 @@
+#include "baselistmodel.h"
+
+BaseListModel::BaseListModel(QObject *parent)
+    : QAbstractListModel(parent)
+{
+
+}
+
+QVariantMap BaseListModel::getRowRaw(int row)
+{
+    QHash<int,QByteArray> names = roleNames();    
+    QHashIterator<int, QByteArray> i(names);
+    QVariantMap res;
+
+    while (i.hasNext()) {
+        i.next();
+
+        if (i.value() == "display")
+            continue;
+
+        QModelIndex idx = index(row);
+        QVariant d = data(idx, i.key());
+        res[i.value()] = d;
+    }
+    return res;
+}

Some files were not shown because too many files changed in this diff