Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

key不存在时,get方法返回值是false感觉不合适 #45

Open
danvinhe opened this issue Jan 7, 2015 · 7 comments
Open

key不存在时,get方法返回值是false感觉不合适 #45

danvinhe opened this issue Jan 7, 2015 · 7 comments

Comments

@danvinhe
Copy link

danvinhe commented Jan 7, 2015

如果业务本身需要,存的value为false时,很容易混淆。不知道是不存在这个key,还是key的值就是false。两点建议:

  1. key不存在时,返回null
  2. set时,value不允许是null
@Neeke
Copy link

Neeke commented Jan 10, 2015

@danvinhe 那如果业务本身需要,存的value为null呢?

@danvinhe
Copy link
Author

@Neeke 是的,这个比较惆怅。我们的解决方案是存以前把$value,变成array($value)

@liufang
Copy link

liufang commented Jan 25, 2015

@Neeke null本身就是未知, 你自己都不知道, 你还设置啥. key不存在, 返回null应该是正确的.

@geekli
Copy link

geekli commented Jan 25, 2015

我觉得这种情况应该就不需要使用这种方式缓存了
假如真想缓存 做变换处理 存储一个特殊字符(对了 难道这种不是只能做字符串存储吗?)

@captainQW
Copy link

有在线上跑的么?

@yyxx9988
Copy link

1. key不存在时,返回null
2. set时,value不允许是null

@laruence 我也觉得这样比较好,一般PHP框架数据库ORM返回值的时候,如果不存在就返回null

@gouchaoer
Copy link

返回false没有问题,比如yii2的缓存接口就是返回false:http://www.yiichina.com/doc/guide/2.0/caching-data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants