mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-26 18:42:41 +01:00
added Redis library
This commit is contained in:
135
Redis/src/RedisStream.cpp
Normal file
135
Redis/src/RedisStream.cpp
Normal file
@@ -0,0 +1,135 @@
|
||||
//
|
||||
// RedisStream.cpp
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Library: Redis
|
||||
// Package: Redis
|
||||
// Module: RedisStream
|
||||
//
|
||||
// Implementation of the RedisStream class.
|
||||
//
|
||||
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Redis/RedisStream.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Redis {
|
||||
|
||||
|
||||
//
|
||||
// RedisStreamBuf
|
||||
//
|
||||
|
||||
|
||||
RedisStreamBuf::RedisStreamBuf(Net::StreamSocket& redis):
|
||||
BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::in | std::ios::out),
|
||||
_redis(redis)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
RedisStreamBuf::~RedisStreamBuf()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int RedisStreamBuf::readFromDevice(char* buffer, std::streamsize len)
|
||||
{
|
||||
return _redis.receiveBytes(buffer, len);
|
||||
}
|
||||
|
||||
|
||||
int RedisStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
|
||||
{
|
||||
return _redis.sendBytes(buffer, length);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// RedisIOS
|
||||
//
|
||||
|
||||
|
||||
RedisIOS::RedisIOS(Net::StreamSocket& redis):
|
||||
_buf(redis)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
RedisIOS::~RedisIOS()
|
||||
{
|
||||
try
|
||||
{
|
||||
_buf.sync();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
RedisStreamBuf* RedisIOS::rdbuf()
|
||||
{
|
||||
return &_buf;
|
||||
}
|
||||
|
||||
|
||||
void RedisIOS::close()
|
||||
{
|
||||
_buf.sync();
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// RedisOutputStream
|
||||
//
|
||||
|
||||
|
||||
RedisOutputStream::RedisOutputStream(Net::StreamSocket& redis):
|
||||
RedisIOS(redis),
|
||||
std::ostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
RedisOutputStream::~RedisOutputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
RedisInputStream::RedisInputStream(Net::StreamSocket& redis):
|
||||
RedisIOS(redis),
|
||||
std::istream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// RedisInputStream
|
||||
//
|
||||
|
||||
|
||||
RedisInputStream::~RedisInputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
std::string RedisInputStream::getline()
|
||||
{
|
||||
std::string line;
|
||||
std::getline(*this, line);
|
||||
if ( line.size() > 0 ) line.erase(line.end() - 1);
|
||||
return line;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Redis
|
||||
Reference in New Issue
Block a user