Coder Social home page Coder Social logo

car8's People

Watchers

 avatar  avatar  avatar

car8's Issues

111111231232

  public class UnSortedSet<T>
    {
        internal UnSortedSet(RedisDB db, string key, IDataFormater dataFormater = null)
        {
            DB = db;
            Key = key;
            DataFormater = dataFormater;
        }

        public string Key { get; private set; }

        internal RedisDB DB { get; set; }

        public IDataFormater DataFormater { get; set; }

        public async ValueTask<long> Card()
        {
            SCARD cmd = new SCARD(Key);
            var result = await DB.Execute(cmd, typeof(string));
            if (result.IsError)
                throw new RedisException(result.Messge);
            return System.Convert.ToInt64(result.Value);
        }

        public async ValueTask<long> Add(params T[] values)
        {
            SADD cmd = new SADD(Key, DataFormater);
            for (int i = 0; i < values.Length; i++)
                cmd.Values.Add(values[i]);
            var result = await DB.Execute(cmd, typeof(T));
            if (result.IsError)
                throw new RedisException(result.Messge);
            return (long)result.Value;
        }

        public async ValueTask<T[]> Members()
        {
            SMEMBERS cmd = new SMEMBERS(Key, DataFormater);
            var result = await DB.Execute(cmd, typeof(T));
            if (result.IsError)
                throw new RedisException(result.Messge);
            return (from a in result.Data select (T)a.Data).ToArray();
        }

        public async ValueTask<long> Rem(params T[] members)
        {
            if (members == null || members.Length == 0)
                return 0;
            SREM cmd = new SREM(Key, DataFormater);
            for (int i = 0; i < members.Length; i++)
                cmd.Values.Add(members[i]);
            var result = await DB.Execute(cmd, typeof(T));
            if (result.IsError)
                throw new RedisException(result.Messge);
            return (long)result.Value;
        }

        public async ValueTask<bool> IsMember(T member)
        {
            SISMEMBER cmd = new SISMEMBER(Key, member, DataFormater);
            var result = await DB.Execute(cmd, typeof(T));
            if (result.IsError)
                throw new RedisException(result.Messge);
            return (long)result.Value > 0;
        }
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.