QF yerine Redis kullanmak

  • Konbuyu başlatan Konbuyu başlatan Admin
  • Başlangıç tarihi Başlangıç tarihi
  • Cevaplar Cevaplar 0
  • Görüntüleme Görüntüleme 80

Admin

Metin2Lobby
Yönetici
Founder
Katılım
6 Mayıs 2022
Mesajlar
52,647
Ticaret : 1 / 0 / 0


Bu konuda redis veritabanına mantıksal olarak yani pratikte nasıl geçileceğini anlatacağım, yanlış anlaşılma olmaması adına bazı şeyleri düzeltmek zorundayım, yani tamamen bir geçiş işlemi içermemektedir.

Neden Redis?

📦 MySQL (veya MariaDB)


  • <li data-xf-list-type="ul">Kalıcı veriler tutulur:
    • <li data-xf-list-type="ul">shop_item <li data-xf-list-type="ul">karakter bilgileri <li data-xf-list-type="ul">eşya bilgileri <li data-xf-list-type="ul">fiyatlar, vnumlar, moblar, vs.
    <li data-xf-list-type="ul">Oyuncu oyundan çıksa bile veriler kaybolmaz.

⚡

  • <li data-xf-list-type="ul">Geçici/verimli erişim gereken şeylerde kullanılır (qf gibi):
    • <li data-xf-list-type="ul">cooldown’lar <li data-xf-list-type="ul">aktif GM komutları <li data-xf-list-type="ul">hızlı sayaçlar
<blockquote data-attributes="" data-quote="" data-source="" class="bbCodeBlock bbCodeBlock--expandable bbCodeBlock--quote js-expandWatch">
Kod:
-- Oyuncunun günlük giriş bonusunu alıp almadığını kontrol ediyorsun if pc.getf("login_reward", "taken") == 1 then     return end pc.setf("login_reward", "taken", 1)

Questflag yerine Redis kullanacak olursak:


Kod:
local key = string.format("reward:daily:%d", pc.get_player_id()) if redis.exists(key) then     return end redis.setex(key, 86400, 1) -- 1 gün geçerli

Bir başka örnek ile daha açıklamaya çalışalım;

Bekleme süresi olayı (eski hali)

Kod:
if get_global_time() &lt; pc.getf("teleport", "cooldown") then     syschat("Bekleme süresi var.")     return end pc.setf("teleport", "cooldown", get_global_time() + 30)

Redis (yeni hali)

Kod:
local key = string.format("teleport_cd:%d", pc.get_player_id()) local ttl = redis.ttl(key) if ttl &gt; 0 then     syschat(string.format("Bekleme süresi var: %d sn", ttl))     return end redis.setex(key, 30, 1) syschat("Teleport edildin.")

<blockquote data-attributes="" data-quote="" data-source="" class="bbCodeBlock bbCodeBlock--expandable bbCodeBlock--quote js-expandWatch is-expandable">
Kod:
#include "stdafx.h" #include &lt;lua.hpp&gt; #include &lt;string&gt; #include &lt;sw/redis++/redis++.h&gt; using namespace sw::redis; static std::shared_ptr&lt;Redis&gt; g_redis; void InitRedisConnection() {     if (!g_redis) {         try {             g_redis = std::make_shared&lt;Redis&gt;("tcp://127.0.0.1:6379");         } catch (const std::exception&amp; e) {             sys_err("Redis connection failed: %s", e.what());         }     } } // redis.set(key, value) int lua_redis_set(lua_State* L) {     const char* key = luaL_checkstring(L, 1);     const char* value = luaL_checkstring(L, 2);     InitRedisConnection();     g_redis-&gt;set(key, value);     return 0; } // redis.setex(key, seconds, value) int lua_redis_setex(lua_State* L) {     const char* key = luaL_checkstring(L, 1);     int seconds = luaL_checkinteger(L, 2);     const char* value = luaL_checkstring(L, 3);     InitRedisConnection();     g_redis-&gt;setex(key, std::chrono::seconds(seconds), value);     return 0; } // redis.get(key) int lua_redis_get(lua_State* L) {     const char* key = luaL_checkstring(L, 1);     InitRedisConnection();     auto val = g_redis-&gt;get(key);     if (val) {         lua_pushstring(L, val-&gt;c_str());     } else {         lua_pushnil(L);     }     return 1; } // redis.exists(key) int lua_redis_exists(lua_State* L) {     const char* key = luaL_checkstring(L, 1);     InitRedisConnection();     bool exists = g_redis-&gt;exists(key) &gt; 0;     lua_pushboolean(L, exists);     return 1; } // redis.del(key) int lua_redis_del(lua_State* L) {     const char* key = luaL_checkstring(L, 1);     InitRedisConnection();     g_redis-&gt;del(key);     return 0; } // redis.ttl(key) int lua_redis_ttl(lua_State* L) {     const char* key = luaL_checkstring(L, 1);     InitRedisConnection();     auto ttl = g_redis-&gt;ttl(key);     if (ttl) {         lua_pushinteger(L, static_cast&lt;int&gt;(ttl-&gt;count()));     } else {         lua_pushinteger(L, -1); // -1 = sonsuz     }     return 1; } // Kayıt void RegisterRedisFunctions(lua_State* L) {     lua_getglobal(L, "redis");     if (lua_isnil(L, -1)) {         lua_newtable(L);         lua_setglobal(L, "redis");     }     lua_getglobal(L, "redis");     lua_pushcfunction(L, lua_redis_set);     lua_setfield(L, -2, "set");     lua_pushcfunction(L, lua_redis_setex);     lua_setfield(L, -2, "setex");     lua_pushcfunction(L, lua_redis_get);     lua_setfield(L, -2, "get");     lua_pushcfunction(L, lua_redis_exists);     lua_setfield(L, -2, "exists");     lua_pushcfunction(L, lua_redis_del);     lua_setfield(L, -2, "del");     lua_pushcfunction(L, lua_redis_ttl);     lua_setfield(L, -2, "ttl");     lua_pop(L, 1); }

