From c1740b2223635d7500e5e034d47a3ca9178d1c5a Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Sun, 26 Apr 2020 20:33:04 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B8=D0=BC=D0=B5=D1=80=20=D0=BA?= =?UTF-8?q?=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D0=B0=20=D0=B4=D0=BB=D1=8F=20Red?= =?UTF-8?q?is?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/redis.old/01_client/client.hpp | 89 ------------------- .../01_client/CMakeLists.txt | 5 +- .../{redis.old => redis}/01_client/client.cpp | 9 +- examples/redis/01_client/client.hpp | 32 +++++++ examples/{redis.old => redis}/CMakeLists.txt | 0 5 files changed, 43 insertions(+), 92 deletions(-) delete mode 100644 examples/redis.old/01_client/client.hpp rename examples/{redis.old => redis}/01_client/CMakeLists.txt (95%) rename examples/{redis.old => redis}/01_client/client.cpp (63%) create mode 100644 examples/redis/01_client/client.hpp rename examples/{redis.old => redis}/CMakeLists.txt (100%) diff --git a/examples/redis.old/01_client/client.hpp b/examples/redis.old/01_client/client.hpp deleted file mode 100644 index 29cb080..0000000 --- a/examples/redis.old/01_client/client.hpp +++ /dev/null @@ -1,89 +0,0 @@ -#include -#include - -#include - -namespace MR = myx::redis; - -class RedisClient : public QObject -{ - Q_OBJECT - - MR::Client m_client; - MR::Client m_subscribe; - MR::Request* m_request; - MR::Request* m_channel; - -public: - RedisClient( QObject* parent = nullptr ) : - QObject( parent ) - { - connect( &m_client, &MR::Client::connected, this, &RedisClient::slotConnected ); - connect( &m_subscribe, &MR::Client::connected, this, &RedisClient::slotStartSubscribe ); - m_client.connectToHost( "127.0.0.1" ); - m_subscribe.connectToHost( "127.0.0.1" ); - } - - - virtual ~RedisClient() {} - - Q_SLOT void slotStartSubscribe() - { - m_channel = m_subscribe.subscribeToChannel( "test" ); - connect( m_channel, &MR::Request::reply, this, &RedisClient::slotSubscribeTest ); - } - - - Q_SLOT void slotSubscribeTest( MR::Reply reply ) - { - qDebug() << static_cast< int >( reply.type() ); - auto& v = reply.value(); - if ( !v.canConvert< QVariantList >() ) { return; } - - auto l = v.toList(); - for ( auto& a: l ) - { - qDebug() << a.value< MR::Reply >().value().toByteArray(); - } - } - - - Q_SLOT void slotConnected() - { - m_request = m_client.sendCommand( "PING" ); - connect( m_request, &MR::Request::reply, this, &RedisClient::slotPong ); - } - - - Q_SLOT void slotPong( MR::Reply reply ) - { - qDebug() << static_cast< int >( reply.type() ); - qDebug() << reply.value().toString(); - m_request->disconnect(); - m_request->deleteLater(); - - m_request = m_client.sendCommand( "SET value 10" ); - connect( m_request, &MR::Request::reply, this, &RedisClient::slotSetValue ); - } - - - Q_SLOT void slotSetValue( MR::Reply reply ) - { - qDebug() << static_cast< int >( reply.type() ); - qDebug() << reply.value().toString(); - m_request->disconnect(); - m_request->deleteLater(); - - m_request = m_client.sendCommand( "GET value" ); - connect( m_request, &MR::Request::reply, this, &RedisClient::slotGetValue ); - } - - - Q_SLOT void slotGetValue( MR::Reply reply ) - { - qDebug() << static_cast< int >( reply.type() ); - qDebug() << reply.value().toByteArray(); - m_request->disconnect(); - m_request->deleteLater(); - } -}; // class RedisClient diff --git a/examples/redis.old/01_client/CMakeLists.txt b/examples/redis/01_client/CMakeLists.txt similarity index 95% rename from examples/redis.old/01_client/CMakeLists.txt rename to examples/redis/01_client/CMakeLists.txt index 66c16c9..bc9f579 100644 --- a/examples/redis.old/01_client/CMakeLists.txt +++ b/examples/redis/01_client/CMakeLists.txt @@ -60,8 +60,9 @@ endif() if(MYXLIB_BUILD_EXAMPLES_HO) set(REDIS_LIB_DIR ${CMAKE_SOURCE_DIR}/src/myx/redis) - set(REDIS_moc_hpp ${REDIS_LIB_DIR}/client.hpp ${REDIS_LIB_DIR}/lexer.hpp ${REDIS_LIB_DIR}/parser.hpp - ${REDIS_LIB_DIR}/request.hpp) + set(REDIS_moc_hpp ${REDIS_LIB_DIR}/base.hpp + ${REDIS_LIB_DIR}/containers.hpp + ${REDIS_LIB_DIR}/pubsub.hpp) qt5_wrap_cpp(REDIS_moc_cpp ${REDIS_moc_hpp}) diff --git a/examples/redis.old/01_client/client.cpp b/examples/redis/01_client/client.cpp similarity index 63% rename from examples/redis.old/01_client/client.cpp rename to examples/redis/01_client/client.cpp index befda50..0fda55f 100644 --- a/examples/redis.old/01_client/client.cpp +++ b/examples/redis/01_client/client.cpp @@ -1,12 +1,19 @@ #include "client.hpp" +#include + #include #include +namespace MR = myx::redis; + int main( int argc, char** argv ) { QCoreApplication app( argc, argv ); - RedisClient client; + + MR::PubSub a; + RedisClient c( &a ); + a.start(); return( QCoreApplication::exec() ); } // main diff --git a/examples/redis/01_client/client.hpp b/examples/redis/01_client/client.hpp new file mode 100644 index 0000000..432a015 --- /dev/null +++ b/examples/redis/01_client/client.hpp @@ -0,0 +1,32 @@ +#include +#include + + #include + +namespace MR = myx::redis; + +class RedisClient : public QObject +{ + Q_OBJECT + +public: + explicit RedisClient( MR::PubSub* p, QObject* o = nullptr ) : + QObject( o ) + { + p->subscribe( "test", this, "readChannelTest" ); + } + + +private: + Q_INVOKABLE void readChannelTest( const QString& channel, const QByteArray& message ) + { + qDebug() << channel; + qDebug() << message; + + if ( message == "quit" ) + { + qCritical() << message; + qApp->quit(); + } + } +}; // class RedisClient diff --git a/examples/redis.old/CMakeLists.txt b/examples/redis/CMakeLists.txt similarity index 100% rename from examples/redis.old/CMakeLists.txt rename to examples/redis/CMakeLists.txt