admin管理员组文章数量:1656251
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
844 {
845 List
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
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
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 }
版权声明:本文标题:C#-Redis帮助类(.NetFramework) 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1720492106a827392.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论