Nasıl Çağıracaksın?

<blockquote data-attributes="" data-quote="" data-source="" class="bbCodeBlock bbCodeBlock--expandable bbCodeBlock--quote js-expandWatch is-expandable">
Kod:
// questlua.cpp içinde lua_init fonksiyonunun en altına ekle: RegisterRedisFunctions(L); ve dahil et extern void RegisterRedisFunctions(lua_State* L);
Kod:
local key = string.format("cd:move:%d", pc.get_player_id()) if redis.exists(key) then     local kalan = redis.ttl(key)     syschat("Bekleme süresi var: "..kalan.." sn")     return end redis.setex(key, 30, "1") syschat("Işınlandın.")



QF Yerine Redis Kullanmak: Metin2 Geliştiricileri İçin Güçlü ve Hızlı Bir Alternatif

Redis, özellikle büyük ölçekli Metin2 sunucularında performans artışı sağlayabilecek güçlü bir önbellekleme çözümüdür. Bu yazıda, klasik Queue Framework (QF) yerine Redis'in neden daha avantajlı olabileceği, nasıl entegre edileceği ve Metin2 özel sunucu sistemleri üzerindeki etkisi incelenmektedir.

Queue Framework (QF) Nedir?
Queue Framework, Metin2 özel sunucularında veri akışlarını yönetmek, istemci ile sunucu arasında mesajlaşma sağlamak ve oyun içi işlemlerin senkronize çalışmasını sağlamak için yaygın olarak kullanılan bir sistemdir. Özellikle Auth ve Game sunucuları arasında veri aktarımı yapılırken kullanılır. Ancak QF, yüksek trafik altında yavaşlamaya ve gecikmelere neden olabilir. Bu durum, özellikle PVP yoğun oyun sunucularında kullanıcı deneyimini olumsuz etkileyebilir.

Redis Nedir ve Neden Kullanılır?
Redis (Remote Dictionary Server), açık kaynaklı, bellek tabanlı veri yapısı deposudur. Yüksek hızda okuma/yazma işlemleri yapabilir ve farklı veri yapılarını destekler (string, list, set, hash vb.). Metin2 özel sunucularında Redis, veri paylaşımını kolaylaştırır, veritabanı yükünü azaltır ve QF gibi eski sistemlerin yerine daha hızlı bir alternatif sunar.

Redis'in Avantajları
Yüksek Performans: Bellek tabanlı olması sayesinde veri erişimi çok hızlıdır. Bu, Metin2 gibi gerçek zamanlı oyunlarda önemli bir artıdır.
Yüksek Eşzamansızlık: Redis, çoklu işlem desteğiyle aynı anda binlerce isteği karşılayabilir. Bu da yoğun oyuncu trafiği sırasında stabilite sağlar.
Veri Paylaşımı: Auth, Game, DB gibi farklı servisler Redis üzerinden veri alışverişinde bulunabilir. Bu, sistem mimarisini daha sade ve yönetilebilir kılar.

Redis Nasıl Entegre Edilir?
Metin2 özel sunucularda Redis entegrasyonu için Python veya C++ tabanlı Redis kütüphaneleri kullanılabilir. Örneğin hiredis (C/C++) veya redis-py (Python) gibi kütüphaneler ile kolayca bağlantı sağlanabilir. Oyun içindeki olaylar, oyuncu envanterleri, eşya transferleri gibi veriler Redis üzerinde tutulabilir. Bu sayede veritabanı ile olan iletişim azaltılmış olur.

QF ile Redis Karşılaştırması
Gecikme Süresi: QF, veri iletiminde bazı gecikmeler yaşayabilir. Redis ise düşük gecikme süresiyle veri aktarımı sağlar.
Esneklik: Redis, farklı veri yapılarını desteklediği için daha esnek kullanım imkanı sunar. QF sadece belirli mesaj tipleriyle sınırlıdır.
Yönetilebilirlik: Redis, komut satırı arayüzü ile kolayca izlenebilir ve yönetilebilir. QF’in bu konuda daha sınırlı bir arayüzü vardır.

Metin2 Geliştiricileri İçin Pratik Uygulamalar
Envanter Verileri: Oyuncu envanteri Redis üzerinde tutulabilir. Bu sayede oyun sunucusu ile veri alışverişi hızlı olur.
Oyuncu Bilgileri: Oyuncuların level, gold, exp gibi verileri Redis üzerinde tutularak veritabanı sorguları azaltılabilir.
PVP Sistemleri: PVP skorları, turnuva verileri gibi dinamik veriler Redis ile hızlıca güncellenebilir ve okunabilir.

Sonuç
Queue Framework (QF), uzun yıllardır Metin2 özel sunucularında güvenilir bir yöntemdi ancak modern sistemlerde Redis gibi teknolojiler çok daha yüksek performans ve esneklik sunmaktadır. Özellikle PVP yoğun sistemlerde, C++ veya Python tabanlı Redis entegrasyonu, sunucu verimliliğini ciddi anlamda artırabilir. Metin2 geliştiricileri, QF yerine Redis kullanmayı düşünerek hem sistemlerini optimize edebilir hem de oyunculara daha iyi bir deneyim sunabilirler.


Using Redis Instead of QF: A Powerful and Fast Alternative for Metin2 Developers

Redis is a powerful caching solution that can significantly improve performance on large-scale Metin2 servers. This article examines why Redis may be more advantageous than the traditional Queue Framework (QF), how it can be integrated, and its impact on Metin2 private server systems.

What is Queue Framework (QF)?
Queue Framework is a system widely used in Metin2 private servers to manage data flows, enable messaging between client and server, and ensure synchronized execution of in-game operations. It is particularly used during data transfers between Auth and Game servers. However, QF can cause slowdowns and delays under high traffic, which can negatively affect user experience, especially in PVP-intensive game servers.

What is Redis and Why Should You Use It?
Redis (Remote Dictionary Server) is an open-source, memory-based data structure store. It performs read/write operations at high speed and supports various data structures (strings, lists, sets, hashes, etc.). In Metin2 private servers, Redis facilitates data sharing, reduces database load, and offers a faster alternative to older systems like QF.

Advantages of Redis
High Performance: Being memory-based allows for very fast data access, which is crucial for real-time games like Metin2.
High Concurrency: With multi-operation support, Redis can handle thousands of requests simultaneously, ensuring stability during high player traffic.
Data Sharing: Different services such as Auth, Game, and DB can exchange data via Redis, simplifying and making the system architecture more manageable.

How to Integrate Redis?
Redis integration in Metin2 private servers can be achieved using Redis libraries based on Python or C++. Libraries such as hiredis (C/C++) or redis-py (Python) allow easy connection. Events within the game, player inventories, item transfers, etc., can be stored on Redis, thereby reducing communication with the database.

QF vs Redis Comparison
Latency Time: QF may experience some delays during data transmission. Redis provides low-latency data transfer.
Flexibility: Since Redis supports different data structures, it offers more flexible usage. QF is limited to specific message types.
Manageability: Redis can be easily monitored and managed through a command-line interface. QF has more limited interface options in this regard.

Practical Applications for Metin2 Developers
Inventory Data: Player inventory can be stored on Redis, allowing fast data exchange with the game server.
Player Information: Player data such as level, gold, and exp can be stored on Redis to reduce database queries.
PVP Systems: Dynamic data like PVP scores and tournament records can be quickly updated and read using Redis.

Conclusion
While Queue Framework (QF) has been a reliable method for Metin2 private servers for many years, modern technologies like Redis offer much higher performance and flexibility. Especially in PVP-intensive systems, integrating Redis based on C++ or Python can significantly enhance server efficiency. Metin2 developers can optimize their systems and provide better experiences for players by considering Redis as a replacement for QF.
 

Şuan Bu Konuyu Görüntüleyen Kullanıcılar (Toplam : 0, Üye : 0, Misafir : 0)

Benzer konular

Geri
Üst Alt