Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
RedisHashDatabase.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* RedisHashDatabase.cc (C) 2000-2023 */
9/* */
10/* File system managed hash database. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/TraceAccessor.h"
15#include "arcane/utils/Array.h"
16#include "arcane/utils/FatalErrorException.h"
17
18#include "arcane/std/internal/IHashDatabase.h"
19#include "arcane/std/internal/IRedisContext.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30class RedisHashDatabase
31: public TraceAccessor
32, public IHashDatabase
33{
34 public:
35
36 RedisHashDatabase(ITraceMng* tm, const String& machine_name, Int32 port)
37 : TraceAccessor(tm)
38 , m_context(createRedisContext(tm))
39 {
40 ARCANE_CHECK_POINTER(m_context.get());
41 m_context->open(machine_name, port);
42 }
43 ~RedisHashDatabase()
44 {
45 }
46
47 public:
48
49 void writeValues(const HashDatabaseWriteArgs& args, HashDatabaseWriteResult& xresult) override
50 {
51 // TODO: only write if the key is not present
52 m_context->sendBuffer(args.hashValue(), args.values());
53 xresult.setHashValueAsString(args.hashValue());
54 }
55
56 void readValues(const HashDatabaseReadArgs& args) override
57 {
59 m_context->getBuffer(args.hashValueAsString(), bytes);
60 if (bytes.size() != args.values().size())
61 ARCANE_FATAL("Bad size expected={0} actual={1}", args.values().size(), bytes.size());
62 args.values().copy(bytes);
63 }
64
65 private:
66
67 Ref<IRedisContext> m_context;
68};
69
70/*---------------------------------------------------------------------------*/
71/*---------------------------------------------------------------------------*/
72
73extern "C++" Ref<IHashDatabase>
74createRedisHashDatabase(ITraceMng* tm, const String& machine_ip, Int32 port)
75{
76 return makeRef<IHashDatabase>(new RedisHashDatabase(tm, machine_ip, port));
77}
78
79/*---------------------------------------------------------------------------*/
80/*---------------------------------------------------------------------------*/
81
82} // namespace Arcane
83
84/*---------------------------------------------------------------------------*/
85/*---------------------------------------------------------------------------*/
#define ARCANE_CHECK_POINTER(ptr)
Macro returning the pointer ptr if it is not null or throwing an exception if it is null.
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Reference to an instance.
__host__ __device__ void copy(const U &copy_array)
Copies the array copy_array into the instance.
Definition Span.h:477
constexpr __host__ __device__ SizeType size() const noexcept
Returns the size of the array.
Definition Span.h:327
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
1D data vector with value semantics (STL style).
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Creates a reference on a pointer.
std::int32_t Int32
Signed integer type of 32 bits.