Unity-Redis数据存储
创始人
2024-11-14 19:05:45
0次

1.Redis 安装测试:
  安装:
    安装包 链接:https://pan.baidu.com/s/1BzuqRNJHW1MiB4xm4UT4MA 提取码:pvrj
  使用:
    运行包内 redis-server.exe 启动 Redis 服务 ,运行包内 redis-cli.exe 启动客户端 (本地自联)
    远程到主机为 127.0.0.1,端口为 6379 ,密码为 mypass 的 redis 服务上 : redis-cli -h 127.0.0.1 -p 6379 -a "mypass"
  命令:
    检测连接 ping PONG
    增:set key value (setnx key value只有在 key 不存在时设置 key 的值 , exists key 存在 (integer) 1,不存在 (integer) 0)
    删:del key (命令执行后输出 (integer) 1,否则将输出 (integer) 0)
    改: set key value (rename key newkey 修改key, renamenx key newkey 仅当 newkey 不存在时,将 key 改名为 newkey)
    查: get key (type key 查看value类型 ,strlen key 返回 key 所储存的字符串值的长度)

2.Unity-Redis 存储调用:

  untiy工程需添加dll:链接:https://pan.baidu.com/s/1mPI4HYPTP5rfi3q-C3y-WQ   提取码:0wod  

using UnityEngine; using ServiceStack.Redis; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks;     public class Unity_Redis : MonoBehaviour {     string exePath = @"F:\Redis\Redis-x64-5.0.10\redis-server.exe";     //string exePath = Application.dataPath + "/Resources/redis-server.exe";     RedisClient redisClient = new RedisClient("127.0.0.1", 6379);            private void Start()     {         //var P_exe = Process.Start(exePath);         //Application.OpenURL(exePath);           Process pro = new Process();         pro.StartInfo.FileName = exePath;         pro.StartInfo.UseShellExecute = true;         pro.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;         pro.Start();     }     private void Update()     {         if (Input.GetKeyDown(KeyCode.Q))         {             redisClient.Add("name", "xiaolang");             UnityEngine.Debug.Log("添加:name -- " + redisClient.Get("name"));         }         if (Input.GetKeyDown(KeyCode.W))         {             UnityEngine.Debug.Log("删除:name -- " + redisClient.Get("name"));             redisClient.Del("name");         }         if (Input.GetKeyDown(KeyCode.Delete))         {             redisClient.FlushAll();             UnityEngine.Debug.Log("清理Redis");         }     }     private void OnDestroy()     {         KillProcess("redis-server");     }     private void KillProcess(string processName)     {         //processName是exe的文件名           Process[] processes = Process.GetProcesses();         foreach (Process process in processes)         {             try             {                 if (!process.HasExited)                 {                     if (process.ProcessName == processName)                     {                         process.Kill();                         UnityEngine.Debug.Log("已关闭进程");                     }                 }             }             catch (Exception e)             {                 UnityEngine.Debug.Log(e.ToString());             }         }     } }

参考:https://www.jianshu.com/p/fab041e93b52

相关内容

热门资讯

微扑克辅助器!德州平台有没有挂... 您好:德州平台有没有挂这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌...
AApoker透视挂!wepo... 很多人使用云端 AI 时,都担心wepoker透视挂是真的吗、内部资料上传带来隐私风险。这款本地运行...
WePoKer透视!wepok... WePoKer透视!wepoker如何拿到好牌,分享透视多功能软件APP模板;近期一款 AI 黑科技...
红龙扑克透视挂!德扑之星规律,... 红龙扑克透视挂!德扑之星规律,解迷透视挂多功能插件APP法门是一款可以让一直输的玩家,快速成为一个“...
aapoker透视!WePoK... 您好,WePoKer有没有透视软件挂这款游戏可以开挂的,确实是有挂的,需要了解加微【48527505...
红龙扑克开挂!微扑克的辅助工具... 很多人使用云端 AI 时,都担心微扑克的辅助工具有哪些、内部资料上传带来隐私风险。这款本地运行的 A...
aapoker辅助!wepok... 您好:wepoker私人局怎么设置抽水这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会...
aapoker辅助挂!wepo... aapoker辅助挂!wepoker透视挂安全吗,普及辅助挂多功能方法APP策略AI 智能体黑科技再...
红龙PoKer辅助挂!wepo... 您好:wepokerplus透视挂真的假的这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌...
德扑之星辅助挂!德州ai辅助有... 德扑之星辅助挂!德州ai辅助有用吗,详细辅助挂多功能下载APP指南书是一款可以让一直输的玩家,快速成...