diff --git a/src/storage/rocksdb.cpp b/src/storage/rocksdb.cpp index fe2e7cbf5..eb6a7a7fa 100644 --- a/src/storage/rocksdb.cpp +++ b/src/storage/rocksdb.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "../server.h" #include "../cluster.h" #include "rocksdbfactor_internal.h" @@ -230,7 +231,8 @@ void RocksDBStorageProvider::setExpire(const char *key, size_t cchKey, long long { rocksdb::Status status; std::unique_lock l(m_lock); - std::string prefix((const char *)&expire,sizeof(long long)); + long long beExpire = htonll(expire); + std::string prefix((const char *)&beExpire,sizeof(long long)); std::string strKey(key, cchKey); if (m_spbatch != nullptr) status = m_spbatch->Put(m_spexpirecolfamily.get(), rocksdb::Slice(prefix + strKey), rocksdb::Slice(strKey)); @@ -244,7 +246,8 @@ void RocksDBStorageProvider::removeExpire(const char *key, size_t cchKey, long l { rocksdb::Status status; std::unique_lock l(m_lock); - std::string prefix((const char *)&expire,sizeof(long long)); + long long beExpire = htonll(expire); + std::string prefix((const char *)&beExpire,sizeof(long long)); std::string strKey(key, cchKey); std::string fullKey = prefix + strKey; if (!FExpireExists(fullKey)) diff --git a/src/storage/rocksdb.h b/src/storage/rocksdb.h index 094e085b4..564c9a432 100644 --- a/src/storage/rocksdb.h +++ b/src/storage/rocksdb.h @@ -4,7 +4,13 @@ #include "../IStorage.h" #include #include +#ifdef __APPLE__ +#include +#define htole16(x) OSSwapHostToLittleInt16(x) +#define le16toh(x) OSSwapLittleToHostInt16(x) +#else #include +#endif #include "../fastlock.h" #define INTERNAL_KEY_PREFIX "\x00\x04\x03\x00\x05\x02\x04"