跳转到主要内容

缓存批量查询

一次查询多个缓存值的 API。

URL 确认

此 API 使用 service-api.playnanoo.com 域名。

API 信息

  • URL: https://service-api.playnanoo.com/cache/v20241201/mget
  • Method: PUT
  • 需要认证: 是

请求参数

参数类型必需说明
cache_keysList\<string>必需要查询的缓存键列表
DeviceInfo 继承

此 API 的 Req 类继承自 DeviceInfo。DeviceInfo 的所有属性将自动包含。

响应数据

Res 类

字段类型说明
ItemsList\<CacheItems>缓存项目列表

CacheItems 结构

字段类型说明
keystring缓存键
valuestring缓存值

Unity C# 实现

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Networking;

public class CacheMultiGet
{
static string path = "https://service-api.playnanoo.com/cache/v20241201/mget";

[Serializable]
public class Req : DeviceInfo
{
public List<string> cache_keys;

public IEnumerator Send(List<string> cacheKeys, Action<Res> onSuccess, Action<BaseResponse> onError)
{
this.cache_keys = cacheKeys;

yield return HttpClient.Send<Req, Res>(
UnityWebRequest.kHttpVerbPUT,
path,
requireToken: true,
body: this,
onSuccess: onSuccess,
onError: onError
);
}
}

[Serializable]
public class Res : BaseResponse
{
public List<CacheItems> Items;
}

[Serializable]
public class CacheItems
{
public string key;
public string value;
}
}

使用示例

public void GetMultipleCaches()
{
CacheMultiGet.Req req = new CacheMultiGet.Req();

List<string> keys = new List<string>
{
"player_level",
"player_score",
"player_hp"
};

StartCoroutine(req.Send(
cacheKeys: keys,
onSuccess: res =>
{
foreach (var item in res.Items)
{
Debug.Log($"{item.key}: {item.value}");
}
},
onError: (error) =>
{
Debug.LogError($"Mget 실패: [{error.ErrorCode}] [{error.Message}]");
}
));
}