admin管理员组

文章数量:1567737

2024年7月9日发(作者:)

826

827 ///

828 /// 删除单个key

829 ///

830 /// redis key

831 /// 是否删除成功

832 public bool KeyDelete(string key)

833 {

834 key = AddSysCustomKey(key);

835 return Do(db => ete(key));

836 }

837

838 ///

839 /// 删除多个key

840 ///

841 /// rediskey

842 /// 成功删除的个数

843 public long KeyDelete(List keys)

844 {

845 List newKeys = (AddSysCustomKey).ToList();

846 return Do(db => ete(ConvertRedisKeys(newKeys)));

847 }

848

849 ///

850 /// 判断key是否存储

851 ///

852 /// redis key

853 ///

854 public bool KeyExists(string key)

855 {

856 key = AddSysCustomKey(key);

857 return Do(db => sts(key));

858 }

859

860 ///

861 /// 重新命名key

862 ///

863 /// 就的redis key

864 /// 新的redis key

865 ///

866 public bool KeyRename(string key, string newKey)

867 {

868 key = AddSysCustomKey(key);

869 return Do(db => ame(key, newKey));

870 }

871

872 ///

873 /// 设置Key的时间

874 ///

875 /// redis key

876 ///

877 ///

878 public bool KeyExpire(string key, TimeSpan? expiry = default(TimeSpan?))

879 {

880 key = AddSysCustomKey(key);

881 return Do(db => ire(key, expiry));

882 }

883

884 #endregion key

885

886 #region 发布订阅

887

888 ///

889 /// Redis发布订阅 订阅

890 ///

891 ///

892 ///

893 public void Subscribe(string subChannel, Action handler = null)

894 {

895 ISubscriber sub = _scriber();

896 ibe(subChannel, (channel, message) =>

897 {

898 if (handler == null)

899 {

900 ine(subChannel + " 订阅收到消息:" + message);

901 }

902 else

903 {

904 handler(channel, message);

905 }

906 });

907 }

908

909 ///

910 /// Redis发布订阅 发布

911 ///

912 ///

913 ///

914 ///

915 ///

916 public long Publish(string channel, T msg)

917 {

918 ISubscriber sub = _scriber();

919 return h(channel, ConvertJson(msg));

920 }

921

922 ///

923 /// Redis发布订阅 取消订阅

924 ///

925 ///

926 public void Unsubscribe(string channel)

927 {

928 ISubscriber sub = _scriber();

929 cribe(channel);

930 }

931

932 ///

933 /// Redis发布订阅 取消全部订阅

934 ///

935 public void UnsubscribeAll()

936 {

937 ISubscriber sub = _scriber();

938 cribeAll();

939 }

940

941 #endregion 发布订阅

942

943 #region 其他

944

945 public ITransaction CreateTransaction()

946 {

947 return GetDatabase().CreateTransaction();

948 }

本文标签: 订阅发布是否删除设置