字符串类型

应用场景:
高速缓存HTML片段或者页面;
高速缓存关系型数据库查询的数据结果;
高速缓存会话控制数据;
分布式锁;
防止重复提交;
存储设置固定格式的字符串序列(例如:时间序列);
统计网站访问者数量;
每天注册用户数;
限制API在某一时段的访问次数;
用户签到;
统计活跃用户;
用户在线状态。

Redis字符串类型键的设置
  1.SET 给一个key添加字符串类型的值
  2.MSET 同时设置多个key,如果key存在会覆盖。
  3.SETEX 给一个键设置为字符串类型,并指定生存时间(单位:秒)。
  4.PSETEX 给一个键设置为字符串类型,并指定生存时间(单位:毫秒)
  5.SETNX 如果key不存在,将其设置为字符串类型
  6.MSETNX 同时设置多个key,如果其中一个key存在则设置失败,不考虑其他键是否存在.
  7.SETRANGE 修改或者设置一个键的字符串类型值的内容
  8.APPEND 追加value的内容

Redis字符串类型键的查询
  1.GET  查询key的值
  2.MGET 查询所有key的值
  3.GETRANGE 查询一个字符串的子串,子串的内容取决于start和end.
  4.STRLEN 返回key的字符串长度
  5.GETSET 原子地给一个key设置value并且将旧值返回

Redis字符串类型键的计数操作
  1.INCR 将 key 中储存的数字值增一
  2.INCRBY 将 key 所储存的值加上增量 increment
  3.INCRBYFLOAT 可以使用科学计数法
  4.DECR 将 key 中储存的数字值减一
  5.DECRBY

Redis字符串类型键的二进制操作
  SETBIT 对 key 所储存的字符串值,设置或清除指定偏移量上的位
  GETBIT 对 key 所储存的字符串值,获取指定偏移量上的位
  BITCOUNT 计算给定字符串中,被设置为 1 的比特位的数量
  BITOP 对一个或多个保存二进制位的字符串key进行位元操作,并将结果保存到destkey上
  BITPOS 返回字符串里面第一个被设置为1或者0的bit位
  BITFIELD 本命令会把Redis字符串当作位数组,并能对变长位宽和任意未字节对齐的指定整型位域进行寻址

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
自己实现的字符串 class CMStringImp; class CMstring { public: explicit CMstring(void); ~CMstring(void); CMstring(LPCTSTR lpszstr); CMstring(const CMstring& lpszstr); CMstring& operator = (const CMstring& lpszstr); operator LPCTSTR() const; bool operator == (const CMstring&) const; bool operator != (const CMstring&) const; bool operator < (const CMstring&) const; TCHAR operator[] (int nIndex) const; TCHAR& operator[] (int nIndex); CMstring& operator += (LPCTSTR pStr); CMstring& operator += (TCHAR ch); friend CMstring operator+(const CMstring& str1, const CMstring& str2); friend CMstring operator+(const CMstring& str1, LPCTSTR lpszstr); friend CMstring operator+(const CMstring& str1, TCHAR ch); friend CMstring operator+(TCHAR ch, const CMstring& str1); friend CMstring operator+(LPCTSTR lpszstr, const CMstring& str1); // friend wostream operator <<(wostream &is;,const CMstring &str;); public: LPCTSTR GetData() const; bool IsEmpty() const; TCHAR GetAt(int) const; TCHAR& GetAt(int); int GetLength() const; int Compare(const CMstring&) const; int CompareNoCase(const CMstring&) const; int Find(TCHAR ch, int nStart = 0) const; int Find(LPCTSTR pStr, int nStart = 0) const; int ReverseFind(TCHAR ch) const; int ReverseFind(LPCTSTR pStr) const; CMstring Right(int nCount) const; CMstring Left(int nCount ) const; public: CMstring& MakeLower(); CMstring& MakeUpper(); CMstring& MakeReverse(); int Replace(TCHAR chOld, TCHAR chNew); int Replace(LPCTSTR pszOld, LPCTSTR pszNew); int Insert(int iIndex, TCHAR ch); void Format(LPCTSTR lpszFormat, ...); private: CMStringImp* m_pImp; };

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值