| 12345678910111213141516171819202122232425262728293031323334353637383940414243 | using FreeRedis;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace WCS.Core{    public class VitrualRedisPLC : IPLCAccessor    {        RedisClient redis;        PLCInfo plcInfo;        int dbLen = 50000;        public VitrualRedisPLC(PLCInfo plcInfo, string redisConnStr)        {            this.plcInfo = plcInfo;            redis = new RedisClient(redisConnStr);        }        public byte[] ReadBytes(ushort db, ushort address, ushort length)        {            var key = $"{plcInfo.IP}-{db}";            if (!redis.Exists(key))            {                redis.SetRange(key, 0, new byte[dbLen]);            }            var res = redis.GetRange<byte[]>(key, address, address + length - 1);            return res;        }        public void WriteBytes(ushort db, ushort address, byte[] data)        {            var key = $"{plcInfo.IP}-{db}";            if (!redis.Exists(key))            {                redis.SetRange(key, 0, new byte[dbLen]);            }            redis.SetRange(key, address, data);        }    }}
 |