Memcache 键值key的格式和类型

开发搜索功能的时候,需要搜索词分词并且标红。因为搜索词标红是一个费时的操作,所以对于搜素词的分词结果做了五分钟的缓存。并且以搜索词为key,开发完毕。某次搜索之后,发现了异常的log, 文本如下:
java.lang.IllegalArgumentException: Key contains invalid characters:  ``mem_search_segment_pattern_str_思维 曲线 ^&''
        at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)

这才想起来memcache key不能有空格,翻看了memcache /doc/protocal.txt对key的介绍如下
Keys
----

Data stored by memcached is identified with the help of a key. A key
is a text string which should uniquely identify the data for clients
that are interested in storing and retrieving it.  Currently the
length limit of a key is set at 250 characters (of course, normally
clients wouldn't need to use such long keys); the key must not include
control characters or whitespace.

第一感觉使用正则表达式
 String newKey = key.replaceAll("\\p{Cntrl}]|\\p{Space}""_");
另外长度要控制在250个字符。。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值