|
| 1 | +# go-redis |
| 2 | + |
| 3 | +go-redis - The GNU Octave redis client |
| 4 | + |
| 5 | + |
| 6 | +A [Redis](http://redis.io) client for [GNU Octave](http://www.gnu.org/software/octave/), written in pure Octave, using |
| 7 | +[instrumen-control](http://octave.sourceforge.net/instrument-control/index.html) package. |
| 8 | + |
| 9 | +This client works by establishing a TCP connection to the specified Redis server and using the [Redis protocol](http://redis.io/topics/protocol). |
| 10 | +It's fast. It writes 1*10^6 Values in ~10 seconds (tested on AMD E-450) on localhost. |
| 11 | + |
| 12 | + |
| 13 | +# Versions |
| 14 | + |
| 15 | +### go-redis [developer Version] |
| 16 | + |
| 17 | + git clone https://github.com/markuman/go-redis.git |
| 18 | + |
| 19 | +* (will be go-redis-2.0 one day) |
| 20 | + * some improvements + matlab compatibility (maybe, maybe not...not finished yet) |
| 21 | + |
| 22 | + |
| 23 | +### go-redis 1.0 [stable] |
| 24 | + |
| 25 | + git clone https://github.com/markuman/go-redis.git && cd go-redis |
| 26 | + git checkout b8b6b1d |
| 27 | + |
| 28 | +* for Octave >= 3.6, instrument-control >= 0.2, redis >= 2.6 |
| 29 | + |
| 30 | + |
| 31 | +# Documentation |
| 32 | + |
| 33 | +## set and get in go-redis |
| 34 | + |
| 35 | +set can save single values (num or str) or numeric n-dimension Matrix _(and structs of depth one)_. |
| 36 | +Furthermore, it is important to know, how go-redis is saving n-dimension Matrix. It use RPUSH (a list of values) in redis and reshape |
| 37 | +in octave. But the first(!) value in the RPUSH list is reservated for the dimension of your Matrix. This is important, if you want to use the |
| 38 | +values with other applications or programming languages too! E.g. for 4x7 Matrix, the first Value is "4 7 ". |
| 39 | + |
| 40 | +## usage |
| 41 | + |
| 42 | +Make a redis connection: |
| 43 | + |
| 44 | + r = redis() % connect to localhost on port 6379 |
| 45 | + r = redis('192.168.1.1') % connect to 192.168.1.1 on port 6379 |
| 46 | + r = redis('foo.com', 4242) % connect to foo.com on port 4242 |
| 47 | + |
| 48 | +Authenticate if needed: |
| 49 | + |
| 50 | + status = auth(r,'password'); |
| 51 | + |
| 52 | +For set are no options. It knows if you want to store a string, a matrice or a single value. |
| 53 | + |
| 54 | + status = set(r,'keyName',variablename); |
| 55 | + % if you don't name a keyname, the name of the variable will be taken as keyname |
| 56 | + status = set(r,variablename); |
| 57 | + |
| 58 | +For get are no options too |
| 59 | + |
| 60 | + matrix = get(r,'keyName'); |
| 61 | + |
| 62 | +To test the connection or keep your session alive, you can use redisPing |
| 63 | + |
| 64 | + pong = redisPing(r) |
| 65 | + |
| 66 | +To change the database on the connected redis server, use redisSelect. By default, redisConnection connects to database 0, whitch is the first |
| 67 | +database |
| 68 | + |
| 69 | + feedback = select(r,2); % Connects to the 3rd database |
| 70 | + |
| 71 | +Increase or Decrease Integer Values |
| 72 | + |
| 73 | + incr(r,'keyname'); % just increase a value without feedback |
| 74 | + tmp = decr(r,'keyname'); % decrease a value and asign the new value to 'tmp' variable in octave |
| 75 | + |
| 76 | +Rename or moving keys |
| 77 | + |
| 78 | + rename(r,'oldkeyname','newkeyname'); |
| 79 | + |
| 80 | +To get the size of the database |
| 81 | + |
| 82 | + size_of_db = dbsize(r); |
| 83 | + |
| 84 | +Synchronously save the dataset to disk |
| 85 | + |
| 86 | + reply = save(r); |
| 87 | + |
| 88 | +With command you can use any command with redis. But the output is raw! So you have to parse the output by yourself (redis protocol)! You |
| 89 | +just want to use this for debugging. At least, you need two or three arguments (atm very limited)! |
| 90 | + |
| 91 | + redis 127.0.0.1:6379[1]> keys * |
| 92 | + 1) "test" |
| 93 | + 2) "wurst" |
| 94 | + ---- |
| 95 | + octave:7> command(R,'keys','*') |
| 96 | + ans = *2 |
| 97 | + $4 |
| 98 | + test |
| 99 | + $5 |
| 100 | + wurst |
| 101 | + |
| 102 | + redis 127.0.0.1:6379> LLEN SportB |
| 103 | + (integer) 3 |
| 104 | + ---- |
| 105 | + octave:9> command(R,'LLEN', 'SportB') |
| 106 | + ans = :3 |
| 107 | + |
| 108 | + redis 127.0.0.1:6379> ping |
| 109 | + PONG |
| 110 | + ---- |
| 111 | + octave:10> command(R,'PING') |
| 112 | + ans = +PONG |
| 113 | + |
| 114 | + |
| 115 | +# Thanks |
| 116 | +* https://github.com/dac922/ |
| 117 | + |
0 commit comments