码迷,mamicode.com
首页 > 数据库 > 详细

Redis数据库

时间:2016-08-05 15:39:59      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:

字符串

import redis
conn = redis.Redis()
#相当于
#redis.Redis(‘localhost’)
#redis.Redis(‘localhost‘, 6379)

#列出所有的键
conn.keys(‘*‘)
#[]

conn.set(‘secret‘, ‘ni!‘)
#True
conn.set(‘carats‘, 24)
#True
conn.set(‘fever‘, ‘101.5‘)
#True

conn.get(‘secret‘)
#b‘ni!‘

#键不存在时才设定值
conn.setnx(‘secret‘, ‘icky-icky-icky-ptang-zoop-boing!‘)
#False

#返回旧值同时赋新值
conn.getset(‘secret‘, ‘icky-icky-icky-ptang-zoop-boing!‘)

#得到子串
conn.getrange(‘secret‘, -6, -1)
#b‘boing!‘

#设置子串
conn.setrange(‘secret‘, 0, ‘ICKY‘)

#设置多个键值
conn.mset({‘pie‘: ‘cherry‘, ‘cordial‘: ‘sherry‘})
#[b‘101.5‘, b‘24‘]

conn.mget([‘fever‘, ‘carats‘])

conn.delete(‘fever‘)
#True

 

Redis数据库

标签:

原文地址:http://www.cnblogs.com/jzm17173/p/5740989.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!