Description
Changelog
Reviews (0)

GodotRedis

  • Native Redis plugin for Godot 4.6+ with redis-py style syntax. Powered by GDExtension, hiredis and C++ library, it delivers far better performance than pure GDScript implementations.
  • Godot 4.6+ 原生高性能 Redis 客户端,采用 redis-py 风格 API。基于 GDExtension、hiredis、C++ 构建,速度极快、延迟极低。

Core Features | 功能介绍

  • Redis-py Compatible API: Nearly identical method names and usage to Python's redis-py — start coding in seconds
  • Native Performance: C-backed low-latency implementation, drastically outperforms script-based clients
  • Built-in Connection Pool: Production-grade connection management out of the box
  • Full Command Coverage: Strings, Hashes, Lists, Sets, Sorted Sets and common commands
  • Cross-Platform Codebase: Core logic supports Windows / Linux / macOS in principle

Compatibility & Platform Note | 平台兼容性

  • Supported Engine: Godot 4.6+ (GDExtension)
  • Redis Server: 5.x / 6.x / 7.x fully compatible
  • Precompiled Binary Included: Windows x64
  • Other Platforms: Linux, macOS builds are available on request. Source code can also be provided upon request.

Quick Start: GDScript | 使用示例

  • Drop the addons folder into your project root. The plugin activates automatically with no extra setup required.
  • addons 文件夹放入项目根目录,插件自动激活,无需额外配置。
var Redis0: Redis = Redis.new()
var Redis1: Redis = Redis.new()


func _enter_tree() -> void:
    # Connect to database 0 | 连接到 0 号数据库
    if not Redis0.connect(host: String = "127.0.0.1", port: int = 6379, password: String = "", database: int = 0, timeout_ms: int = 3000, max_connections: int = 10):
        print("❌ Redis0: connection failed | 连接失败")
    else:
        print("✅ Redis0: connected successfully | 连接成功")

    # Connect to database 1 | 连接到 1 号数据库
    if not Redis1.connect("127.0.0.1", 6379, "", 1, 3000, 10):
        print("❌ Redis1: connection failed | 连接失败")
    else:
        print("✅ Redis1: connected successfully | 连接成功")
    randomize()


# Release all connections | 释放所有连接
func _exit_tree() -> void:
    Redis0.disconnect()
    Redis1.disconnect()



# demo code | 参考示例
func Test_Request_():
    # Set key value | 设置键值对 (returns bool)
    await Redis0.set("player","Tom")

    # Get value by key | 根据键获取值 (returns String | false if key not exists)
    var player_name: Variant = await Redis0.get("player")

    # Increment value by step | 按步长自增数值 (returns int: new value)
    var new_score: int = await Redis0.incrby("score", 50)

    # Check if key exists | 检查键是否存在 (returns bool)
    var is_exists: int = await Redis0.exists("player")

    # Delete key | 删除键 (returns bool)
    await Redis0.del("player")

    # Set key expire time in seconds | 设置键的过期时间(秒) (returns int)
    await Redis0.expire("player", "score", 3600)

    # Get remaining TTL in seconds | 获取剩余过期时间(秒) (returns int)
    var ttl: int = await Redis0.ttl("player")

    # Batch set fields via dictionary | 通过字典批量设置字段 (returns int | bool)
    await Redis0.hset("player", "level", 30)
    await Redis0.hmset("player", Dictionary)

    # Get single field value | 获取单个字段值 (returns Variant | false if field not exists)
    var level: Variant = await Redis0.hget("player","stats", "level")

    # Get all fields and values | 获取所有字段与值 (returns Dictionary)
    var stats: Dictionary = await Redis0.hgetall("player")

    # Delete single field | 删除单个字段 (returns bool)
    await Redis0.hdel("player", stats")

Function List | 函数列表

For List Functions, Please Refer to the Built-in Documentation

  • bool connect(host: String = "127.0.0.1", port: int = 6379, password: String = "", database: int = 0, timeout_ms: int = 3000, max_connections: int = 10)
  • Signal decr(key: String)
  • Signal decrby(key: String, decrement: int)
  • Signal del(key: String)
  • void disconnect()
  • Signal execute_command(command: String, args: Array = [])
  • Signal exists(key: String)
  • Signal expire(key: String, seconds: int)
  • Signal get(key: String)
  • Signal hdel(key: String, field: String)
  • Signal hexists(key: String, field: String)
  • Signal hget(key: String, field: String)
  • Signal hgetall(key: String)
  • Signal hkeys(key: String)
  • Signal hlen(key: String)
  • Signal hmset(key: String, mapping: Dictionary)
  • Signal hset(key: String, field_or_dict: Variant, value: Variant = null)
  • Signal hvals(key: String)
  • Signal incr(key: String)
  • Signal incrby(key: String, increment: int)
  • bool is_connected() const
  • Signal keys(pattern: String = "*")
  • Signal llen(key: String)
  • Signal lpop(key: String)
  • Signal lpush(key: String, value: Variant)
  • Signal lrange(key: String, start: int, end: int)
  • Signal rpop(key: String)
  • Signal rpush(key: String, value: Variant)
  • Signal sadd(key: String, value: Variant)
  • Signal scard(key: String)
  • Signal set(key: String, value: Variant, ex: int = -1, px: int = -1, nx: bool = false, xx: bool = false)
  • Signal sismember(key: String, value: Variant)
  • Signal smembers(key: String)
  • Signal srem(key: String, value: Variant)
  • Signal ttl(key: String)
  • Signal zadd(key: String, score: float, member: String)
  • Signal zcard(key: String)
  • Signal zrange(key: String, start: int, stop: int, withscores: bool = false)
  • Signal zrem(key: String, member: String)
  • Signal zrevrange(key: String, start: int, stop: int, withscores: bool = false)
  • Signal zscore(key: String, member: String)

Feedback | 问题反馈

Changelog for version v1.0.0

No changelog provided for this version.

Reviews

GodotRedis has no reviews yet.

Login to write a review.