设为首页 加入收藏

TOP

redis基础入门(二)
2015-11-21 01:31:27 来源: 作者: 【 】 浏览:1
Tags:redis 基础 入门
on', 'software engineer'); $redis->hset($key, 'reknown', 'linux kernel'); $redis->hset($key, 'to delete', 'i will be deleted'); $redis->hget($key, 'age'); // 44 $redis->hget($key, 'country')); // Finland $redis->del($key, 'to delete'); $redis->hincrby($key, 'age', 20); // 64 $redis->hmset($key, [ 'age' => 44, 'country' => 'finland', 'occupation' => 'software engineer', 'reknown' => 'linux kernel', ]); // finally $data = $redis->hgetall($key); print_r($data); // returns all key-value that belongs to the hash /* [ 'age' => 44, 'country' => 'finland', 'occupation' => 'software engineer', 'reknown' => 'linux kernel', ] */

Working with Sets

set相关的命令:

SADD: 给set增加N个成员,数组或者单个元素

SREM: 从数组中移除单个或者一个成员

SISMEMBER: 判断成员是否存在

SMEMBERS: 获取set中所有成员


            sadd($key, ';china';); $redis->sadd($key, ['england', 'france', 'germany']); $redis->sadd($key, 'china'); // this entry is ignored $redis->srem($key, ['england', 'china']); $redis->sismember($key, 'england'); // false $redis->smembers($key); // ['france', 'germany'] 

Set Expiry and Persistence

因为Resia在内存中存储,你可能并不像永久存储,就比如我之前的介绍Node创建session的文章. 这里可以设置过期的方法有 EXPIRE, EXPIREAT, TTL, PERSIST –

EXPIRE: 以秒为单位,设置过期时间

EXPIREAT: 过多久之后被删除,以秒为单位

TTL:距离过期还剩多少时间

PERSIST:让一个键永久保存

$key = "expire in 1 hour"; $redis->expire($key, 3600); // expires in 1 hour $redis->expireat($key, time() + 3600); // expires in 1 hour sleep(600); // don't try this, just an illustration for time spent $redis->ttl($key); // 3000, ergo expires in 50 minutes $redis->persist($key); // this will never expire. 

CONCLUSION

后悔中......花了30分钟,翻译了这么一篇没水平的文章,也不知道自己是怎么想的。越想越不对,但是既然翻译了,就翻译完了,里面可能有翻译的不对的地方,或者代码错误的地方,那都不是问题,掠过就可以。

Future of Redis

Redis is a better replacement for memcached, as it is faster, scales better (supports master-slave replication), supports datatypes that many (Facebook, Twitter, Instagram) have dropped memcached for Redis. Redis is open source and many brilliant programmers from the open-source community have contributed patches.

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇iosCoreData用父类的实例对象pers.. 下一篇关于控制文件转储后的trace文件中..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: