Size: 2768
Comment:
|
← Revision 26 as of 2023-05-26 11:42:56 ⇥
Size: 5258
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 3: | Line 3: |
https://redis.io/ Key-value in-memory data store used as a * database * cache * streaming engine * message broker |
|
Line 5: | Line 13: |
SlackBuild Redis page [[http://slackbuilds.org/repository/14.0/system/redis/]]. Build SlackBuild for Redis 2.6.12: * cd /tmp * wget http://slackbuilds.org/slackbuilds/14.0/system/redis.tar.gz * tar xvzf redis.tar.gz * cd redis * wget http://redis.googlecode.com/files/redis-2.6.12.tar.gz * su * ./redis.SlackBuild * installpkg /tmp/redis-2.6.12-x86_64-1_SBo.tgz |
SlackBuilds Redis page [[http://slackbuilds.org/repository/14.0/system/redis/]]. Build SlackBuilds for Redis 2.6.12: {{{#!highlight sh cd /tmp wget http://slackbuilds.org/slackbuilds/14.0/system/redis.tar.gz tar xvzf redis.tar.gz cd redis wget http://redis.googlecode.com/files/redis-2.6.12.tar.gz su ./redis.SlackBuild installpkg /tmp/redis-2.6.12-x86_64-1_SBo.tgz }}} |
Line 21: | Line 31: |
SlackBuild Redis page [[http://slackbuilds.org/repository/14.0/system/redis/]]. Build SlackBuild for Redis 2.6.14: * su * cd /tmp * wget http://slackbuilds.org/slackbuilds/14.0/system/redis.tar.gz * tar xvzf redis.tar.gz * cd redis * wget http://redis.googlecode.com/files/redis-2.6.14.tar.gz * ./redis.SlackBuild * installpkg /tmp/redis-2.6.14-i486-1_SBo.tgz Built package for Slackware 14: |
SlackBuilds Redis page [[http://slackbuilds.org/repository/14.0/system/redis/]]. Build SlackBuilds for Redis 2.6.14: {{{#!highlight sh su cd /tmp wget http://slackbuilds.org/slackbuilds/14.0/system/redis.tar.gz tar xvzf redis.tar.gz cd redis wget http://redis.googlecode.com/files/redis-2.6.14.tar.gz ./redis.SlackBuild installpkg /tmp/redis-2.6.14-i486-1_SBo.tgz }}} Built package for Slackware 14: [[attachment:redis-2.6.14-i486-1_SBo.tgz]] |
Line 38: | Line 50: |
* chmod 755 /etc/rc.d/rc.redis * /etc/rc.d/rc.redis start |
{{{#!highlight sh chmod 755 /etc/rc.d/rc.redis # start on boot /etc/rc.d/rc.redis start }}} Manual start/stop: {{{#!highlight sh sh /etc/rc.d/rc.redis start sh /etc/rc.d/rc.redis stop }}} |
Line 51: | Line 71: |
* redis-cli -h <hostname> -p <port> * redis-cli -h 127.0.0.1 -p 6379 |
* redis-cli -h <hostname> -p <port> -a <passwd> * redis-cli -h 127.0.0.1 -p 6379 -a secretPass |
Line 58: | Line 78: |
To show all keys use '''keys *''' To get the type of a key use '''type keyName''' |
|
Line 66: | Line 90: |
Set an hash key with multiple keys with values: * hmset <haskey> <key> <value> <key> <value> <key> <value> (...) |
Command prefix '''H'''. Set an hash key with multiple fields with values: * hmset <haskey> <field> <value> <field> <value> <field> <value> (...) |
Line 70: | Line 96: |
Gets key values for an hash key: * hmget <haskey> <key> <key> <key> (...) * hmget test:properties prop1 prop3 Get all keys and values for an hash key: * hmgetall <haskey> * hmgetall test:properties Get keys for an hash key: |
Gets field values for an hash key: * hget <haskey> <field> <field <field> (...) * hget test:properties prop1 prop3 Get all fields and values for an hash key: * hgetall <haskey> * hgetall test:properties Get fields for an hash key: |
Line 82: | Line 108: |
Get keys for an hash key: | Get field for an hash key: |
Line 86: | Line 112: |
Delete key from an hash key: * hdel <haskey> <key> |
Delete field from an hash key: * hdel <haskey> field |
Line 91: | Line 117: |
Command prefix '''L''' or '''R'''. Examples: * rpush list value * rpop list * rpush queueA "{'id':1,'task':'add','values':[1,2,3,4,5,6,7,8]}" * rpop list value * lpush lx "aaaaa" * llen lx * lindex lx 0 * lpush lx "bbbbb" * lpush lx "ccccc" * llen lx * lindex lx 0 * lindex lx 1 * lindex lx 2 * lpop lx * lpop lx * lpop lx * lpop lx === Redis sorted set === Command prefix '''Z'''. Only allow unique members values on the sorted set. When a existing member is added, the score is updated. Examples: * zadd sortedSetx 123 "{'key':'hello'}" #add member to the sorted set with score 123 * zcard sortedSetx #number of members in the sorted set sortedSetx * zrangebyscore sortedSetx 100 150 # get members where the score is between 100 and 150 * zrange sortedSetx 0 0 #get the members between 0 and 1 index * zrem sortedSetx "{'key':'hello'}" #removes the member in the sorted set == Python client install from pip == {{{#!highlight sh su easy_install pip # if no pip installed pip install redis }}} == Python client install from source == {{{#!highlight sh su cd /tmp wget [[https://pypi.python.org/packages/source/r/redis/redis-2.8.0.tar.gz]] tar xvzf redis-2.8.0.tar.gz cd redis-2.8.0 python setup.py build python setup.py install }}} {{{#!highlight python python import redis r = redis.StrictRedis(host='localhost', port=6379, db=0) # r = redis.Redis(host='localhost', port=6379, db=0) r.rpush('queueA','test') r.rpush('queueA','test2') r.rpop('queueA') r.rpop('queueA') r.rpush('queueA', {'key':1234} ) x=r.pop('queueA') #convert string to dictionary import ast dictx=ast.literal_eval(x) dictx dictx['key'] }}} == Install on FreeBSD 10.3 == {{{#!highlight sh pkg install redis #freebsd add redis_enable="YES" to /etc/rc.conf /usr/local/etc/rc.d/redis start /usr/local/etc/redis.conf requirepass 12345678 }}} == Install redis in debian == {{{#!highlight sh sudo apt install redis redis-cli }}} |
Redis
Key-value in-memory data store used as a
- database
- cache
- streaming engine
- message broker
Install Redis 2.6.12 on Slackware64 14
SlackBuilds Redis page http://slackbuilds.org/repository/14.0/system/redis/.
Build SlackBuilds for Redis 2.6.12:
Built package for Slackware64 14: redis-2.6.12-x86_64-1_SBo.tgz
Install Redis 2.6.14 on Slackware 14
SlackBuilds Redis page http://slackbuilds.org/repository/14.0/system/redis/.
Build SlackBuilds for Redis 2.6.14:
Built package for Slackware 14: redis-2.6.14-i486-1_SBo.tgz
Start Redis service on Slackware
Run the following commands:
Manual start/stop:
It listens in port 6379 and stores it's data on /var/lib/redis/, as configured in /etc/redis.conf.
Tutorial The Little Redis Book
Tutorial in http://openmymind.net/redis.pdf.
Connect to a Redis server
To connect to a Redis server, the redis-cli command may be used.
Usage examples:
redis-cli -h <hostname> -p <port> -a <passwd>
- redis-cli -h 127.0.0.1 -p 6379 -a secretPass
Setting and getting keys
The basic anatomy of a command is:
<command> <key> <value>
To show all keys use keys *
To get the type of a key use type keyName
To set a key named unixcommand:bc with the value {command:'bc' , description:'bc - An arbitrary precision calculator language' , syntax:'bc [ -hlwsqv ] [long-options] [ file ... ]'} the command would be:
- set unixcommand:bc "{command:'bc' , description:'bc - An arbitrary precision calculator language' , syntax:'bc [ -hlwsqv ] [long-options] [ file ... ]'}"
To get the key value the command would be:
- get unixcommand:bc
Redis hash key
Command prefix H.
Set an hash key with multiple fields with values:
hmset <haskey> <field> <value> <field> <value> <field> <value> (...)
- hmset test:properties prop1 value1 prop2 value2 prop3 value3
Gets field values for an hash key:
hget <haskey> <field> <field <field> (...)
- hget test:properties prop1 prop3
Get all fields and values for an hash key:
hgetall <haskey>
- hgetall test:properties
Get fields for an hash key:
hkeys <haskey>
- hkeys test:properties
Get field for an hash key:
hkeys <haskey>
- hkeys test:properties
Delete field from an hash key:
hdel <haskey> field
- hdel test:properties prop2
Redis list
Command prefix L or R.
Examples:
- rpush list value
- rpop list
- rpush queueA "{'id':1,'task':'add','values':[1,2,3,4,5,6,7,8]}"
- rpop list value
- lpush lx "aaaaa"
- llen lx
- lindex lx 0
- lpush lx "bbbbb"
- lpush lx "ccccc"
- llen lx
- lindex lx 0
- lindex lx 1
- lindex lx 2
- lpop lx
- lpop lx
- lpop lx
- lpop lx
Redis sorted set
Command prefix Z. Only allow unique members values on the sorted set. When a existing member is added, the score is updated.
Examples:
- zadd sortedSetx 123 "{'key':'hello'}" #add member to the sorted set with score 123
- zcard sortedSetx #number of members in the sorted set sortedSetx
- zrangebyscore sortedSetx 100 150 # get members where the score is between 100 and 150
- zrange sortedSetx 0 0 #get the members between 0 and 1 index
- zrem sortedSetx "{'key':'hello'}" #removes the member in the sorted set
Python client install from pip
Python client install from source
1 python
2 import redis
3 r = redis.StrictRedis(host='localhost', port=6379, db=0)
4 # r = redis.Redis(host='localhost', port=6379, db=0)
5 r.rpush('queueA','test')
6 r.rpush('queueA','test2')
7 r.rpop('queueA')
8 r.rpop('queueA')
9 r.rpush('queueA', {'key':1234} )
10 x=r.pop('queueA')
11 #convert string to dictionary
12 import ast
13 dictx=ast.literal_eval(x)
14 dictx
15 dictx['key']
Install on FreeBSD 10.3