Skip to content

Commit

Permalink
Add support for JSON serialized memcache & confdata values (#1107)
Browse files Browse the repository at this point in the history
  • Loading branch information
apolyakov authored Oct 9, 2024
1 parent c89c757 commit bed2e4d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
11 changes: 8 additions & 3 deletions runtime/memcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

#include "runtime/memcache.h"

#include "runtime-core/utils/kphp-assert-core.h"
#include "runtime/array_functions.h"
#include "runtime/math_functions.h"
#include "runtime/json-functions.h"
#include "runtime/net_events.h"
#include "runtime/serialize-functions.h"
#include "runtime/zlib.h"
#include "server/php-queries.h"
Expand Down Expand Up @@ -154,14 +156,17 @@ mixed mc_get_value(const char *result_str, int32_t result_str_len, int64_t flags
mixed result;
if (flags & MEMCACHE_COMPRESSED) {
flags ^= MEMCACHE_COMPRESSED;
string::size_type uncompressed_len;
result_str = gzuncompress_raw({result_str, static_cast<size_t>(result_str_len)}, &uncompressed_len);
string::size_type uncompressed_len = 0;
result_str = gzuncompress_raw({result_str, static_cast<string::size_type>(result_str_len)}, &uncompressed_len);
result_str_len = uncompressed_len;
}

if (flags & MEMCACHE_SERIALIZED) {
flags ^= MEMCACHE_SERIALIZED;
result = unserialize_raw(result_str, result_str_len);
} else if (flags & MEMCACHE_JSON_SERIALIZED) {
flags ^= MEMCACHE_JSON_SERIALIZED;
result = json_decode({result_str, static_cast<string::size_type>(result_str_len)}).first;
} else {
result = string(result_str, result_str_len);
}
Expand Down
12 changes: 4 additions & 8 deletions runtime/memcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@

#pragma once

#include <utility>
#include <cstdint>

#include "common/algorithms/hashes.h"
#include "common/wrappers/string_view.h"
#include "runtime-core/runtime-core.h"
#include "runtime/dummy-visitor-methods.h"
#include "runtime/exception.h"
#include "runtime/memory_usage.h"
#include "runtime/net_events.h"
#include "runtime/resumable.h"
#include "runtime/rpc.h"

void init_memcache_lib();
void free_memcache_lib();
Expand All @@ -25,9 +21,9 @@ mixed mc_get_value(const char *result_str, int32_t result_str_len, int64_t flags

bool mc_is_immediate_query(const string &key);


constexpr int64_t MEMCACHE_SERIALIZED = 1;
constexpr int64_t MEMCACHE_COMPRESSED = 2;
inline constexpr int64_t MEMCACHE_SERIALIZED = 1U << 0U;
inline constexpr int64_t MEMCACHE_COMPRESSED = 1U << 1U;
inline constexpr int64_t MEMCACHE_JSON_SERIALIZED = 1U << 4U;

struct C$Memcache : public abstract_refcountable_php_interface {
public:
Expand Down

0 comments on commit bed2e4d

Please sign in to comment.