@@ -17,12 +17,7 @@ describe("The 'eval' method", function () {
17
17
client = redis . createClient . apply ( redis . createClient , args ) ;
18
18
client . once ( "error" , done ) ;
19
19
client . once ( "connect" , function ( ) {
20
- client . flushdb ( function ( err ) {
21
- if ( ! helper . serverVersionAtLeast ( client , [ 2 , 5 , 0 ] ) ) {
22
- err = Error ( 'exec not supported in redis <= 2.5.0' ) ;
23
- }
24
- return done ( err ) ;
25
- } ) ;
20
+ client . flushdb ( done ) ;
26
21
} ) ;
27
22
} ) ;
28
23
@@ -31,30 +26,37 @@ describe("The 'eval' method", function () {
31
26
} ) ;
32
27
33
28
it ( 'converts a float to an integer when evaluated' , function ( done ) {
29
+ helper . serverVersionAtLeast . call ( this , client , [ 2 , 5 , 0 ] ) ;
34
30
client . eval ( "return 100.5" , 0 , helper . isNumber ( 100 , done ) ) ;
35
31
} ) ;
36
32
37
33
it ( 'returns a string' , function ( done ) {
38
- client . EVAL ( "return 'hello world'" , 0 , helper . isString ( 'hello world' , done ) ) ;
34
+ helper . serverVersionAtLeast . call ( this , client , [ 2 , 5 , 0 ] ) ;
35
+ client . eval ( "return 'hello world'" , 0 , helper . isString ( 'hello world' , done ) ) ;
39
36
} ) ;
40
37
41
38
it ( 'converts boolean true to integer 1' , function ( done ) {
39
+ helper . serverVersionAtLeast . call ( this , client , [ 2 , 5 , 0 ] ) ;
42
40
client . eval ( "return true" , 0 , helper . isNumber ( 1 , done ) ) ;
43
41
} ) ;
44
42
45
43
it ( 'converts boolean false to null' , function ( done ) {
44
+ helper . serverVersionAtLeast . call ( this , client , [ 2 , 5 , 0 ] ) ;
46
45
client . eval ( "return false" , 0 , helper . isNull ( done ) ) ;
47
46
} ) ;
48
47
49
48
it ( 'converts lua status code to string representation' , function ( done ) {
49
+ helper . serverVersionAtLeast . call ( this , client , [ 2 , 5 , 0 ] ) ;
50
50
client . eval ( "return {ok='fine'}" , 0 , helper . isString ( 'fine' , done ) ) ;
51
51
} ) ;
52
52
53
53
it ( 'converts lua error to an error response' , function ( done ) {
54
+ helper . serverVersionAtLeast . call ( this , client , [ 2 , 5 , 0 ] ) ;
54
55
client . eval ( "return {err='this is an error'}" , 0 , helper . isError ( done ) ) ;
55
56
} ) ;
56
57
57
58
it ( 'represents a lua table appropritely' , function ( done ) {
59
+ helper . serverVersionAtLeast . call ( this , client , [ 2 , 5 , 0 ] ) ;
58
60
client . eval ( "return {1,2,3,'ciao',{1,2}}" , 0 , function ( err , res ) {
59
61
assert . strictEqual ( 5 , res . length ) ;
60
62
assert . strictEqual ( 1 , res [ 0 ] ) ;
@@ -69,25 +71,27 @@ describe("The 'eval' method", function () {
69
71
} ) ;
70
72
71
73
it ( 'populates keys and argv correctly' , function ( done ) {
72
- client . eval ( "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}" , 2 , "a" , "b" , "c" , "d" , function ( err , res ) {
73
- assert . strictEqual ( 4 , res . length ) ;
74
- assert . strictEqual ( "a" , res [ 0 ] ) ;
75
- assert . strictEqual ( "b" , res [ 1 ] ) ;
76
- assert . strictEqual ( "c" , res [ 2 ] ) ;
77
- assert . strictEqual ( "d" , res [ 3 ] ) ;
78
- return done ( ) ;
79
- } ) ;
74
+ helper . serverVersionAtLeast . call ( this , client , [ 2 , 5 , 0 ] ) ;
75
+ client . eval ( "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}" , 2 , "a" , "b" , "c" , "d" , function ( err , res ) {
76
+ assert . strictEqual ( 4 , res . length ) ;
77
+ assert . strictEqual ( "a" , res [ 0 ] ) ;
78
+ assert . strictEqual ( "b" , res [ 1 ] ) ;
79
+ assert . strictEqual ( "c" , res [ 2 ] ) ;
80
+ assert . strictEqual ( "d" , res [ 3 ] ) ;
81
+ return done ( ) ;
82
+ } ) ;
80
83
} ) ;
81
84
82
85
it ( 'allows arguments to be provided in array rather than as multiple parameters' , function ( done ) {
83
- client . eval ( [ "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}" , 2 , "a" , "b" , "c" , "d" ] , function ( err , res ) {
84
- assert . strictEqual ( 4 , res . length ) ;
85
- assert . strictEqual ( "a" , res [ 0 ] ) ;
86
- assert . strictEqual ( "b" , res [ 1 ] ) ;
87
- assert . strictEqual ( "c" , res [ 2 ] ) ;
88
- assert . strictEqual ( "d" , res [ 3 ] ) ;
89
- return done ( ) ;
90
- } ) ;
86
+ helper . serverVersionAtLeast . call ( this , client , [ 2 , 5 , 0 ] ) ;
87
+ client . eval ( [ "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}" , 2 , "a" , "b" , "c" , "d" ] , function ( err , res ) {
88
+ assert . strictEqual ( 4 , res . length ) ;
89
+ assert . strictEqual ( "a" , res [ 0 ] ) ;
90
+ assert . strictEqual ( "b" , res [ 1 ] ) ;
91
+ assert . strictEqual ( "c" , res [ 2 ] ) ;
92
+ assert . strictEqual ( "d" , res [ 3 ] ) ;
93
+ return done ( ) ;
94
+ } ) ;
91
95
} ) ;
92
96
93
97
describe ( 'evalsha' , function ( ) {
@@ -101,19 +105,23 @@ describe("The 'eval' method", function () {
101
105
} ) ;
102
106
103
107
it ( 'allows a script to be executed that accesses the redis API' , function ( done ) {
108
+ helper . serverVersionAtLeast . call ( this , client , [ 2 , 5 , 0 ] ) ;
104
109
client . eval ( source , 0 , helper . isString ( 'eval get sha test' , done ) ) ;
105
110
} ) ;
106
111
107
112
it ( 'can execute a script if the SHA exists' , function ( done ) {
113
+ helper . serverVersionAtLeast . call ( this , client , [ 2 , 5 , 0 ] ) ;
108
114
client . evalsha ( sha , 0 , helper . isString ( 'eval get sha test' , done ) ) ;
109
115
} ) ;
110
116
111
117
it ( 'throws an error if SHA does not exist' , function ( done ) {
118
+ helper . serverVersionAtLeast . call ( this , client , [ 2 , 5 , 0 ] ) ;
112
119
client . evalsha ( 'ffffffffffffffffffffffffffffffffffffffff' , 0 , helper . isError ( done ) ) ;
113
120
} ) ;
114
121
} ) ;
115
122
116
123
it ( 'allows a key to be incremented, and performs appropriate conversion from LUA type' , function ( done ) {
124
+ helper . serverVersionAtLeast . call ( this , client , [ 2 , 5 , 0 ] ) ;
117
125
client . set ( "incr key" , 0 , function ( err , reply ) {
118
126
if ( err ) return done ( err ) ;
119
127
client . eval ( "local foo = redis.call('incr','incr key')\n" + "return {type(foo),foo}" , 0 , function ( err , res ) {
@@ -126,6 +134,7 @@ describe("The 'eval' method", function () {
126
134
} ) ;
127
135
128
136
it ( 'allows a bulk operation to be performed, and performs appropriate conversion from LUA type' , function ( done ) {
137
+ helper . serverVersionAtLeast . call ( this , client , [ 2 , 5 , 0 ] ) ;
129
138
client . set ( "bulk reply key" , "bulk reply value" , function ( err , res ) {
130
139
client . eval ( "local foo = redis.call('get','bulk reply key'); return {type(foo),foo}" , 0 , function ( err , res ) {
131
140
assert . strictEqual ( 2 , res . length ) ;
@@ -137,6 +146,7 @@ describe("The 'eval' method", function () {
137
146
} ) ;
138
147
139
148
it ( 'allows a multi mulk operation to be performed, with the appropriate type conversion' , function ( done ) {
149
+ helper . serverVersionAtLeast . call ( this , client , [ 2 , 5 , 0 ] ) ;
140
150
client . multi ( )
141
151
. del ( "mylist" )
142
152
. rpush ( "mylist" , "a" )
@@ -157,6 +167,7 @@ describe("The 'eval' method", function () {
157
167
} ) ;
158
168
159
169
it ( 'returns an appropriate representation of Lua status reply' , function ( done ) {
170
+ helper . serverVersionAtLeast . call ( this , client , [ 2 , 5 , 0 ] ) ;
160
171
client . eval ( "local foo = redis.call('set','mykey','myval'); return {type(foo),foo['ok']}" , 0 , function ( err , res ) {
161
172
assert . strictEqual ( 2 , res . length ) ;
162
173
assert . strictEqual ( "table" , res [ 0 ] ) ;
@@ -166,6 +177,7 @@ describe("The 'eval' method", function () {
166
177
} ) ;
167
178
168
179
it ( 'returns an appropriate representation of a Lua error reply' , function ( done ) {
180
+ helper . serverVersionAtLeast . call ( this , client , [ 2 , 5 , 0 ] ) ;
169
181
client . set ( "error reply key" , "error reply value" , function ( err , res ) {
170
182
if ( err ) return done ( err ) ;
171
183
client . eval ( "local foo = redis.pcall('incr','error reply key'); return {type(foo),foo['err']}" , 0 , function ( err , res ) {
@@ -178,6 +190,7 @@ describe("The 'eval' method", function () {
178
190
} ) ;
179
191
180
192
it ( 'returns an appropriate representation of a Lua nil reply' , function ( done ) {
193
+ helper . serverVersionAtLeast . call ( this , client , [ 2 , 5 , 0 ] ) ;
181
194
client . del ( "nil reply key" , function ( err , res ) {
182
195
if ( err ) return done ( err ) ;
183
196
client . eval ( "local foo = redis.call('get','nil reply key'); return {type(foo),foo == false}" , 0 , function ( err , res ) {
0 commit comments