Add hash commands to extra/redis
parent
f0be8408e6
commit
33cc7c45f5
|
@ -112,6 +112,68 @@ IN: redis.command-writer.tests
|
|||
|
||||
[ "SMEMBERS key\r\n" ] [ [ "key" smembers ] with-string-writer ] unit-test
|
||||
|
||||
#! Hashes
|
||||
[ "HDEL key field\r\n" ] [
|
||||
[ "field" "key" hdel ] with-string-writer
|
||||
] unit-test
|
||||
|
||||
[ "HEXISTS key field\r\n" ] [
|
||||
[ "field" "key" hexists ] with-string-writer
|
||||
] unit-test
|
||||
|
||||
[ "HGET key field\r\n" ] [
|
||||
[ "field" "key" hget ] with-string-writer
|
||||
] unit-test
|
||||
|
||||
[ "HGETALL key\r\n" ] [
|
||||
[ "key" hgetall ] with-string-writer
|
||||
] unit-test
|
||||
|
||||
[ "HINCRBY key field 1\r\n" ] [
|
||||
[ 1 "field" "key" hincrby ] with-string-writer
|
||||
] unit-test
|
||||
|
||||
[ "HINCRBYFLOAT key field 1.0\r\n" ] [
|
||||
[ 1.0 "field" "key" hincrbyfloat ] with-string-writer
|
||||
] unit-test
|
||||
|
||||
[ "HKEYS key\r\n" ] [
|
||||
[ "key" hkeys ] with-string-writer
|
||||
] unit-test
|
||||
|
||||
[ "HLEN key\r\n" ] [
|
||||
[ "key" hlen ] with-string-writer
|
||||
] unit-test
|
||||
|
||||
[ "HMGET key field1 field2\r\n" ] [
|
||||
[
|
||||
{ "field1" "field2" }
|
||||
"key"
|
||||
hmget
|
||||
] with-string-writer
|
||||
] unit-test
|
||||
|
||||
[ "HMSET key field1 value1 field2 value2\r\n" ] [
|
||||
[
|
||||
{ { "field1" "value1" } { "field2" "value2" } }
|
||||
"key"
|
||||
hmset
|
||||
] with-string-writer
|
||||
] unit-test
|
||||
|
||||
[ "HSET key field value\r\n" ] [
|
||||
[
|
||||
"value"
|
||||
"field"
|
||||
"key"
|
||||
hset
|
||||
] with-string-writer
|
||||
] unit-test
|
||||
|
||||
[ "HSETNX key field value\r\n" ] [ [ "value" "field" "key" hsetnx ] with-string-writer ] unit-test
|
||||
|
||||
[ "HVALS key\r\n" ] [ [ "key" hvals ] with-string-writer ] unit-test
|
||||
|
||||
#! Multiple db
|
||||
[ "SELECT 2\r\n" ] [ [ 2 select ] with-string-writer ] unit-test
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
! Copyright (C) 2009 Bruno Deferrari
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: io io.crlf kernel math.parser sequences strings interpolate locals ;
|
||||
USING: assocs io io.crlf kernel math.parser sequences strings interpolate locals ;
|
||||
IN: redis.command-writer
|
||||
|
||||
<PRIVATE
|
||||
|
@ -84,6 +84,28 @@ PRIVATE>
|
|||
"SUNIONSTORE " write write " " join space write crlf ;
|
||||
: smembers ( key -- ) "SMEMBERS " write write crlf ;
|
||||
|
||||
#! Hashes
|
||||
: hdel ( field key -- ) "HDEL " write write space write crlf ;
|
||||
: hexists ( field key -- ) "HEXISTS " write write space write crlf ;
|
||||
: hget ( field key -- ) "HGET " write write space write crlf ;
|
||||
: hgetall ( key -- ) "HGETALL " write write crlf ;
|
||||
: hincrby ( integer field key -- )
|
||||
"HINCRBY " write write space write space number>string write crlf ;
|
||||
: hincrbyfloat ( float field key -- )
|
||||
"HINCRBYFLOAT " write write space write space number>string write crlf ;
|
||||
: hkeys ( key -- ) "HKEYS " write write crlf ;
|
||||
: hlen ( key -- ) "HLEN " write write crlf ;
|
||||
: hmget ( seq key -- )
|
||||
"HMGET " write write space " " join write crlf ;
|
||||
: hmset ( assoc key -- )
|
||||
"HMSET " write write space
|
||||
>alist [ " " join ] map " " join write crlf ;
|
||||
: hset ( value field key -- ) "HSET " write write space write
|
||||
space write crlf ;
|
||||
: hsetnx ( value field key -- ) "HSETNX " write write space
|
||||
write space write crlf ;
|
||||
: hvals ( key -- ) "HVALS " write write crlf ;
|
||||
|
||||
#! Multiple db
|
||||
: select ( integer -- ) "SELECT " write number>string write crlf ;
|
||||
: move ( integer key -- ) "MOVE " write write-key/integer crlf ;
|
||||
|
|
|
@ -56,6 +56,21 @@ IN: redis
|
|||
: redis-sunionstore ( keys destkey -- response ) sunionstore flush read-response ;
|
||||
: redis-smembers ( key -- response ) smembers flush read-response ;
|
||||
|
||||
#! Hashes
|
||||
: redis-hdel ( field key -- response ) hdel flush read-response ;
|
||||
: redis-hexists ( field key -- response ) hexists flush read-response ;
|
||||
: redis-hget ( field key -- response ) hget flush read-response ;
|
||||
: redis-hgetall ( key -- response ) hgetall flush read-response ;
|
||||
: redis-hincrby ( integer field key -- response ) hincrby flush read-response ;
|
||||
: redis-hincrbyfloat ( float field key -- response ) hincrbyfloat flush read-response ;
|
||||
: redis-hkeys ( key -- response ) hkeys flush read-response ;
|
||||
: redis-hlen ( key -- response ) hlen flush read-response ;
|
||||
: redis-hmget ( seq key -- response ) hmget flush read-response ;
|
||||
: redis-hmset ( assoc key -- response ) hmset flush read-response ;
|
||||
: redis-hset ( value field key -- response ) hset flush read-response ;
|
||||
: redis-hsetnx ( value field key -- response ) hsetnx flush read-response ;
|
||||
: redis-hvals ( key -- response ) hvals flush read-response ;
|
||||
|
||||
#! Multiple db
|
||||
: redis-select ( integer -- response ) select flush read-response ;
|
||||
: redis-move ( integer key -- response ) move flush read-response ;
|
||||
|
|
Loading…
Reference in New Issue