Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries and streams. Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.
REmote DIctionary Server(Redis) 是一个由Salvatore Sanfilippo写的key-value存储系统。Redis是一个开源的使用ANSI C语言编写、遵守BSD协议、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。它通常被称为数据结构服务器,因为值(value)可以是 字符串(String), 哈希(Hash), 列表(list), 集合(sets) 和 有序集合(sorted sets)等类型。
server - python - django:
# setting.py
# pip3 install django-redis
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
"PICKLE_VERSION": -1,
# "PASSWORD": "SECRET",
}
}
}
# redis-server
# view.py
# pip install django==2.2.7
from django.core.cache import cache
from parking.models import *
def redis_pool(key_id, val_dt=None):
try:
if val_dt is None: return cache.get(key_id)
cache.set(key_id, val_dt); return True
except: return False
try:
redis_pool('hello', 'world')
print(redis_pool('hello'))
except Exception as e:
print(e)
server Installation - linux:
# linux (centos7)
wget http://download.redis.io/releases/redis-5.0.7.tar.gz
tar -zvxf redis-5.0.7.tar.gz
make && make install
mkdir /etc/local/redis
mkdir /etc/local/redis/bin/
mkdir /etc/local/redis/etc/
mv redis.conf /usr/local/redis/etc/
cd src
mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-server /usr/local/redis/bin/
./redis-serve
# more config
bind 127.0.0.1
vi /usr/local/redis/etc/redis.conf
daemonize -> yes
redis-server /usr/local/redis/etc/redis.conf
ln -s /usr/local/redis/bin/redis-server /usr/bin/redis-server
# yum
yum install redis / yum install epel-release
yum install redis
# apt
sudo apt-get install redis-server
sudo apt-get purge --auto-remove redis-server
# Runtime (centOS7 / unbuntu)
service redis start / sudo service redis-server start
service redis stop / sudo service redis-server stop
service redis status / ps aux|grep redis
ps -ef | grep redis
# auto start
chkconfig redis on
# windows https://github.com/microsoftarchive/redis/releases
# macos
# brew update
# brew install redis
# brew services start redis
# redis-server /usr/local/etc/redis.conf # background service
# redis-cli ping # runtime check
# /usr/local/etc/redis.conf
# brew uninstall redis # uninstall
# rm ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
client test - python
import redis # pip install redis
r = redis.Redis(host="10.170.15.54", port='6379')
r.set('hello','there')
print((r.get('hello')))
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有